身份验证代码如下
webform1:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
FormsAuthentication.SignOut();
}
if(HttpContext.Current.Request.Cookies["aaa"]!=null)
{
HttpContext.Current.Request.Cookies.Remove("aaa");
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
cookie=new HttpCookie("aaa");
cookie.Values["name"]="zou";
HttpContext.Current.Request.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}
webform2:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Page.User.Identity.IsAuthenticated==false)
Server.Transfer("WebForm1.aspx");
}调试的结果是Page.User.Identity.IsAuthenticated一直都是等于false,我实在不知道问题出在哪里,懂的朋友来帮帮忙。
webform1:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
FormsAuthentication.SignOut();
}
if(HttpContext.Current.Request.Cookies["aaa"]!=null)
{
HttpContext.Current.Request.Cookies.Remove("aaa");
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
cookie=new HttpCookie("aaa");
cookie.Values["name"]="zou";
HttpContext.Current.Request.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}
webform2:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Page.User.Identity.IsAuthenticated==false)
Server.Transfer("WebForm1.aspx");
}调试的结果是Page.User.Identity.IsAuthenticated一直都是等于false,我实在不知道问题出在哪里,懂的朋友来帮帮忙。
解决方案 »
- asp.net让FCKEditor上传图片到动态指定的目录
- asp.net 网站退出问题
- SmartGridView谁用过?
- 在使用FileUpload1.PostedFile.FileName返回路径时发现路径中多了一个"\"
- 很简单的问题啊,<asp:Button>控件,如何在启用了这个事件OnClientClick="check()" 再启用这个事件OnClick="Button1_Click"
- vs2005的程序部署在WIN2000上没有问题,部署在WIN2003上真麻烦,帮我看看...
- 如何固定<select></select>下拉列表框的宽度?
- 谁有兴趣做OA?
- ***如何使frame的子页面获得传给frame的参数信息??****************
- 为什么我的DataGrid的事件变成DGCard_SelectedIndexChanged(object sender, System.EventArgs e)了?
- ??? 编译器错误信息: CS0117: “object”并不包含对“SubString”的定义 ???
- 分页的DataDrid,怎么让一开始登陆改页面时显示的是第三页
ByVal persistent As Boolean) As FormsAuthenticationTicket
Return New FormsAuthenticationTicket(1, userName, DateTime.Now, _
DateTime.Now.AddMinutes(60), persistent, roles)
End Function Private Function CreateAuthCookie(ByVal authTicket As FormsAuthenticationTicket) As HttpCookie
Return New HttpCookie(FormsAuthentication.FormsCookieName, _
FormsAuthentication.Encrypt(authTicket))
End Function
登陆完成:
Dim authTicket As FormsAuthenticationTicket
Dim authCookie As HttpCookie authTicket = CreateAuthTicket(txtUserID.Text, CStr(viewstate("roles")), False)
authCookie = CreateAuthCookie(authTicket)
HttpContext.Current.Response.Cookies.Add(authCookie) If Request("ReturnUrl") Is Nothing Then
Response.Redirect("./Menu/Menu.aspx")
Else
Response.Redirect(Request("ReturnUrl"))
End If
if(验证通过)
{
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username,CheckBox1.Checked);}
即可
如果是第一次登陆呢?这样的代码不行呀
我想知道怎么才能让IsAuthenticated得到的值是true也就是验证通过的用户。
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket("aaa", false, 60);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, ticket));
能写的完整点吗?谢谢