我有一个AngularJS应用程序,它利用URL重写进行链接.我的重写规则如下:
<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="^api/(.*)" negate="false" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
Run Code Online (Sandbox Code Playgroud)
我在SO上找到了这个解决方案:如何在HTML5模式下为URL重写AngularJS应用程序配置IIS?并进行了一次修改以允许我的API通过.
基本上,我想将我的所有请求重定向Default.cshtml到我的Web API的EXCEPT调用.当我我加载在基础URL应用这个伟大的工程,如:localhost/myapp.但是,如果我在一个有角度的路线上重新加载页面:localhost/myapp/dashboard它失败说:
<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost/myapp/dashboard'.</Message>
<MessageDetail>No type was found that matches the controller named 'dashboard'.</MessageDetail></Error>
Run Code Online (Sandbox Code Playgroud)
我有一个解决方法:
<rewrite>
<rules>
<rule name="Default" stopProcessing="true">
<match url="^(?!lib|api|dist|assets|app/|bower|common|main|signalr|templates|bower_components/).*" />
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
它工作得很好.任何想法如何我可以利用上面的清洁解决方案仍然完成重写?
我需要的格局和变化而变化{REQUEST_FILE},以{REQUEST_URI}在几个地方.在这里看我的演示:
<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2667 次 |
| 最近记录: |