本机测试
网站1
主页地址 http://127.0.0.1:81
后台登录 http://127.0.0.1:81/admin网站2
主页地址 http://127.0.0.1:82
后台地址 http://127.0.0.1:82/admin
两个网站用的后台程序一模一样,使用ASP.NET FORM认证
认证成功后:System.Web.Security.FormsAuthentication.SetAuthCookie(user, false);
HttpCookie newCookie = new HttpCookie("User");
HttpContext.Current.Response.Cookies["Name"].Value = System.Web.HttpUtility.UrlEncode(user);
HttpContext.Current.Response.Cookies["pass"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "sha1");
HttpContext.Current.Response.Cookies["id"].Value = System.Web.HttpUtility.UrlEncode(ds.Tables["login"].Rows[0]["id"].ToString());
问题:
当成功登录网站1时,打开http://127.0.0.1:82/admin,发现已经成功登录了,成功登录网站2时,网站1也是登录成功状态,当使用System.Web.Security.FormsAuthentication.SignOut();注销一个网站登录时,另一个也会注销,如何解决?
网站1
主页地址 http://127.0.0.1:81
后台登录 http://127.0.0.1:81/admin网站2
主页地址 http://127.0.0.1:82
后台地址 http://127.0.0.1:82/admin
两个网站用的后台程序一模一样,使用ASP.NET FORM认证
认证成功后:System.Web.Security.FormsAuthentication.SetAuthCookie(user, false);
HttpCookie newCookie = new HttpCookie("User");
HttpContext.Current.Response.Cookies["Name"].Value = System.Web.HttpUtility.UrlEncode(user);
HttpContext.Current.Response.Cookies["pass"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "sha1");
HttpContext.Current.Response.Cookies["id"].Value = System.Web.HttpUtility.UrlEncode(ds.Tables["login"].Rows[0]["id"].ToString());
问题:
当成功登录网站1时,打开http://127.0.0.1:82/admin,发现已经成功登录了,成功登录网站2时,网站1也是登录成功状态,当使用System.Web.Security.FormsAuthentication.SignOut();注销一个网站登录时,另一个也会注销,如何解决?
解决方案 »
- socket传输压缩文件
- 何如在网页上播放视频文件。
- 急!急! 在线等!!!Excel 导入SQL2005 报错“无法初始化链接服务器 "(null)" 的 OLE DB 访问接口...”
- 把EXCEL里的数据导入到SQLSERVER数据库老出错啊,代码贴出来了
- gridview弹出新页面,并返回值.
- 看下这段代码,为什么一直都是提示else后面的代码?
- o as System.Web.UI.WebControls.BoundColumn
- 如何以编程方式添加GridView列?
- 请教各位大哥一个问题,相当于送分给大家,马上结贴~
- 高分求解:水晶报表访问被拒绝问题,UP有分
- 为什么保存cookie的方法上传到服务器报错
- 【问题】图片是在后台动态生成的,显示的时候要能滑动,并且刷新
你目前就是用了同一个cookie,所以相同如果不同,你可以分两个cookie
//根据用户输入的用户名和密码查询
if (ds.Tables["login"].Rows.Count == 1)
{
System.Web.Security.FormsAuthentication.SetAuthCookie(user, false); HttpCookie newCookie = new HttpCookie("User");
HttpContext.Current.Response.Cookies["Name"].Value = System.Web.HttpUtility.UrlEncode(user);
HttpContext.Current.Response.Cookies["pass"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "sha1");
HttpContext.Current.Response.Cookies["id"].Value = System.Web.HttpUtility.UrlEncode(ds.Tables["login"].Rows[0]["id"].ToString());
//登录成功
}
我用COOKIE保存了登录用户的信息
if (ds.Tables["login"].Rows.Count == 1)
{
System.Web.Security.FormsAuthentication.SetAuthCookie(user, false);
//HttpCookie newCookie = new HttpCookie("User");
//HttpContext.Current.Response.Cookies["Name"].Value = System.Web.HttpUtility.UrlEncode(user);
//HttpContext.Current.Response.Cookies["pass"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "sha1");
//HttpContext.Current.Response.Cookies["id"].Value = System.Web.HttpUtility.UrlEncode(ds.Tables["login"].Rows[0]["id"].ToString());
win = true;
}
<forms loginUrl="Account/Login.aspx" timeout="5000000" name="FormTicket1" />
</authentication>
不清楚的话看这个吧http://msdn.microsoft.com/zh-cn/library/system.web.security.formsauthentication.formscookiename(v=vs.80).aspx