我正在尝试部署一个ASP Net Core 2应用程序,似乎一切正常,我正在VS2017中使用deploy Files选项,将其添加到我的路径inetpub \ wwwroot \ App1文件夹中,然后添加了该应用程序。 我浏览到路径http://localhost:8088/App1/Home/Index/ 然后我看到了:
ArgumentException:“值”中的路径必须以“ /”开头。 Nombre delparámetro:价值 Microsoft.AspNetCore.Http.PathString..ctor(字符串值) Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder 应用,字符串errorHandlingPath) OCIndicadoresOperativoClientes.Startup.Configure(IApplicationBuilder app,IHostingEnvironment env)在Startup.cs中 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder 应用程式) Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter + <> c__DisplayClass3_0.b__0(IApplicationBuilder 应用程式) Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter + <> c__DisplayClass0_0.b__0(IApplicationBuilder 建造者) Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
在下面您可以看到Startup.cs的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace App1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
services.AddMvc().AddSessionStateTempDataProvider();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(25);
options.Cookie.HttpOnly = true;
});
services.AddAuthenticationCore();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseExceptionHandler("App1/Home/Error");
app.UseStaticFiles();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "Home",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "Shippers",
template: "{controller=ControllerB}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
routes.MapSpaFallbackRoute(
name: "ControllerB",
defaults: new { controller = "ControllerB", action = "Index" });
});
}
}
}
另外,我将提供有关webconfig的详细信息:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\App1.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
您看到任何错误吗?我将感谢您的帮助!
答案 0 :(得分:0)
基于堆栈跟踪,此行中发生了错误:
public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseExceptionHandler (
this Microsoft.AspNetCore.Builder.IApplicationBuilder app,
string errorHandlingPath);
当前,您正在使用UseExceptionHandler
的此重载,它需要URL路径:
errorHandlingPath
请注意,app.UseExceptionHandler("/App1/Home/Error");
参数需要正确的URL格式,因为它将用于调用PathString
构造函数,因此您应在URL的开头添加斜杠:
{{1}}
答案 1 :(得分:0)
我也遇到了这个问题。之所以这样,是因为异常处理路径应以“ /”开头
错误是:
ArgumentException:“值”中的路径必须以“ /”开头。参数:值Microsoft.AspNetCore.Http.PathString..ctor(字符串值)Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder应用程序,字符串errorHandlingPath)
已通过替换
修复 app.UseExceptionHandler("Home/Error");
使用
app.UseExceptionHandler("/Home/Error");
您还可以尝试使用
进行部署 app.UseDeveloperExceptionPage();
并找到错误(如果有)。