Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将重写规则应用于ASP.NET项目中包含的HTML文件?_Asp.net_Azure_Url Rewriting - Fatal编程技术网

如何将重写规则应用于ASP.NET项目中包含的HTML文件?

如何将重写规则应用于ASP.NET项目中包含的HTML文件?,asp.net,azure,url-rewriting,Asp.net,Azure,Url Rewriting,我有一个使用ASP.NET构建的项目。我在其他人构建的项目中包括平面文件HTML。没有与这些页关联的控制器 我正在尝试将所有页面上的HTTP重定向到HTTPS。在熟悉了似乎无法应用的web.config重写规则之后,我终于在global.asax中实现了以下代码作为最后手段: protected void Application_BeginRequest(Object sender, EventArgs e) { if (HttpContext.Curre

我有一个使用ASP.NET构建的项目。我在其他人构建的项目中包括平面文件HTML。没有与这些页关联的控制器

我正在尝试将所有页面上的HTTP重定向到HTTPS。在熟悉了似乎无法应用的web.config重写规则之后,我终于在global.asax中实现了以下代码作为最后手段:

protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
            {
                Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
            + HttpContext.Current.Request.RawUrl);
            }
        }
现在,当我使用
http://www.example.com
我被重定向到
https://www.example.com
,万岁

除非我仍然可以使用HTTP导航到其他页面

似乎这些规则只适用于单独导航到域以及我的任何API控制器时

我在web.config中仍然有重写规则:

<rewrite>
  <rules>
    <rule name="Enforce SSL" enabled="true" stopProcessing="true">
      <match url="/?(secure.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" />
    </rule>
  </rules>
</rewrite>

但这些不适用于我在项目中包含的文件

如何将重写规则应用于包含在项目中的平面HTML文件


值得一提的是,这是一个Azure网站角色。

我不是一个重写规则向导,但规则定义上的enabled=“false”看起来可疑

这适用于我(在system.webServer内部):


这要归功于Maarten Balliauw(),他不久前与我分享了这一点。经过几次尝试,我最终选择了仿制意大利面。那是最新的。更改为
true
,但仍然没有运气。
<rewrite>
  <rules>
    <rule name="Force HTTPS" enabled="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action 
          type="Redirect" 
          url="https://{HTTP_HOST}/{R:1}" 
          appendQueryString="true"
          redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>