我使用FORMS表单验证,登录页面有两个选择(1.无 2.1年),选择1就使用session,选择2就使用cookies可是我选择1并登录成功后,不能进入该页面我的CONFIG配置如下:
<authentication mode="Forms">
<forms name="MyAppFormsAuth" loginUrl="Afreshtwo.aspx" protection="Encryption" timeout="20" path="/">
</forms>
</authentication>代码如下:
if(Session["id"].ToString() != "" || User.Identity.Name!=null)
{}
else
{}
<authentication mode="Forms">
<forms name="MyAppFormsAuth" loginUrl="Afreshtwo.aspx" protection="Encryption" timeout="20" path="/">
</forms>
</authentication>代码如下:
if(Session["id"].ToString() != "" || User.Identity.Name!=null)
{}
else
{}
{
r.Close();
FormsAuthenticationTicket ticket = null;
if(this.dlValidity.SelectedItem.Value == "0")
{
Page.Session["id"]=1;
Session.Timeout = 30;
string strRedirect = @"Privatelyowned/SuccedInto.aspx";
Response.Redirect(strRedirect,true);
}
else
{
ticket = new FormsAuthenticationTicket(1,this.tbUser.Text,DateTime.Now,
DateTime.Now.AddDays(double.Parse(this.dlValidity.SelectedItem.Value)),true,"User");
string cookieStr = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie =new HttpCookie(FormsAuthentication.FormsCookieName,cookieStr);
cookie.Expires=ticket.Expiration;
cookie.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(cookie);
string strRedirect = @"Privatelyowned/SuccedInto.aspx";
Response.Redirect(strRedirect,true);
}
}
{
r.Close();
FormsAuthenticationTicket ticket = null;
if(this.dlValidity.SelectedItem.Value == "0")
{
Page.Session["id"]=1;
Session.Timeout = 30;
string strRedirect = @"Privatelyowned/SuccedInto.aspx";
Response.Redirect(strRedirect,true);
}
else
{
ticket = new FormsAuthenticationTicket(1,this.tbUser.Text,DateTime.Now,
DateTime.Now.AddDays(double.Parse(this.dlValidity.SelectedItem.Value)),true,"User");
string cookieStr = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie =new HttpCookie(FormsAuthentication.FormsCookieName,cookieStr);
cookie.Expires=ticket.Expiration;
cookie.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(cookie);
string strRedirect = @"Privatelyowned/SuccedInto.aspx";
Response.Redirect(strRedirect,true);
}
}
if(Session["id"].ToString() != "" || User.Identity.Name!=null)
User.Identity.Name就会=null,那就相当于未登录了
代码逻辑有问题
改为
Session["id"] != null
Session["id"].ToString() != "" 的