我正在使用带角度的ASP.net核心样板。我尝试将两个应用程序分别托管在Angular网站和IIS localhost下的.NET Core网站上,都没有问题。:但是,当我想在公共场所部署我的应用程序时,我遇到了这个问题:1-我只有一个公共IP重定向到IIS默认网站,并且每个应用程序都有一个不同的端口。**因此,前端和后端都应使用不同的端口托管在IIS默认网站下。
更新
这是我的appsetting.json
{
"ConnectionStrings": {
"Default": "Server=localhost\\SQLEXPRESS; Database=MyDb;User Id=admin;Password=1234"
},
"App": {
"ServerRootAddress": "http://localhost:21021/",
"ClientRootAddress": "http://localhost:4200/",
"CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081,http://localhost:3000"
},
"Authentication": {
"JwtBearer": {
"IsEnabled": "true",
"SecurityKey": "MyApp_C421AAEE0D114E9C",
"Issuer": "MyApp",
"Audience": "MyApp"
}
}
}
只有您的有角度的网站应该是公开的。每个IIS网站都需要一个唯一的端口。https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Deployment-Angular-Publish-IIS
也请在您的IIS主机网站中检出appSettings.json用于
"App": {
"ServerRootAddress": "http://localhost:21021/", -> Host
"ClientRootAddress": "http://localhost:4200/", -> Angular
"CorsOrigins": "http://localhost:4200" -> your domain, https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.1
},
如果您已合并Angular和Host项目:https://aspnetboilerplate.com/Pages/Documents/Zero/Startup-Template-Angular#merged-project
以下是一些步骤:
先决条件
前端:
使用npm run build建立您的角度
转到IIS中的默认网站
添加应用程序
添加别名并在角度应用程序中将物理路径指向您的dist文件夹
您可以测试此http://localhost/client-alias
后端
发布API项目,以便我们可以将内容复制到API服务的新Web应用程序。
使用.net CLR版本将应用程序池创建为无托管代码
在IIS中为API服务创建一个新的Web应用程序,其中在步骤9中添加了应用程序池,并在步骤8中添加了已发布文件夹的物理路径。
现在这两个应用程序以http://127.0.0.1/client-alias和http://127.0.0.1/service-alias的身份运行>
您可以公开IP(8080),而无需打开其他端口。