感谢回复程序和账号确实相同。就只有环境不一样。win2003 iis6和win2008 iis7
加密后的结果和username长短无关。无论多长在2003中也是160位,2008也是232位
username是当前登录的账号。

解决方案 »

  1.   

    http://www.cnblogs.com/songrun/archive/2013/06/08/3125668.html注意事项,参考
      

  2.   

    是否与.net framework 的版本有关,换一个高版本的试试、
      

  3.   

    如果你希望保持一致,需要自己写一个MembershipProvider,自己重载SetAuthCookie。那么你想怎么做就你决定了。google custom MembershipProvider
      

  4.   

    忘记说了   我们这个项目用的是forms表单类型。不是windowswin2003里面安装了.net2.0、3.0、3.5。   win2008里面安装的是系统自带的.net 3.5.1
    过会儿我在win2008里面装下win2003的这几个个环境试试。恩   这个兴许是闭源项目的缺点,不能由自己控制。    这个项目我是临时接的,单点登录采用这种方式是之前搞的。而且接这个登录系统的其他系统,好多。不可能去再自己重新写一个。
      

  5.   

    看源码到这里,感觉不容易解决啊
    private static HttpCookie GetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath, bool hexEncodedTicket)
    {
        Initialize();
        if (userName == null)
        {
            userName = string.Empty;
        }
        if ((strCookiePath == null) || (strCookiePath.Length < 1))
        {
            strCookiePath = FormsCookiePath;
        }
        DateTime utcNow = DateTime.UtcNow;
        DateTime expirationUtc = utcNow.AddMinutes((double) _Timeout);
        FormsAuthenticationTicket ticket = FormsAuthenticationTicket.FromUtc(2, userName, utcNow, expirationUtc, createPersistentCookie, string.Empty, strCookiePath);
        string str = Encrypt(ticket, hexEncodedTicket);
        if ((str == null) || (str.Length < 1))
        {
            throw new HttpException(SR.GetString("Unable_to_encrypt_cookie_ticket"));
        }
        HttpCookie cookie = new HttpCookie(FormsCookieName, str);
        cookie.HttpOnly = true;
        cookie.Path = strCookiePath;
        cookie.Secure = _RequireSSL;
        if (_CookieDomain != null)
        {
            cookie.Domain = _CookieDomain;
        }
        if (ticket.IsPersistent)
        {
            cookie.Expires = ticket.Expiration;
        }
        return cookie;
    }
      

  6.   


    为什么感觉不容易解决呢?之前做过将win2003中的system.web替换到win2008中的system.web,但是没有起到效用。帮忙看看,我替换的对不。
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\system.web.dll
    替换到2008的
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\system.web.dll
    C:\Windows\Microsoft.NET\Framework64\v2.0.50727\system.web.dll
      

  7.   

    FormsAuthentication.SetAuthCookie(userName, true); 
    默认采用最新版本的验证数据和加密方式
    可改为指定版本,手动设置cookie,FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                        1, //version
                        userName,
                        DateTime.Now,
                        DateTime.Now.AddMinutes(30),
                        false,
                        "admins,users,xxx"
                        );
                    
                    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    System.Web.HttpCookie authCookie = new System.Web.HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);