Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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 Url重写为小写不起作用_Asp.net_Url Rewriting_Web Config - Fatal编程技术网

Asp.net Url重写为小写不起作用

Asp.net Url重写为小写不起作用,asp.net,url-rewriting,web-config,Asp.net,Url Rewriting,Web Config,我的web.config中有以下重写规则。规范规则有效,但小写规则无效 我试着这样测试它:www.mysite.com/UPPERCASE。我本以为url会被转换为www.mysite.com/uppercase,但它仍然是大写的。我做错了什么 <rewrite xdt:Transform="Insert"> <rules> <rule name="LowerCaseRule" patternSyntax="ExactMatch"> &

我的web.config中有以下重写规则。规范规则有效,但小写规则无效

我试着这样测试它:www.mysite.com/UPPERCASE。我本以为url会被转换为www.mysite.com/uppercase,但它仍然是大写的。我做错了什么

<rewrite xdt:Transform="Insert">
  <rules>
    <rule name="LowerCaseRule" patternSyntax="ExactMatch">
      <match url="[A-Z]" ignoreCase="false"/>
      <action type="Redirect" url="{ToLower:{URL}}"/>
    </rule>
    <rule name="CanonicalHostName">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www.mysite.com$" negate="true" />
      </conditions>
      <action type="Redirect" url="{MapSSL:{HTTPS}}www.mysite.com/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
  <rewriteMaps>
    <rewriteMap name="MapSSL" defaultValue="OFF">
      <add key="ON" value="https://" />
      <add key="OFF" value="http://" />
    </rewriteMap>
  </rewriteMaps>
</rewrite>

您应该从规则
小写字母
中删除
patternSyntax=“ExactMatch”
,因为在您的情况下,您希望使用正则表达式系统(默认情况下或通过设置
patternSyntax=“ECMAScript”

所以你的规则应该是:

<rule name="LowerCaseRule">
  <match url="[A-Z]" ignoreCase="false"/>
  <action type="Redirect" url="{ToLower:{URL}}"/>
</rule>

试试这个

<rule name="LowerCaseRule" stopProcessing="true">
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{URL}" pattern=".*[A-Z].*" ignoreCase="false" />
        </conditions>
        <action type="Redirect" url="{ToLower:{URL}}" />
    </rule>

这对我来说更好。我注意到,
{URL}
无法正确解析当您有类似于
cassete.axd/scripts/myscript.js?xxx
的路径时,它将重定向到
caste.axd?xxx

    <rule name="LowerCaseRule - HTTPS">
      <match url="[A-Z]" ignoreCase="false"/>
      <conditions>
        <add input="{HTTPS}" pattern="on" ignoreCase="true"/>
      </conditions>
      <action type="Redirect" url="https://{ToLower:{HTTP_HOST}}{ToLower:{PATH_INFO}}" appendQueryString="true"/>
    </rule>

    <rule name="LowerCaseRule - HTTP">
      <match url="[A-Z]" ignoreCase="false"/>
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
      </conditions>
      <action type="Redirect" url="http://{ToLower:{HTTP_HOST}}{ToLower:{PATH_INFO}}" appendQueryString="true"/>
    </rule>

希望这对别人有帮助