C# 从发布文件夹在IIS中部署后无法访问的.net核心Web API
在我的.net core 3.1应用程序中,我将Web API和angular应用程序添加到clientFolder 问题是,当我使用IISServer从VisualStudio直接运行应用程序时,一切都运行得很好 但是,从发布文件夹在IIS中部署应用程序后,web API部件无法工作 加载了用户界面和招摇过市部分 启动文件:C# 从发布文件夹在IIS中部署后无法访问的.net核心Web API,c#,angular,asp.net-web-api,.net-core,C#,Angular,Asp.net Web Api,.net Core,在我的.net core 3.1应用程序中,我将Web API和angular应用程序添加到clientFolder 问题是,当我使用IISServer从VisualStudio直接运行应用程序时,一切都运行得很好 但是,从发布文件夹在IIS中部署应用程序后,web API部件无法工作 加载了用户界面和招摇过市部分 启动文件: namespace TestApp { public class Startup { public Startup(IConfigurat
namespace TestApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(MyAllowSpecificOrigins,
builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});
});
services.AddControllersWithViews();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist/TestAppUI";
});
services.AddSwaggerGen();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "DO Admin API");
});
app.UseStaticFiles();
if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}
app.UseRouting();
app.UseCors(MyAllowSpecificOrigins);
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
}
}
}
API调用返回304未修改的HTML响应
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TestAppUI</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="styles.dc819048a0054fcb6932.css"></head>
<body class="main-body">
<app-root></app-root>
<script src="runtime-es2015.cdfb0ddb511f65fdc0a0.js" type="module"></script><script src="runtime-es5.cdfb0ddb511f65fdc0a0.js" nomodule defer></script><script src="polyfills-es5.f19fc0a3e24e5df6cb6e.js" nomodule defer></script><script src="polyfills-es2015.dc4fd68f0a557169bd87.js" type="module"></script><script src="main-es2015.d0017b3969d32d14fb8c.js" type="module"></script><script src="main-es5.d0017b3969d32d14fb8c.js" nomodule defer></script></body>
</html>
TestAppUI
您还可以分享api方法如何返回结果吗?您的IIS web.config中是否有url重写规则?如果您尝试删除它们,则对angular应用程序的重写已经由中间件处理。@J.Loscos我确实有一个web.Config,其中的内容在描述中更新。如果我没有,我会得到问题中的错误Description@tontonsevilla该方法返回ActionResult EX:[HttpGet]public ActionResult GetConfigs(){return ConfigRepository.GetAllConfigs();}@TBA,这是干什么用的<代码>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\DOAdminV2.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>