我有登录页面,其中使用了登录控制,一切在本地机器上工作正常,但在服务器上不起作用。成功登录后没有任何错误或错误,它再次重定向到登录页面。 下面是我的代码。 的web.config
<location path="Admin">
<system.web>
<authorization>
<allow roles="Admin,user"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<authentication mode="Forms">
<forms name="RJD" domain="abc.net" loginUrl="Login.aspx" protection="All" slidingExpiration="true" defaultUrl="~/Admin/ApproveComments.aspx" timeout="60" path="/">
</forms>
</authentication>
protected void ctrLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
FormsAuthentication.Initialize();
clsAuthenticate objauthonticate = new clsAuthenticate();
try
{
objauthonticate.user = ctrLogin.UserName.Trim();
objauthonticate.Pasword = ctrLogin.Password.Trim();
if (objauthonticate.Authonticate())
{
HttpContext.Current.Session["user"] = objauthonticate.user.ToString();
CreateTicket();
e.Authenticated = true;
// FormsAuthentication.RedirectFromLoginPage(ctrLogin.UserName, ctrLogin.RememberMeSet);
Response.Redirect("~/Admin/ApproveComments.aspx");
}
else
{
e.Authenticated = false;
}
}
catch (Exception ex)
{
//throw ex;
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Alert", "alert('" + ex.Message + "');", true);
}
}
private void CreateTicket()
{
clsAuthenticate oblogin = new clsAuthenticate();
string role = oblogin.getRoleByID(Session["user"].ToString());
FormsAuthentication.HashPasswordForStoringInConfigFile(ctrLogin.Password, "sha1");
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "Forms", DateTime.Now, DateTime.Now.AddMinutes(30), true, role);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
Response.Cookies.Add(cookie);
}
答案 0 :(得分:0)
当用户使用Forms Authentication对网站进行身份验证时,服务器会创建一个cookie。 cookie的值是加密的表单身份验证票证。在每次向应用程序发出请求时,cookie都会传递给服务器,FormsAuthenticationModule类会解密cookie值并确定用户是否有效。 我认为你的项目web.config中有标记。删除它
...
<modules>
<remove name="FormsAuthentication" />
</modules>
....