我要几天才能将网站发布到IIS。我可以看到前端正在将物理路径设置为Client/dist
,但是我无法连接到服务器。我的技术堆栈为Angular8, Asp.net Core 3.1
。我实际上不知道还能做些什么。有任何见解或想法吗?
我做了什么:
1.我将Physcap路径设置为内置文件所在的Client/dist
。
2.我将如下所示的应用程序根目录配置放入appsetting中。
网站绑定
应用程序池
物理路径
appsetting.json
"AllowedHosts": "*",
"JwtIssuerOptions": {
"Issuer": "webApi",
"Audience": "http://localhost:4200/"
},
"App": {
"ServerRootAddress": "http://localhost:21021/",
"ClientRootAddress": "http://localhost/Client/dist",
"CorsOrigins": "http://localhost/Client/dist"
}
"ConnectionStrings": {
"connectionstring": "connection string here",
},
startup.cs
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.WithOrigins("http://localhost:4200", "http://localhost:44318")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
services.AddSpaStaticFiles(Configuration =>
{
Configuration.RootPath = "Client/dist";
});
-------------------------------------
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseCors("CorsPolicy");
app.UseExceptionHandler(
builder =>
{
builder.Run(
async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
var error = context.Features.Get<IExceptionHandlerFeature>();
if (error != null)
{
context.Response.AddApplicationError(error.Error.Message);
await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
}
});
});
app.UseRouting();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
//app.UseMvc();
app.UseSpa(spa =>
{
spa.Options.SourcePath = "Client";
spa.UseAngularCliServer(npmScript: "start");
});
]