asp.net-mvc - 错误在应用程序部署中的 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>
你看到任何错误吗?我会很感激你的帮助!
解决方案
我也有这个问题。这是因为异常处理路径预计以“/”开头
错误是:
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();
并找到错误(如果有)。
推荐阅读
- mysql - MySQL缓存准备好的语句以提高性能
- semantic-ui-react - 我可以为我的自定义主题添加新颜色到 SUI.COLORS 吗?
- javascript - 如何从另一个网站复制 {{}} 内的数据以供在我的网站中使用?
- android - Android & Unity3D - 混合数据交换/动作/通信并使用 UNity3D 作为集成
- python - 我们可以将条件参数传递给 pytest 中的夹具函数吗?
- sql - 如何确定每个用户的平均笔记数?
- python - shutil.copyfile 不应该用 follow_symlinks 集替换 dst 中的链接吗?
- knockout.js - KnockoutJS:为现有模型分配一个新模型,例如(model.order = neworder)不会改变视图中的值,为什么?
- css - 单独使用 css 移动元素
- java - 如何引发“应用程序无响应”