「[[マイクロソフト系技術情報 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ソリューション プロジェクトの構成検討]]にも書いたように、プロジェクト分割したいケースがある。
-[[VSソリューション プロジェクトの構成検討]]~
にも書いたように、プロジェクト分割したいケースがある。

-ここでは、ASP.NETアプリケーションのP層部分のプロジェクト分割に伴い、~
必要となる「SessionCookie、Cookie認証Ticketを共有する方法」について説明する。
-ASP.NETアプリケーションのP層部分のプロジェクトを分割すると、~
SessionCookieと、Cookie認証Ticketが共有できなくなり、~
≒ Sessionが分割され、SSOもできない状態になる。

-必要に応じて、
>「SessionCookie、Cookie認証Ticketを共有する」

>設定が必要になる。

*詳細 [#z4124bde]
-[[参考>#wecc42b2]]の処置を施せば、Sessionを共有可能と思われる(未検証

-また、Forms認証のCookie認証Ticketついては、
--EnableCrossAppRedirectsをtrueにしておけば、同一ドメイン内でコレを共有できるので、
--Cookie認証Ticket名だけ一致させておけば問題と思う(既定値で一致していると思う)。
**SessionCookie [#qe11459f]
下記の処置を施せば、Sessionを共有可能と思われる(未検証

-SessionCookie
--SessionCookieを共有するサイトのドメインを指定する。
--SessionCookie名を一致させる(既定値はASP.NET_SessionIdで一致している)。

-Sessionデータ
--当然、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
--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)

-コードログ
--c# – EnableCrossAppRedirects~
クロスドメイン機能はどこで文書化されていますか?~
https://codeday.me/jp/qa/20190405/518500.html

--asp.net – クロスドメインフォーム認証クッキーの適切な作成~
https://codeday.me/jp/qa/20190416/641578.html

----
Tags: [[:.NET開発]], [[:ASP.NET]]



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS