Startup.cs - 'value' 中的路径必须以 '/' 开头 [英] Startup.cs - The path in 'value' must start with '/'

查看:31
本文介绍了Startup.cs - 'value' 中的路径必须以 '/' 开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a new .NET Core MVC application in Visual Studio 2017 and enabled multi-tenant authentication.
I've completed the configuration (ClientId, Authority, etc) but when I debug the application there is an exception in the Startup.cs, specifically the app.useOpenIdConnectAuthentication method.

给出的例外是

System.ArgumentException: 'value' 中的路径必须以 '/' 开头.

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

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

I'm a bit of a novice when it comes to C# and .NET Core, so I'm not sure whether I'm missing something obvious. The main sticking point is what the debugger is referring to with the parameter 'value' as I can't see any mention of it in the code. There are no changes beyond the default template generated by visual studio, other than adding the configuration items to the appsettings.json.

推荐答案

由于题中没有代码,所以尽量做一个笼统的回答.
当您使用此重载 PathString.FromUriComponent(string) 并且字符串不以 / 字符开头

As there is no code in the question, so I will try to make a general answer as possible.
This exception appears when you use this overload PathString.FromUriComponent(string) and the string does not start with the / character

因此,例如,以下代码将引发异常:

so,for example, the following code will throw an exception :

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

为了修复之前的异常,你可以这样写

and to fix the previous exception you can write it like this

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

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

and of course, this will be a relative path.

如果你想使用绝对路径(而不是用 / 开始你的字符串),那么你必须使用这个方法的另一个重载,它接受 Uri 对象作为参数而不是 string

In case you wanted to use an absolute path, (and not start your string with /), then you must use another overload of this method which takes Uri object as a parameter instead of string

这是一个例子

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

这篇关于Startup.cs - 'value' 中的路径必须以 '/' 开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆