ASP.. NET重定向到Https问题-错误401

本文关键字:错误 问题 Https NET 重定向 ASP | 更新日期: 2023-09-27 18:02:30

我们已经为我们的网站实现了https,所以基本上我们所做的是实现重定向。

       <rewrite>
            <rules>
                <rule name="rule - name" enabled="true" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://yourpath" redirectType="youttype" />
                </rule>
            </rules>
        </rewrite>

重定向工作正常,但我有一个问题。有些用户在书签中保存了旧的路径,比如http://applicationName/Account/Login?ReturnUrl=%2f,重定向是这样的-> https://applicationName/?ReturnUrl=/,我得到的错误你可以看到下面:

401 - Unauthorized:由于无效的凭据而拒绝访问。你没有权限使用?查看此目录或页面您提供的凭据。

到目前为止,我试图解决的问题是添加到我的appsetting在网络。配置一些我看到可以解决问题的东西:

<appSettings>
  <add key="autoFormsAuthentication" value="false" />
  <add key="enableSimpleMembership" value="false"/>
</appSettings>

和Also

<authorization>
  <allow users="*"/>
</authorization>

,但我仍然有相同的问题与重定向。我该如何解决这个问题??

谢谢! !

ASP.. NET重定向到Https问题-错误401

尝试基于匹配而不是静态地构建URL:

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
  <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>