我如何在ASP.NET中进行表单身份验证和授权 [英] How can i do form authentication and authorization in asp.net

查看:85
本文介绍了我如何在ASP.NET中进行表单身份验证和授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个文件夹,一个是Admin,一个是具有单独web.config文件的User.

并在global.asax文件中完成了此代码....

I have create to folder one is Admin and one is User with separete web.config file.

and in global.asax file i have done this code....

protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
              if (HttpContext.Current.User != null)
        {
          cookie (ticket) exists for this user
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
               FormsAuthentication
                if (HttpContext.Current.User.Identity is FormsIdentity)
                {
                  
                    FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;
                    FormsAuthenticationTicket ticket = identity.Ticket;
                    string[] roles = ticket.UserData.Split('','');
                    HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(identity, roles);
                }
            }
        }


但是当我运行登录页面时,如何检查此页面是针对管理员还是用户.

请告诉我................


but when i run the login page how can i check this page is for admin or user.

Plz tell me................

推荐答案

您不需要检查用户角色,asp.如果web.config中的设置正确,net将处理允许/拒绝访问.

http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx [ ^ ]
You don''t need to check for user roles, asp.net will handle allowing/denying access if the settings in the web.config are correct.

http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx[^]


看看这些:
了解角色管理 [ ASP.NET 2.0第I部分中的成员资格和角色提供程序 [ ASP.NET 2.0 Part II中的成员资格和角色提供程序 [
Have a look at these:
Understanding Role Management[^]
Membership and Role Providers in ASP.NET 2.0 Part I[^]
Membership and Role Providers in ASP.NET 2.0 Part II [^]
Go through them...


这篇关于我如何在ASP.NET中进行表单身份验证和授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆