在最新的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) –