我在 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/