简体   繁体   English

如何在ASP.NET C#Web表单中进行不同的身份验证?

[英]how to make different authentication in asp.net c# web form?

we have two part for authentication in web site. 我们在网站中分为两部分进行身份验证。 the first use in admin and the second use for users to enter to site.when admin authentication in site and go to user page ,make error.how to create different authentication for those?web config code: Web配置代码:第一次在admin中使用,第二次用于用户进入site。当在站点中进行admin身份验证并转到用户页面时,出现错误。如何为这些用户创建不同的身份验证?

<authentication mode="Forms">
  <forms loginUrl="~/admin/Login.aspx" timeout="2880" />
</authentication>

Based on your reply in comments... 根据您在评论中的回复...

we read users permissions on sign on.when i use User.Identity.IsAuthenticated then its return true.but this Authenticated for admin.how to make different Authenticated for users? 我们会读取用户的登录权限。当我使用User.Identity.IsAuthenticated时,其返回true。但是,此Authenticated for admin。如何为用户设置不同的Authenticated?

Checking whether a user is authenticated is different from checking a user's permissions. 检查用户是否已通过身份验证与检查用户的权限不同。 Authentication only tells you that the person visiting your site has authenticated themselves (ie logged on to their account). 身份验证仅告诉您访问您网站的人已经对自己进行了身份验证(即登录其帐户)。

What's missing in your equation is the authorization phase (Remember college/uni? Everyone is issued ID cards, on access to the college/uni grounds you authenticate yourself, staff members also authenticate themselves, students won't have authorization to enter the staff room or perform certain tasks, but staff members do). 您的方程式中缺少的是授权阶段(记住大学/大学?每个人都获得了身份证,进入大学/大学的理由是您对自己进行身份验证,工作人员也进行了身份验证,学生将无权进入员工室或执行某些任务,但工作人员会这么做)。

We implement this using what's called Roles , every user should have a Role . 我们使用所谓的Roles ,每个用户都应该有一个Role Every Role should have a set of Permissions associated with it, for now I wouldn't worry about Permissions as it can get real complicated real quick, if you focus on ìmplementing roles alone for now, it would be enough to get you going. 每个Role都应具有与其相关联的一组Permissions ,现在,我不必担心Permissions因为它可以很快地变得非常复杂,如果您现在仅关注“实施角色”,那么就足够了。

Once every user has a role associated to their account, you can check their Role instead of whether they're simply authenticated, which doesn't tell you much. 一旦每个用户都具有与他们的帐户相关联的角色,您就可以检查他们的Role而不是仅对他们进行身份验证,这不会告诉您太多。

There should be an extension method to the IPrinciple interface along the lines of GetUserRoles() already implemented in framework, User.Identity.GetUserRoles() something along the lines of that. 应当已经在框架中实现了GetUserRoles()IPrinciple接口扩展方法,即User.Identity.GetUserRoles()

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

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