ASP.NET 核心 3 - 有没有办法将模块部分添加到生成的 Web 配置文件中
ASP.NET Core 3 - Is there a way to add Module section to produced Web Config File
如标题中所述,我正在向 IIS 发布 ASP.NET Core 3 API。当我发布 API 时,系统会在部署目录中创建一个 Web 配置文件,其中包含:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\xxxxx.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: daddb75b-3c54-4970-8945-8404ade81fbc-->
一切正常,但我想做的是在 System.webServer 部分添加下面的三行,以解决此 link:https://fantinel.dev/net-core-api-method-not-allowed-on-put-and-delete-requests/
摘录以供解释:
What happens is that, when published, .NET Core enables the
WebDAVModule, which disables PUT and DELETE requests by default.
因此,要获得 PUT 和 DELETE 动词,我们必须使用以下行禁用此 WebDAVModule:
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
有没有办法自动将这些行包含到 produced/published web.config 中?在 VS 解决方案中,我没有看到任何 Web.Config 文件或驱动部署输出的选项。
谢谢大家的建议。
刚刚发现,当你自己添加一个web.config
文件时,发布向导会把正常生成的web.config和你自己定义的文件结合在一起。例如:
否 web.config ==> 产生以下 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 7b031640-46da-4eac-b60c-740bd3659fce-->
在 ASP.NET 核心项目的根目录中关注 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</location>
</configuration>
产生以下 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
因此 ASP.NET 核心部署似乎结合了两个 xml。我正在使用 ASP.NET Core 3.1。
如标题中所述,我正在向 IIS 发布 ASP.NET Core 3 API。当我发布 API 时,系统会在部署目录中创建一个 Web 配置文件,其中包含:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\xxxxx.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: daddb75b-3c54-4970-8945-8404ade81fbc-->
一切正常,但我想做的是在 System.webServer 部分添加下面的三行,以解决此 link:https://fantinel.dev/net-core-api-method-not-allowed-on-put-and-delete-requests/ 摘录以供解释:
What happens is that, when published, .NET Core enables the WebDAVModule, which disables PUT and DELETE requests by default.
因此,要获得 PUT 和 DELETE 动词,我们必须使用以下行禁用此 WebDAVModule:
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
有没有办法自动将这些行包含到 produced/published web.config 中?在 VS 解决方案中,我没有看到任何 Web.Config 文件或驱动部署输出的选项。
谢谢大家的建议。
刚刚发现,当你自己添加一个web.config
文件时,发布向导会把正常生成的web.config和你自己定义的文件结合在一起。例如:
否 web.config ==> 产生以下 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 7b031640-46da-4eac-b60c-740bd3659fce-->
在 ASP.NET 核心项目的根目录中关注 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</location>
</configuration>
产生以下 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
因此 ASP.NET 核心部署似乎结合了两个 xml。我正在使用 ASP.NET Core 3.1。