![](/img/trans.png)
[英]ASP.NET Web API 2 - How to implement OAuth2.0 for SPA applications
[英]How to circumvent the .NET 6 SPA proxy for Angular applications?
編輯:我設法使用有效證書通過IIS
運行它,但我還沒有找到放棄新代理方法的方法。 如果您想了解有關使用IIS
而不是IIS Express
的信息,請跳至結束。
In short: Using the latest ASP.NET 6
and Angular
template (Visual Studio 2022), how do you go about bypassing the reverse proxy and instead use the same approach as pervious version of .NET? 我不想通過 SPA URL 運行應用程序,后端請求被轉發到 SPA 代理。
詳細來說,我的目標:
我想導航到https://mydomain.local並讓它服務於一切,這在 .NET 6 之前沒有問題。你會使用UseProxyToSpaDevelopmentServer
,運行npm start
盡管我知道您仍然可以使用它,但 .NET 6 放棄了Startup.cs
,並且指南建議繼續使用簡化的Program.cs
。
我努力了:
aspnetcore-https.js
)angular.json
中刪除 proxyConfig 屬性來擺脫代理配置( proxy.conf.js
)angular.json
中定義一個非默認主機似乎沒有任何效果,文檔也不是很好。
眼下:
SpaProxyServerUrl
屬性定義的值任何幫助將非常感激。
我不確定自簽名 ASP.NET 證書有什么問題。 我只是刪除了它的所有引用並再次添加它們。
%AppData%\Roaming\ASP.NET\https
中刪除證書chrome://net-internals/#hsts
清除域的所有安全策略chrome://settings/clearBrowserData
)run command: mmc
File --> Add/Remove Snap-In --> Certificates
)。 刪除個人證書和受信任的根證書dotnet dev-certs https --trust
再次生成證書要放棄 IIS Express 並回復正常的 IIS 實例:
https
綁定,我建議使用mkcert
創建一個有效的自簽名證書。launchSettings.json
中定義的端口匹配launchSettings.json
,隨意刪除您不需要的任何配置文件。 你想要類似的東西:{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "https://yourdomain.local",
"sslPort": 443
}
},
"profiles": {
"IIS": {
"commandName": "IIS",
"launchBrowser": true,
"launchUrl": "https://yourdomain.local",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
}
}
}
const PROXY_CONFIG = [
{
context: [
"/yourRoute",
],
target: "https://yourdomain.local:443",
secure: false,
changeOrigin: true,
logLevel: "info",
headers: {
Connection: 'Keep-Alive'
}
}
]
module.exports = PROXY_CONFIG;
.csproj
文件並確保在<SpaProxyServerUrl></SpaProxyServerUrl>
中定義的端口與使用的angular.json
匹配就是這樣,你會對 go 很好。 手動啟動 Angular 應用程序,訪問https://yourdomain.local
一切都應該是精明的。
我希望我能很好地理解你想要做什么。 我所做的是我可以手動啟動 angular 並且不需要在每個服務器端重新啟動更改是將以下內容添加到我的 package.json。
{
...
"scripts": {
"dev": "set ASPNETCORE_HTTPS_PORT=7186 && npm start"
}
...
}
將“7186”更改為運行.Net 6 服務器的端口。 在你的 443 中。然后運行“npm run dev”等待它加載並啟動后端服務器。
希望這對將來有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.