2 wang2245 wang2245 于 2016.09.17 23:28 提问

asp.net mvc 4 二级域名身份验证为空

在user.a.com中有如下代码做用户登陆:

 var __doubleTimeOut = FormsAuthentication.Timeout.TotalMinutes;
string __strJson = Beicity.Utility.JsonHelper.JsonSerializer(loginModel);       
FormsAuthenticationTicket __authTicket = new FormsAuthenticationTicket(1, __strJson, DateTime.Now, DateTime.Now.AddMinutes(__doubleTimeOut), false, Request.UserHostAddress);                        
string __encryptedTicket = FormsAuthentication.Encrypt(__authTicket);
System.Web.HttpCookie __authCookie = new System.Web.HttpCookie(FormsAuthentication.FormsCookieName);
 __authCookie.Value = __encryptedTicket;
FormsAuthentication.SetAuthCookie(loginModel.UserName, false);
__authCookie.Domain = System.Configuration.ConfigurationManager.AppSettings["CookieDomain"].ToString();
__authCookie.Path = "/";

HttpCookie _testCookie = new HttpCookie("Test");
_testCookie.Value = "aaaa";
_testCookie.Domain = ".a.com";
_testCookie.Path = "/";

System.Web.HttpContext.Current.Response.Cookies.Add(__authCookie);
System.Web.HttpContext.Current.Response.Cookies.Add(_testCookie);

在test.a.com中:

 Request.Cookies[FormsAuthentication.FormsCookieName]返回为null

搞了一天多了,不知道问题出在哪,_testCookie 可以正常获取,但身份验证的就不行

1个回答

devmiao
devmiao   Ds   Rxr 2016.09.17 23:44
wang2245
wang2245 谢谢!这个我试过了,还是一样
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!