1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ASP.NET が書き出すクッキーのドメイン等を設定する方法と知見

Last updated at Posted at 2018-08-30

本題

ASP.NET_SessionIdや.ASPXAUTHなどASP.NETが書き出すクッキーのDomainやSecureを変更するには下記の設定をWeb.configに追記します。

  <system.web>
    <httpCookies domain="your.domain.name" httpOnlyCookies="true" requireSSL="true" />
  </system.web>

上記で動かない場合、コードで書き換える方法もあるようです。(参考

ちなみにクッキーの名前を変える方法

  <system.web>
    <!--SessionId-->
    <sessionState cookieName="foo" />
    <!--.ASPXAUTH-->
    <authentication mode="Forms">
      <forms name="bar" loginUrl="/Path/To/LoginPage" />
    </authentication>
  </system.web>

知見

例えばexample.jpとadmin.example.jpという2サイトがあった時にDomainが.example.jpになるように設定すると両方で同じクッキーが使用されることになります。

SessionIdが同じでも動くのか?と疑問に思ったんですがちゃんと動きます。値も別々に書き換えてくれて、同じ値が操作されてしまう問題もありません。

…と思ったんですが、同じ値だと操作されてしまうという記事が。インプロセスと状態サーバ、インデックスを揃えたりしてもうちでは再現しませんでした。セッションの保存の仕方やIISの設定が違うんでしょうか?

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?