【发布时间】:2020-07-26 04:29:39
【问题描述】:
我正在使用带有角度的 ASP.net 核心样板。我尝试在 IIS localhost 下单独托管这两个应用程序的 Angular 网站和 .NET 核心网站,没有问题。
:
但是当我想在公共上部署我的应用程序时,我遇到了这个问题:
1- 我只有一个重定向到 IIS 默认网站的公共 IP,每个应用程序都有不同的端口。
**因此,前端和后端都应托管在具有不同端口的 IIS 默认网站下。
这适用于 .NET core 和 Angular 吗?**
更新
这是我的 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"
}
}
}
更新 2
Angular web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
</staticContent>
<!-- IIS URL Rewrite for Angular routes -->
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Angular appconfig.production.json
{
"remoteServiceBaseUrl": "http://localhost:21021",
"appBaseUrl": "http://localhost:4200",
"localeMappings": [
{
"from": "pt-BR",
"to": "pt"
},
{
"from": "zh-CN",
"to": "zh"
},
{
"from": "he-IL",
"to": "he"
}
]
}
【问题讨论】:
-
即使使用一个 IP 地址,您也可以在端口 80 上托管多个站点(不同的主机名)。停止使用不同端口的想法,因为这只会使事情变得复杂。
-
@LexLi 我在服务器 x 上的公共 IP 和我在服务器 Y 上托管项目,我的 X 服务器将请求重定向到 Y IIS 服务器。我不知道他们为什么这样做,但我无法改变这种情况。
-
那么您在服务器 X 上拥有/安装了什么?通常人们在那里有一个反向代理,但你真的需要先了解你有什么。使用反向代理,您几乎可以做任何您喜欢的事情(例如docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/…)。
标签: angular asp.net-core iis web-hosting aspnetboilerplate