首页 > 解决方案 > 错误在应用程序部署中的 ASP.NET Core 2 中的“值”中的路径必须以“/”开头

问题描述

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

ArgumentException:“值”中的路径必须以“/”开头。参数名称:值 Microsoft.AspNetCore.Http.PathString..ctor(string value) Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler(IApplicationBuilder app, string errorHandlingPath) OCIndicadoresOperativoClientes.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) 在启动中。 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。

下面你可以看到 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-mvcasp.net-coredeploymentvisual-studio-2017

解决方案


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

错误是:

ArgumentException:“值”中的路径必须以“/”开头。参数名称: 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();

并找到错误(如果有)。


推荐阅读