本机测试
网站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.   

    你是要两者相同处理还是不同处理?
    你目前就是用了同一个cookie,所以相同如果不同,你可以分两个cookie
      

  2.   

    当然需要两者不同处理,不然用户如果知道一个网站的用户名密码,那个网站也就能登进去了,怎么用两个不同的cookie?
      

  3.   

    Cookie["UserA"]  和 Cookie["UserB"]
      

  4.   

    uses local Cookie information
      

  5.   

    可是是用FORM认证的啊,即使COOKIE不同,FORM登录认证是相同的啊
      

  6.   

    你的用戶信息是存儲在Cookie中的 不是什麼登陸認證方式
      

  7.   


    //根据用户输入的用户名和密码查询
    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保存了登录用户的信息
      

  8.   

    建议使用SSO。令牌授权, 自己可以百度一下
      

  9.   

    一定要SSO那么复杂吗?是些规模小的网站
      

  10.   

    context.Response.Cookies(cookiename).Domain = “sina.com”
      

  11.   

    即使我不用COOKIE,不保存用户信息,FORM认证仍然是通用的,即登录一个网站,另一个也处于登录成功状态
    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;
            }
      

  12.   

    给web.config里authentication节的forms加上name属性,给设1个设置或者给2个设不同的值<authentication mode="Forms">
    <forms loginUrl="Account/Login.aspx" timeout="5000000" name="FormTicket1" />
    </authentication>
      

  13.   

    我试过添加domain="域名",添加后就登录不进去了没有NAME属性啊
      

  14.   

    擦,格式不能嵌套
    不清楚的话看这个吧http://msdn.microsoft.com/zh-cn/library/system.web.security.formsauthentication.formscookiename(v=vs.80).aspx