在最新的ASP.NET WebForms应用程序中,我们不再使用RoleManager等(据我所知),那么我们如何授权访问特定角色的网页?ASP.NET WebForms - 如何授权访问页面
在MVC中,我会使用Authorize属性,但WebForms中不存在,所以我不知所措 - 任何想法?
在最新的ASP.NET WebForms应用程序中,我们不再使用RoleManager等(据我所知),那么我们如何授权访问特定角色的网页?ASP.NET WebForms - 如何授权访问页面
在MVC中,我会使用Authorize属性,但WebForms中不存在,所以我不知所措 - 任何想法?
尝试登录该代码 传递作用的FormsAuthenticationTicket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserName.Text, DateTime.Now, DateTime.Now.AddMinutes(2880), false, role, FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text, false));
上Page_Load事件尤其是网络表格检索角色
protected void Page_Load(object sender, EventArgs e)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
string userData = ticket.UserData;
string[] temp = userData.Split(',');
role=temp[0];
if (role!="Owner")
{
Response.Write("............");
}
}
如果您想在文件夹级别授权,那么不要检查rol E在网路表单中指定该文件夹的web.config文件的作用
<authorization>
<allow roles="Owner"/>
<deny users="*"/>
</authorization>
使用/ a web.config文件和授权元素进行调查。您可以为此目的在任何目录中创建一个web.config文件(即,您可以在整个站点中拥有多个web.config文件)。
一个链接(窥视他人的联系,以及): https://msdn.microsoft.com/en-us/library/8d82143t%28v=vs.85%29.aspx
的可能的复制[有一个authorizeattribute只相当于标准的web形式(不MVC)的.NET(http://stackoverflow.com/问题/ 4217576/IS-有-AN-authorizeattribute等效到只是标准的web表单 - 不MVC-F) –