.ASPXAUTH cookie 未被子应用程序读取

问题描述 投票:0回答:1

我在

asp.net v4.7.2 web app
中的
my.example.com
设置了
IIS
。它使用 asp.net
Forms Authentication
。是
Web.Config
:

<httpCookies requireSSL="true" />

<authentication mode="Forms">
  <forms loginUrl="~/Default.aspx" defaultUrl="~/User/Default.aspx" slidingExpiration="true" timeout="30" requireSSL="true" />
</authentication>

<roleManager defaultProvider="SqlProvider" enabled="true">
  <providers>
    <clear />
    <add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="MyConnectionString" applicationName="MyApp" />
  </providers>
</roleManager>

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="30">
  <providers>
    <clear />
    <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MyConnectionString" applicationName="MyApp" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" passwordFormat="Hashed" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="1" maxInvalidPasswordAttempts="25" />
  </providers>
</membership>

我有另一个

asp.net v4.7.2 web app
,通过
IIS > Add Application
作为
my.example.com/test
。它从父站点的
Forms Authentication
继承
web.config
,我可以通过以编程方式获取角色和用户列表来确认这一点。 但是当我使用
User.Identity.IsAuthenticated
检查身份验证时,它总是错误的。是
Web.config
:

<authentication>
    <forms loginUrl="~/../Default.aspx">
    </forms>
</authentication>

子站点只能看到

ASP.NET_SessionId
cookie,其值与父站点相同,但看不到
.ASPXAUTH
cookie(通过记录 cookie 进行检查)。我认为,如果它可以看到 Auth cookie,它应该能够验证并且 IsAuthenticated 应该变为 true。

如何在子应用程序中从父站点 https://my.example.com 读取身份验证 https://my.example.com/test

c# asp.net .net authentication
1个回答
0
投票

想通了。

我以为有一个根级机器密钥,但 IIS 有一个为每个单独的应用程序自动生成机器密钥的每个站点设置。一旦在 IIS 中为父站点单击“生成密钥”,它就会在 web.config 中添加一个机器密钥,并且子应用程序也会继承该密钥:

enter image description here

 <system.web>
   <machineKey decryptionKey="A9...." validationKey="85...." />
 </system.web>
© www.soinside.com 2019 - 2024. All rights reserved.