asp.net-mvc - Startup.cs - 'value' 中的路径必须以 '/' 开头

标签 asp.net-mvc .net-core openid-connect

我在 Visual Studio 2017 中创建了一个新的 .NET Core MVC 应用程序并启用了 Multi-Tenancy 身份验证。
我已完成配置(ClientId、Authority 等),但当我调试应用程序时,Startup.cs 中出现异常,特别是 app.useOpenIdConnectAuthentication 方法。

给出的异常(exception)是

System.ArgumentException: The path in 'value' must start with '/'.

对于 C# 和 .NET Core,我有点新手,所以我不确定我是否遗漏了一些明显的东西。主要的症结在于调试器使用参数“值”引用的内容,因为我在代码中看不到任何提及它的内容。除了将配置项添加到 appsettings.json 之外,除了 Visual Studio 生成的默认模板之外,没有任何更改。

最佳答案

由于问题中没有代码,所以我会尝试尽可能做出一般性答案。
当您使用此重载 PathString.FromUriComponent(string) 并且字符串不以 / 字符开头

时,会出现此异常

例如,下面的代码将抛出异常:

PathString.FromUriComponent("controllerName/actionName"); // throw exception

要修复之前的异常,您可以这样编写

PathString.FromUriComponent("/controllerName/actionName"); // working, but as relative path

当然,这将是一个相对路径。

如果您想使用绝对路径(并且不以 / 开头字符串),那么您必须使用此方法的另一个重载,该重载采用 Uri 对象作为参数而不是字符串

这是一个例子

// use an absolute path
PathString.FromUriComponent(new Uri("https://localhost:8000/controller/action/"))

关于asp.net-mvc - Startup.cs - 'value' 中的路径必须以 '/' 开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41834645/

相关文章:

c# - 在 ASP.NET Core Web API 中上传文件和 JSON

c# - Azure Pipeline 在 dotnet 构建中失败,需要升级到最新的 .net core 版本

asp.net - 如何让 Owin 在访问 token 过期时自动使用刷新 token

claims-based-identity - 添加 id_token 作为声明 AspNetCore OpenIdConnect 中间件

asp.net-mvc - ASP.NET MVC Content 文件夹中应该包含哪些文件?

c# - 生成 DbContext 后如何修改数据库?

c# - ASP.NET Core 中外部类库的本地化

c# - JwtSecurityTokenHandler 表示更改 1 个字符后 JWT 的签名有效

asp.net-mvc - 无法使用 MiniProfiler 到达一垒

c# - 从 MVC Controller 将 HTML 渲染为字符串