简体   繁体   English

Web配置文件中的WCF Rest服务身份验证

[英]WCF Rest service authentication in web config file

I am developing a WCFRest service and want to authenticate it by a single userid and password . 我正在开发WCFRest服务,并希望通过单个用户ID和密码对其进行身份验证。 Go through the lot of stuff on internet .But the thing is complex. 遍历互联网上的很多东西。但是事情很复杂。 I want to know is there any way to give the permission for single userid,password in web Config file . 我想知道有什么办法可以给Web配置文件中的单个userid,password授予权限。

 <Location path="Test.svc"> 
   <system.web>
      <authorization>
          <denyusers="?"/>
      </authorization>
    </system.web>
 </Location

If there is any way to authenticate it .Please Help me on this. 如果有任何方法可以对其进行身份验证,请为此提供帮助。

Here's the thing: you do not want to just allow a specific USER, you want to allow a specific ROLE, ie someone who is allowed to do that. 事情是这样的:您不想只允许特定的USER,而是想允许特定的ROLE,即被允许这样做的人。 Using a userID and Password means that if you ever need to change who is allowed (because that person has been fired, or because there are now 2 people with that permission), you would have to change the web.config and redeploy the file, which in extreme cases might break the site. 使用userID和密码意味着,如果您需要更改允许的人(因为该人已被解雇,或者因为现在有2位具有该权限的人),则必须更改web.config并重新部署该文件,在极端情况下可能会破坏网站。

Instead, implement an entire membership system, including roles, and then do this: 而是,实现包括角色在内的整个成员资格系统,然后执行以下操作:

 <Location path="Test.svc"> 
   <system.web>
      <authorization>
          <allow roles="[RoleNameHere]">
          <deny users="*"/>
      </authorization>
    </system.web>
 </Location>

You can then add the user that you want to give access to that role through the standard way of doing this for your membership provider, and s/he'll automatically be allowed access, while everyone else is denied. 然后,您可以通过标准的方式为您的成员资格提供者添加您想要授予该角色访问权限的用户,这样,他/他将自动被允许访问,而其他所有人则被拒绝。 You can also easily change whoever is allowed or denied, because it's a data change, not a code change. 您还可以轻松地更改允许或拒绝的人,因为这是数据更改,而不是代码更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM