【发布时间】:2020-10-07 07:36:24
【问题描述】:
我想向 .net 核心项目添加规则。 在 .net 普通项目中,我可以直接编辑 web.config 文件
实际上我需要在 .net 核心项目中实现这一点
<?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="dotnet" arguments=".\RazorWeb.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
<system.webServer>
<rewrite>
<!---START:ADD THIS RULES-->
<rules>
<rule name="httpTohttps" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<!---END:ADD THIS RULES-->
</rewrite>
</system.webServer>
</configuration>
好吧,自从我在 .net core 中引入之后,我注意到模板项目没有附带这个 .config 文件,但是模板使用 .csproj 文件和 .json 文件来添加配置等...
主要思想是如何在.net核心项目中实现这一点,我在不同的站点中搜索,微软的文档在这方面对我来说并不完全清楚,我找到的最接近的就是这个
https://roslyn-analyzers.readthedocs.io/en/latest/config-analyzer.html 但对我不起作用
【问题讨论】:
标签: c# web .net-core web-config csproj