.net core service && angular项目 iis发布 - zLulus/My_Note GitHub Wiki
.net core 后端服务站点
angular 前端页面站点
.Net Core使用IIS部署出现502Error 502.5 - Process Failure
在项目目录运行命令行,执行
dotnet XXXWeb.dll --XXXWeb.dll是启动项
如果.net core版本不对,则会提示需要安装某版本的.net core
完成安装即可
参考资料
在appsettings.json中设置客户端地址ClientRootAddress
"App": {
"ServerRootAddress": "http://localhost:3521/",
"ClientRootAddress": "http://localhost:4201/",
"CorsOrigins": "*"
}
在Startup.cs
ConfigureServices
方法中设置跨域
// Configure CORS for angular2 UI
services.AddCors(
options => options.AddPolicy(
_defaultCorsPolicyName,
builder => builder
.WithOrigins(
// App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
//读取配置文件CorsOrigins信息
_appConfiguration["App:CorsOrigins"]
//不同Url以逗号分隔
.Split(",", StringSplitOptions.RemoveEmptyEntries)
.Select(o => o.RemovePostFix("/"))
.ToArray()
)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
)
);
发布前记住关闭swagger ui等开发工具
关闭swagger ui,可以选择删去.xml文件,则swagger页面会报错
在angular项目文件中执行
ng build --prod --aot
新部署方法参见Angular前端项目发布到IIS
解决相关报错,生成dist文件夹,包括
bundle
XXX --XXX是你的项目名
在IIS中,新建站点,将XXX文件夹作为根目录
在XXX文件夹中新建文件web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
在/XXX/assets/appconfig.prod.json中设置service地址remoteServiceBaseUrl
{
"remoteServiceBaseUrl": "http://localhost:3521"
}
因为Angular无刷新的特性,所以浏览器地址栏上的网址其实不会映射到磁盘的特定位置,所以我们需要安装Microsoft URL Rewrite Module 2.0 for IIS (x64)
注意Angular项目所在目录的访问权限,可以设置为EveryOne
https://blog.csdn.net/qq_32688731/article/details/80996669
https://angular.io/guide/deployment#server-configuration
https://www.cnblogs.com/dennis0525/p/7631245.html