【问题标题】:Error The path in 'value' must start with '/' in ASP.NET Core 2 in application deploy错误在应用程序部署中的 ASP.NET Core 2 中的“值”中的路径必须以“/”开头
【发布时间】:2019-04-03 21:17:43
【问题描述】:

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

ArgumentException:“value”中的路径必须以“/”开头。 Nombre del parametro: 价值 Microsoft.AspNetCore.Http.PathString..ctor(字符串值) Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder 应用程序,字符串错误处理路径) OCIndicadoresOperativoClientes.Startup.Configure(IApplicationBuilder 应用程序,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>

您是否发现任何错误?感谢您的帮助!

【问题讨论】:

    标签: asp.net-mvc asp.net-core deployment visual-studio-2017


    【解决方案1】:

    根据堆栈跟踪,错误发生在这一行:

    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 - The path in 'value' must start with '/'

    【讨论】:

      【解决方案2】:

      我也有这个问题。这是因为异常处理路径应该以“/”开头

      错误是:

      ArgumentException:“value”中的路径必须以“/”开头。参数名称: value Microsoft.AspNetCore.Http.PathString..ctor(string value) Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder app, string errorHandlingPath)

      通过替换修复

        app.UseExceptionHandler("Home/Error");
      

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

      你也可以尝试部署

        app.UseDeveloperExceptionPage();
      

      如果有错误,请找出错误。

      【讨论】:

        猜你喜欢
        • 2020-02-15
        • 2017-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-27
        相关资源
        最近更新 更多