【发布时间】:2011-07-12 09:40:47
【问题描述】:
我编写了以下代码来访问该页面,但这对我不起作用
if (User.Identity.IsAuthenticated)
{
if (Context.User.IsInRole("DistrictAdmin"))
{
if (!IsPostBack)
{
}
}
else
{
Response.Redirect("Default.aspx");
}
}
else
{
Response.Redirect("Default.aspx");
}
我的登录验证码
string RoleTypeID;
objLogin.UserName = txtUsername.Text;
objLogin.Password = txtPassword.Text;
if (objLogin.getRoles(out RoleTypeID))
{
Session["RoleID"] = RoleTypeID;
FormsAuthenticationTicket oAuthTicket = new FormsAuthenticationTicket(1, txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(20), false, RoleTypeID.ToString(), FormsAuthentication.FormsCookiePath);
string encryptoAuthTicket = FormsAuthentication.Encrypt(oAuthTicket);
HttpCookie oCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptoAuthTicket); // Name of auth cookie
if (oAuthTicket.IsPersistent) oCookie.Expires = oAuthTicket.Expiration;
HttpContext.Current.Response.Cookies.Add(oCookie);
if (RoleTypeID == "DistrictAdmin" || RoleTypeID == "CampusAdministrator" || RoleTypeID == "LPACMember")
{
Response.Redirect("LEPstudentrecords.aspx");
}
}
else
{
lblInvalid.Visible = true;
}
在我的web.config 中我设置如下
<roleManager enabled="false" />
<authentication mode="Forms">
<forms loginUrl="Default.aspx"
timeout="20" />
</authentication>
<sessionState mode="InProc" timeout="180"></sessionState>
但是即使他通过了身份验证,我也无法获得该角色,任何人都可以告诉我该怎么做
这是经过身份验证后的图像,一切正常,但我无法访问该页面
【问题讨论】:
-
为什么是
roleManager enabled="false"??? -
因为我是从我的 sql server 获取角色