[英]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.