【发布时间】:2018-07-31 02:01:09
【问题描述】:
我在 Azure 上有一个带有 AspNetCore WebAPI + AngularApp 的 WebApp,在我的 Web.Config 中有 IIS 重写规则,基于这篇文章:https://weblog.west-wind.com/posts/2017/Apr/27/IIS-and-ASPNET-Core-Rewrite-Rules-for-AspNetCoreModule
我想避免在 Swagger 上重写,所以我将这条规则添加为第一条规则:
<rule name="swagger" enabled="true" stopProcessing="true">
<match url="swagger/.*" />
<action type="None" />
</rule>
基于本网站:https://www.regextester.com/
规则应该排除 swagger/ 以及所有子文件夹和文件。但事实并非如此。
这是我打开http://[MYWEBSITE]/swagger/时看到的
Angular 应用程序正常工作。
我已经对此进行了一些搜索:
- How to exclude a directory with IIS URL rewriting?
- How to Exclude Directories from Rules in Web.config (ASP.NET)
- https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
感谢您的帮助。
编辑 1:
只是为了让您知道,使用默认的 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\[MYWEBAPP].Api.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
</system.webServer>
</configuration>
编辑 2:
在我的测试过程中,我删除了重写规则,只关注处理程序,我注意到这些规则有问题:
这很正常,Swagger 是在 .NetCore WebApi 中构建的。我正在寻找一种从处理程序中排除特定文件夹的方法。
基于此回复:IIS Handlers exclude a Directory when processing htm requests
我在 Azure 上的“D:\home\site\wwwroot\wwwroot\swagger”中创建了一个 web.config,配置如下:
<system.webServer>
<handlers>
<remove name="StaticFileModuleHtml" />
<remove name="StaticFileModuleJs" />
<remove name="StaticFileModuleCss" />
<remove name="StaticFileModulePng" />
</handlers>
</system.webServer>
编辑 3:
显然问题来自静态处理程序。 如果我想使用 Swagger,我需要禁用它们。 如果我想访问我的 Angular 应用程序,我需要添加它们。
我在这里看到了:https://github.com/domaindrivendev/Swashbuckle.AspNetCore#swashbuckleaspnetcorecli
似乎可以直接从 SwaggerUi 中提取内容到构建的文件夹中,但目前,Nugget 包不可用: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/601
我会及时通知你。如果有人有想法,那将很有帮助。我可能不是唯一尝试这样做的人:)。
但问题仍然存在。
【问题讨论】:
标签: iis url-rewriting swagger