ASP.NET Core将http重定向到https [英] ASP.NET Core redirect http to https
问题描述
我已经在web.config中创建了重定向规则,以将我的网站从http重定向到https.我的问题是网站上的每个链接现在都是https.我有很多链接到没有SSL的其他网站,因此我收到证书错误.这就是我所做的:
I have created a redirect rules in my web.config to redirect my website from http to https. The issue i have is that every single link on the website is now https. I have a lots of link to other website which don't have SSL and therefore i get certificate errors. This is what i have done:
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
我如何仅针对我的域而不是网站上的每个链接重定向https?
How can i redirect https only for my domain and not every links on my website?
推荐答案
在asp.net Core 2中,您可以使用独立于Web服务器的URL重写,方法是 像这样在Startup.Configure中的app.UseRewriter:
In asp.net Core 2 you can use an URL Rewrite independent of the Web Server, by using app.UseRewriter in Startup.Configure, like this:
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// todo: replace with app.UseHsts(); once the feature will be stable
app.UseRewriter(new RewriteOptions().AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 443));
}
这篇关于ASP.NET Core将http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!