错误 在应用程序部署 ASP.NET 核心 2 中,"value"中的路径必须以"/"开头



我正在尝试部署一个asp net core 2应用程序,一切似乎都很好,我正在使用VS2017中的deploy Files选项,将该应用程序添加到我的路径inetpub\wwwroot\App1文件夹中。我浏览到路径http://localhost:8088/App1/Home/Index/然后我看到:

ArgumentException:"value"中的路径必须以"/"开头。Nombre del parámetro:价值Microsoft.AspNetCore.Http.PathString.ctor(字符串值(Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder应用程序,字符串错误HandlingPath(OCIndicatorsOperationClientes.Startup.Configure(IApplicationBuilder应用程序,IHostingEnvironment环境(System.Runtime.ExceptionServices.ExceptionDispatchInfo.Sthrow((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=".logsstdout" />
</system.webServer>
</configuration>

你看到错误了吗?我将感谢你的帮助!

根据堆栈跟踪,错误发生在以下行:

app.UseExceptionHandler("App1/Home/Error");

目前您正在使用UseExceptionHandler的重载,它需要URL路径:

public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseExceptionHandler (
this Microsoft.AspNetCore.Builder.IApplicationBuilder app, 
string errorHandlingPath);

注意,errorHandlingPath参数需要正确的URL格式,因为它将用于调用PathString构造函数,因此您应该在URL:的开头添加斜线

app.UseExceptionHandler("/App1/Home/Error");

类似的问题:Startup.cs-路径在';值';必须以'/';

我也遇到了这个问题。它的出现是因为异常处理路径预计以"/"开头

错误是:

ArgumentException:"value"中的路径必须以"/"开头。Nombre del parámetro:value Microsoft.AspNetCore.Http.PathString.ctor(字符串值(Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder应用程序,字符串错误HandlingPath(

通过替换修复

app.UseExceptionHandler("Home/Error");

带有

app.UseExceptionHandler("/Home/Error");

您也可以尝试使用进行部署

app.UseDeveloperExceptionPage();

并查找错误(如果有的话(。

相关内容

最新更新