gpt4 book ai didi

asp.net-mvc - 如何在asp.net C#中从http重定向到https并使其成为网站的默认版本

转载 作者:行者123 更新时间:2023-12-04 13:03:33 28 4
gpt4 key购买 nike

如何在 asp.net c# 中从 http 重定向到 https 我现在已经安装了 https 证书我想将 https 作为我的网站的默认版本 iam 使用 windows server 2008 R2 asp.net C# 4.0

最佳答案

你在寻找这样的东西吗:-

if (!Request.IsLocal && !Request.IsSecureConnection)
{
string sUrl = Request.Url.ToString().Replace("http:", "https:");
Response.Redirect(sUrl);
}

另请检查此相关 forum .

从上面的链接: -

您可以安装网址 Rewrite Module ,创建重定向规则并将其放入您的 web.config文件
<rule name="http to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
</rule>

关于asp.net-mvc - 如何在asp.net C#中从http重定向到https并使其成为网站的默认版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19474437/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com