簡體   English   中英

ASP.NET通過同一域中的兩個應用程序共享表單身份驗證

[英]Asp.net share forms authentication by two applications in the same domain

我在同一個域中有兩個應用程序:mydomain / app1和mydomain / app2,我需要在它們之間共享身份驗證。 一個應用程序位於Asp.Net WebForms中,第二個應用程序使用WebApi2。

我配置如下的web.config:

應用1:

<authentication mode="Forms">
  <forms loginUrl="/Login.aspx" defaultUrl="/Default.aspx" name=".ASPXFORMSAUTH" protection="All" cookieless="UseDeviceProfile" slidingExpiration="true" path="/" domain="mydomain" requireSSL="false" timeout="60" enableCrossAppRedirects="false">
  </forms>
</authentication>
<authorization>
  <deny users="?" />
  <allow users="*"/>
</authorization>
<machineKey validationKey="generated key1" decryptionKey="generated key2" validation="SHA1"/>

應用2:

<authentication mode="Forms">
  <forms loginUrl="/index.html" defaultUrl="/index.html" name=".ASPXFORMSAUTH" protection="All" cookieless="UseDeviceProfile" slidingExpiration="true" path="/" domain="mydomain" requireSSL="false" timeout="60" enableCrossAppRedirects="false">
  </forms>
</authentication>
<authorization>
  <deny users="?" />
  <allow users="*"/>
</authorization>
<machineKey validationKey="generated key1" decryptionKey="generated key2" validation="SHA1"/>

我登錄到app1並觀察cookie的內容。 然后,我從另一個瀏覽器選項卡中的app2請求URL。 第二個選項卡中的cookie(名稱和內容)與第一個選項卡中的相同。 我希望來自第二個選項卡的請求將由app2進行身份驗證,因為cookie已由app1進行身份驗證。 但是,這沒有發生,我被重定向到app2的登錄頁面。

正如OP所建議的,這是在這種情況下有效的答案。

他們已將Cookie加密更改為4至4.5。 您可以使兩者都在同一個.net下運行,也可以通過將屬性添加到計算機密鑰配置節點來打開4.5站點上的兼容性。

https://social.microsoft.com/Forums/en-US/1791c5e3-4087-4e92-a460-51c5c4221f49/any-forms-auth-changes-in-45?forum=Offtopic

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM