0
我想在一個域下託管多個站點。但目前我的工作在本地主機,所以我加了這兩條線到我的etc/hosts文件:將Cookie訪問到子域中
127.0.0.1 something.com
127.0.0.1 orders.something.com
有託管在IIS 2個應用程序。可以使用以下方式瀏覽:orders.something.com/OrdersSSO
和其他可以使用something.com/SSOSample/
瀏覽。
我創建使用此代碼驗證cookie在something.com/SSOSample/
:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
"abc",
DateTime.Now,
DateTime.Now.AddMinutes(30), // value of time out property
true, // Value of IsPersistent property
String.Empty,
FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authCookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
encryptedTicket);
Response.Cookies.Add(authCookie);
所以我記錄在此應用。但是,當我瀏覽orders.something.com/OrdersSSO我沒有得到我的身份驗證cookie。
這是我的形式在web.config中節:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" enableCrossAppRedirects="true" timeout="2880" domain=".something.com" />
</authentication>
我缺少什麼?
請閱讀我的web.config。我已經有了。 – Jaggu
您仍然需要authCookie.Domain =「.something.com」,因爲您正在手動設置Cookie。當ASP.NET自動擴展cookie到期時,將使用您的web.config域屬性。 –