从默认的天蓝色域重定向

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

我正在Azure(namewebsite.azurewebsites.net)上运行.NET Core 3.1网站(C#,Windows)。我找不到任何将所有流量从namewebsite.azurewebsites.net重定向到www.example.com的解决方案。例如:当某人访问https://namewebsite.azurewebsites.net/profile/data时,应完成对https://www.example.com/profile/data的永久重定向。有什么想法吗?

c# azure-web-sites asp.net-core-3.1
2个回答
0
投票

我不确定确切的要求,但是当涉及到重定向时,您可以做的是编辑computes host.txt文件并在其中添加重定向,

C:\Windows\System32\drivers\etc\hosts

https://en.wikipedia.org/wiki/Hosts_(file)

127.0.0.1  https://namewebsite.azurewebsites.net/profile/data

https://www.online-tech-tips.com/computer-tips/edit-windows-hosts-file-to-block-redirect-websites/


0
投票

您通常可以通过在web.config中定义重写规则并使用正则表达式和重定向操作来评估HTTP_HOST来实现此目的。

<system.webServer>  
<rewrite>  
    <rules>  
      <rule name=“Origin URL Redirect stopProcessing="true">
        <match url="(.*)" />  
        <conditions logicalGrouping="MatchAny">
          <add input="{HTTP_HOST}" pattern="^namewebsite\.azurewebsites\.net$" />
        </conditions>
        <action type="Redirect" url="http://www.example.com/{R:0}" />  
      </rule>  
    </rules>  
</rewrite>  

在ASP.NET Core中,您仍然可以通过URL Rewriting Middleware实现。如果您需要满足非www子域请求的要求,也会有所帮助。

另一种选择,根据WAF等其他需求,请考虑在您的应用程序服务前使用Azure Front Door,并且仅允许从前门到您的应用程序服务的流量。

© www.soinside.com 2019 - 2024. All rights reserved.