大佬教程收集整理的这篇文章主要介绍了如何设置uri重写以读取特定的url或文件?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我对如何使用 uri 重写有点困惑。我有一个包含 c# web API 2 和 angular 的项目,我想从 web API 获取数据。所以我在我的 web.config
中使用它:
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJs Routes" 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}" pattern="^/(API)" negate="true" />
</conditions>
<action type="Rewrite" url="./index.HTML" />
</rule>
</rules>
</rewrite>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONsverbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferrequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
我希望通过键入 index.HTML
打开 http://localhost/
。但是我得到 http 404 找不到资源。 但是当我输入 http://localhost/index.HTML
时,我的程序开始正常工作,没有任何问题。我想知道如何通过输入 http://localhost/
来实现这一点
经过研究,我找到了一种获取 .html 类型文件的方法,因此我像这样更改了 web.config
文件:
<compilation debug="true" targetFramework="4.7.2">
<buildProviders >
<add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
<add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>
然后我的应用程序运行良好。
以上是大佬教程为你收集整理的如何设置uri重写以读取特定的url或文件?全部内容,希望文章能够帮你解决如何设置uri重写以读取特定的url或文件?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。