「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。 -戻る --[[ASP.NET (配置)>ASP.NET#g0d096ef]] --[[ASP.NET Session]] --[[ASP.NET Forms認証>ASP.NET Forms認証#zf3414e4]] * 目次 [#t044be2a] #contents *概要 [#x37fa4d3] -[[VSソリューション プロジェクトの構成検討]]~ にも書いたように、プロジェクト分割したいケースがある。 -ASP.NETアプリケーションのP層部分のプロジェクトを分割すると、~ SessionCookieと、Cookie認証Ticketが共有できなくなり、~ [[SessionCookie>#qe11459f]]と、[[Cookie認証Ticket>#ze16e02e]]が共有できなくなり、~ ≒ Sessionが分割され、SSOもできない状態になる。 -必要に応じて、 --SessionCookie --Cookie認証Ticket --[[SessionCookie>#qe11459f]] --[[Cookie認証Ticket>#ze16e02e]] >を共有する設定が必要になる。 *詳細 [#z4124bde] **SessionCookie [#qe11459f] 下記の処置を施せば、Sessionを共有可能と思われる(未検証 ***SessionCookie [#ceeedc54] -SessionCookieを共有するサイトのドメインを指定する。 -SessionCookie名を一致させる(既定値はASP.NET_SessionIdで一致している)。 ***Sessionデータ [#g4925816] -当然、InProcモードではNGなので、StateServerモードを選択する。 -machineKeyを設定する(同一マシンなら不要?)。 -アプリケーション名を設定する(設定処理はGlobal.asaxなどに実装)。 <system.web> <!-- Cookieを共有するサイトのドメインを指定--> <httpCookies domain=".your.site"/> <!-- セッション StateServerにセッション保存、セッションクッキー名の指定、タイムアウト指定--> <sessionState cookieless="UseCookies" cookieName="ASP.NET_SessionId" mode="StateServer" regenerateExpiredSessionId="false" stateConnectionString="tcpip=10.1.1.1:42424" timeout="30"> </sessionState> <!-- machineKeyを設定--> <machineKey validationKey="..." decryptionKey="..." validation="SHA1" decryption="AES" /> </system.web> <appSettings> <!-- アプリケーション名を設定--> <add key="ApplicationName" value="appName" /> </appSettings> **Cookie認証Ticket [#ze16e02e] また、Forms認証のCookie認証Ticketついては、 -Cookie認証Ticket名だけ一致させておけば共有できる(既定値で一致していると思う)。 -ドメイン --単一サイト内ならドメイン指定を省略出来るが、明記することも出来る。 --ドメイン間(サブ・ドメイン間)で共有するには、~ EnableCrossAppRedirectsをtrueに設定する。 <authentication mode="Forms" > <!-- The name, protection, and path attributes must match exactly in each Web.config file. --> <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" protection="All" path="/" domain="contoso.com" timeout="30" /> </authentication> *参考 [#wecc42b2] **SessionCookie [#ic4b59e2] -[ASP.NET][IIS]別アプリケーション&別サーバでセッションを共有する方法 - Qiita~ https://qiita.com/mak_in/items/60f593188e770c7b7ba1 --c# - Share Session between two web sites using asp.net and state server - Stack Overflow~ https://stackoverflow.com/questions/3438912/share-session-between-two-web-sites-using-asp-net-and-state-server --Sharing session between two asp.net web applications~ http://www.freshcodehub.com/Article/48/sharing-session-between-two-aspnet-web-applications **Cookie認証Ticket [#sd588c40] ***Microsoft Docs [#p5e07b0a] -FormsAuthentication.EnableCrossAppRedirects Property (System.Web.Security)~ https://docs.microsoft.com/ja-jp/dotnet/api/system.web.security.formsauthentication.enablecrossappredirects -Forms Authentication Across Applications~ https://docs.microsoft.com/ja-jp/previous-versions/aspnet/eb0zx8fc(v=vs.100) ***コードログ [#df52c40d] -c# – EnableCrossAppRedirects~ クロスドメイン機能はどこで文書化されていますか?~ https://codeday.me/jp/qa/20190405/518500.html -asp.net – クロスドメインフォーム認証クッキーの適切な作成~ https://codeday.me/jp/qa/20190416/641578.html ---- Tags: [[:.NET開発]], [[:ASP.NET]]