2010-04-19 36 views
1

我有多個子域試圖使用單個子域進行身份驗證,使用窗體身份驗證所有在Windows Server 2008 R2上運行的身份驗證。Page.User.Identity.Name在子頁面上爲空

所有形式的認證頁面都設置爲使用相同的名稱,並在認證頁面上添加以下代碼段餅乾:

FormsAuthentication.SetAuthCookie(txtUserName.Text, false); 
System.Web.HttpCookie MyCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(User.Identity.Name.ToString(), false); 
MyCookie.Domain = ConfigurationManager.AppSettings["domainName"]; 
Response.AppendCookie(MyCookie); 

當我登錄到signon.mysite.com page.user.identity.isauthenticated和page.user.identity.name屬性都可以正常工作。當我導航到subdomain.mysite.com時,page.user.identity.isauthenticated返回true,名稱爲空。

我試圖從cookie中檢索它使用以下,但它也是空白的。

HttpCookie cookie = Request.Cookies[".ASPXAUTH"]; 
FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(cookie.Value); 
user2_lbl.Text = fat.Name; 

在谷歌上搜索這個問題,我發現有些人說的東西必須被添加到Global.asax中和其他說這是沒有必要的。

目標是能夠在身份驗證子域上登錄,並且可以從根站點和其他子域訪問用戶身份。機器密鑰在所有web.config中匹配,並且當前將AppSettings [「domainName」]設置爲「mysite.com」。

有誰知道什麼阻止我訪問用戶信息?

+1

這應該特別影響Identity對象,但是您的web.configs在所有站點上的formsAuthentication標記中都有enableCrossAppRedirects =「true」嗎? – 2010-04-19 15:07:02

回答

4

將「mysite.com」更改爲「.mysite.com」(注意前導「。」)。

這會告訴瀏覽器該cookie也適用於子域。

+0

檢查你的緩存,特別是確保沒有老餅乾留下。這是你的問題,當然。這不是針對個人電腦的。 – jvenema 2010-04-19 23:24:27

相關問題