简体   繁体   English

在C#ASP.NET Web表单中为用户分配角色

[英]Assigning Roles to Users in C# ASP.NET Web Forms

I can't seem to get authorization to work in web.config for user authentication. 我似乎无法获得在web.config中进行用户身份验证的授权。

I have this in web.config and I tried to do authentication using 我在web.config中有这个,我尝试使用

<authorization>
    <allow roles="Admin" />
    <deny users="*" />  
  </authorization>

and this how i get authentication 这就是我如何获得身份验证

    FormsAuthentication.RedirectFromLoginPage(txtUsername.Text,false);

Where do I assign Admin to the user so that it is recognized in the web config? 我应在哪里将管理员分配给用户,以便在Web配置中识别它?

Well whatever you are using is right but half of the code 好吧,无论您使用什么,都是正确的,但是一半的代码

<forms loginUrl="Login.aspx">
  </forms>
<location path="HRpages">
  <system.web> 
    <authorization>
      <allow roles="HR" />
      <deny users="*" />
    </authorization>
   </system.web>
</location>

These two are also to be included in webconfig for more info refer to this 这两个也将包含在webconfig中以获取更多信息,请参考此

https://www.codeproject.com/Articles/13872/%2FArticles%2F13872%2FForm-authentication-and-authorization-in-ASP-NET

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

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