mon*_*yDo 7 asp.net iis visual-studio angular
编辑:我设法使用有效证书通过 IIS 运行此程序,但我还没有找到放弃新代理方法的方法。如果您想了解有关使用 IIS 而不是 IIS Express 的一些信息,请跳至结尾。
简而言之:使用最新的 ASP.NET 6 和 Angular 模板 (Visual Studio 2022),如何绕过反向代理并使用与以前版本的 .NET 相同的方法?我不想通过 SPA URL 运行应用程序,并将后端请求转发到 SPA 代理。
详细来说,我的目标:
我想导航到https://mydomain.local并让它为所有内容提供服务,这在 .NET 6 之前不是问题。您可以使用UseProxyToSpaDevelopmentServer、运行npm start,一切都很好。
尽管我知道您仍然可以使用它,但 .NET 6 放弃了它Startup.cs,并且指南建议继续使用简化版Program.cs。
我努力了:
aspnetcore-https.js)proxy.conf.js通过删除 proxyConfig 属性来摆脱代理配置 ( )angular.jsonangular.json似乎没有任何效果,文档也不是很好。
眼下:
SpaProxyServerUrlcsproj 文件中的属性定义的值任何帮助将非常感激。
我不确定自签名 ASP.NET 证书有什么问题。我只是删除了它的所有引用并再次添加它们。
%AppData%\Roaming\ASP.NET\httpsinetcpl.cpl:)chrome://net-internals/#hstschrome://settings/clearBrowserData)mmc文件 --> 添加/删除管理单元 --> 证书)。删除个人证书和受信任的根证书dotnet dev-certs https --trust要放弃 IIS Express 并回复普通 IIS 实例:
mkcert来创建有效的自签名证书。launchSettings.jsonlaunchSettings.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"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
angular.json以相应地引用它。const PROXY_CONFIG = [
{
context: [
"/yourRoute",
],
target: "https://yourdomain.local:443",
secure: false,
changeOrigin: true,
logLevel: "info",
headers: {
Connection: 'Keep-Alive'
}
}
]
module.exports = PROXY_CONFIG;
Run Code Online (Sandbox Code Playgroud)
.csproj文件并确保其中定义的端口与<SpaProxyServerUrl></SpaProxyServerUrl>使用的端口匹配angular.json就是这样,你就可以走了。手动启动 Angular 应用程序,访问https://yourdomain.local,一切都应该很清楚。
小智 2
我所做的就是将以下内容添加到我的 package.json 中,这样我就可以手动启动 Angular 并且不需要在每次服务器端更改时重新启动。
{
...
"scripts": {
"dev": "set ASPNETCORE_HTTPS_PORT=7186 && npm start"
}
...
}
Run Code Online (Sandbox Code Playgroud)
将 更改7186为 .Net 6 服务器运行的端口(在您的情况下为 443)。然后运行“npm run dev”,等待它加载并启动后端服务器。
| 归档时间: |
|
| 查看次数: |
9460 次 |
| 最近记录: |