我最近将我的应用程序发布到本地的 IIS 服务器中,以在下一个路径下测试我的应用程序:%SystemDrive%\inetpub\wwwroot\PDS
这是“Startup.cs”文件下我的应用程序配置:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddCors();
services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder => {
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
/* Here I have my DB connections */
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
} else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCors("AllowAll");
app.UseCors("AllowAll");
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa => {
spa.Options.SourcePath = "ClientApp";
if(env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
spa.Options.StartupTimeout = TimeSpan.FromSeconds(2000);
}
});
}
}
发布应用程序后我的 web.config 文件是这样的:
<?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=".\PDS.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
当我通过使用 IIS 给定的路径运行应用程序时,我的应用程序“加载”,但我在控制台中收到下一个错误:
PDS/:9 GET http://MyServer/styles.71dabd29525fe744.css net::ERR_ABORTED 404 (Not Found)
PDS/:23 GET http://MyServer/main.d97cc394db065bba.js net::ERR_ABORTED 404 (Not Found)
PDS/:23 GET http://MyServer/runtime.04ca1c1b9692da3f.js net::ERR_ABORTED 404 (Not Found)
PDS/:25 GET http://MyServer/assets/Images/webb.png 404 (Not Found)
PDS/:23 GET http://MyServer/polyfills.059cb375bf3e0530.js net::ERR_ABORTED 404(Not Found)
aaaicon.ico:1 GET http://MyServer/assets/aaaicon.ico 404 (Not Found)
我尝试过使用不同的方法,例如“UseSpaStaticFiles()”,但也不起作用。 我的 TS 文件中的路线很好,我的日志没有显示重要信息来了解发生了什么。我还能尝试什么让这些文件正常工作?
转到应用程序的路径,右键单击该文件夹,然后选择“属性”并转到“安全”选项卡,从那里允许 IIS 用户使用所有可用选项。然后在 IIS 中重新启动应用程序轮询并再次启动应用程序