2013-02-21 104 views
0

我們試圖在我們的PC(Windows 7,IIS 7.5)上的兩個應用程序之間使用身份驗證,並且一切都很順利。但問題是,當我們嘗試發佈這些網站(Windows Web服務器2008年,IIS 7.0)交叉認證不起作用!跨多個應用程序進行身份驗證

長invistigation後,我們發現,在下面的代碼是第二個站點上發生的錯誤:

Dim formsCookie As HttpCookie = Request.Cookies(FormsAuthentication.FormsCookieName) 
    If (formsCookie IsNot Nothing) Then 
    Else 
    ' always null 

我們試圖檢查pathes這樣在後面的代碼:

Dim ticket As New FormsAuthenticationTicket(1, smsProfile, DateTime.Now, _ 
                 DateTime.Now.AddDays(1), True, AdminSessions.UserObj.Pid, _ 
                 FormsAuthentication.FormsCookiePath) 
    Dim hash As String = FormsAuthentication.Encrypt(ticket) 
    Dim cookie As New HttpCookie(
     FormsAuthentication.FormsCookieName, 
     hash) 
    If (ticket.IsPersistent) Then 
     cookie.Expires = ticket.Expiration 
    End If 
    Response.Cookies.Add(cookie) 
    Response.Redirect(smsPortal) 

在web.config中:

 <authentication mode="Forms"> 

     <forms name=".ASPXFORMSAUTH" enableCrossAppRedirects="true" domain="mydomain.com.jo" loginUrl="http://..." protection="All" path="/"/> 

    </authentication> 

請告訴我們IIS之間有什麼區別本地PC和服務器。

謝謝。

+0

它們是否都發布到同一個域? – 2013-02-21 06:03:43

+0

是在同一個域中,每個域都在獨立子域中。 ex:sub1.mydomain.com.jo,sub2.mydomain.com.jo – Ibsuser 2013-02-21 06:08:47

+0

有沒有特別的配置? – Ibsuser 2013-02-21 08:24:46

回答

2

瀏覽器很可能不會將認證cookie從第一個站點發送到第二個站點。檢查cookie路徑和域。這兩個網站必須位於同一個域中,並且Cookie路徑必須設置爲公共根。

請參閱此鏈接瞭解詳情: Cookie Domains and Paths

爲了幫助排除故障,使用這樣的實用程序,提琴手或螢火蟲查看請求被髮送的cookie,並確認身份驗證Cookie通過網站1套(用戶登錄的地方)也被髮送到站點2.

如果站點不在同一臺服務器上,請檢查它們是否使用相同的machineKey配置。

+0

我edidt我的帖子,並提到了一些與域和路徑相關的代碼。 – Ibsuser 2013-02-21 06:16:21

+0

使用Fiddler或Firebug驗證是否正在發送Cookie。如果不是,請使用Fiddler/Firebug日誌檢查第一個站點上cookie的實際cookie路徑和域。如果它正在發送,服務器正在接收它,但無法驗證票證,因此請檢查以確保託管站點的所有計算機上的machineKey設置都配置相同。 – Maxam 2013-02-21 06:22:42

+0

謝謝。我試圖用螢火蟲,似乎我發現了這個問題。我發現螢火蟲網格中的顯示沒有向我展示我的.ASPXFORMSAUTH域名,它只顯示他第一個子域名。當我試圖手動將其更改爲我的域名(.mydomain.com.jo)時,它工作正常。我在web.config文件中更改了它,但是沒有成功。我如何在我的代碼和配置文件中解決這個問題? – Ibsuser 2013-02-21 07:43:37