[英]How to add rules to .net core project in *.csproj
我想向 .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但对我不起作用
看到这个。 您应该使用中间件而不是 web.config 来强制执行 https。 https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-3.1&tabs=visual-studio
您仍然可以在需要时在 .NET Core 项目中包含 web.config 文件。 事实上,当您点击“发布”时会生成一个,但还没有一个,这可以为您提供一个制作自定义的起点。
执行以下操作之一:
特别是关于这个文件,有很多令人困惑的信息。 这是一个体面的问题,有体面的答案。 对 .NET Core 中的 web.config 感到困惑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.