Tro*_*acy 6 iis asp.net-mvc url-rewriting static-files asp.net-mvc-5
如何在ASP.NET MVC5中使用静态文件实现相同的行为,例如它在aspnet-core上的正常工作app.UseDefaultFiles(); app.UseStaticFiles();?
我的意思是从根目录下的某个文件夹提供静态文件,例如/wwwroot/some.html必须在mysite.com/some.html,等等上/wwwroot/img/test.jpg打开mysite.com/img/test.jpg。
更新:我已经创建了wwwroot文件夹,并将以下规则添加到web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Static" stopProcessing="true">
<match url="^(?!(wwwroot/|api/))(.*)$" ignoreCase="true"></match>
<action type="Rewrite" url="/wwwroot/{R:1}" />
</rule>
</rules>
Run Code Online (Sandbox Code Playgroud)
所以,IIS必须返回文件wwwroot除了当来电去/api/something,但我一直都想与index.html在wwwroot文件夹中,从来没有其他文件。Api的网址效果很好。
我做错了什么?
一切都以这种方式进行:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Static" stopProcessing="true">
<match url="^((?!(wwwroot\/|api\/))(.*))$" ignoreCase="true"></match>
<action type="Rewrite" url="/wwwroot/{R:1}" />
</rule>
</rules>
</rewrite>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<remove name="StaticFile"/>
<add
name="StaticFile"
path="*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
<staticContent>
<mimeMap fileExtension=".*" mimeType="application/octet-stream" />
</staticContent>
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
不要忘记安装重写模块。
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |