0
我已经使用.net核心创建了一个新的Web项目。 默认web配置是这样的:无法将重写规则添加到web.config .net核心
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
当我打开这个配置文件,我得到一个警告,指出:
元素“system.webServer具有无效子元素“aspNetCore”。
但它让我建立并运行我的项目。 我的项目是一个角度应用程序,所以我想添加html5mode。 要做到这一点,我应该可以加我重写规则:
<rewrite>
<rules>
<!-- AngularJS Html5model -->
<rule name="AngularJS Html5model" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
的问题是,当我加入我的规则,以我的web.config文件中,就像这样:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<rewrite>
<rules>
<!-- AngularJS Html5model -->
<rule name="AngularJS Html5model" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
我的申请停止工作。这就像它无法弄清什么是静态文件或不是。现在找不到任何静态文件。 看规则,它会静态地将任何文件重定向到“/”。 有谁知道如何解决这个问题?