Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Startup.cs - The path in 'value' must start with '/'

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.

The exception given is

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

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.

like image 367
Ben Short Avatar asked Jan 24 '17 17:01

Ben Short


People also ask

What is difference between FromQuery and FromBody?

[FromQuery] - Gets values from the query string. [FromRoute] - Gets values from route data. [FromForm] - Gets values from posted form fields. [FromBody] - Gets values from the request body.

How do you use UseStatusCodePagesWithReExecute?

UseStatusCodePagesWithReExecute("/StatusCode/{0}"); If an endpoint within the app is specified, create an MVC view or Razor page for the endpoint. This method is commonly used when the app should: Process the request without redirecting to a different endpoint.

What is bind property in C#?

The Binding class is used to bind a property of a control with the property of an object. For creating a Binding object, the developer must specify the property of the control, the data source, and the table field to which the given property will be bound.


1 Answers

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.

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

here is an example

// use an absolute path
PathString.FromUriComponent(new Uri("https://localhost:8000/controller/action/"))
like image 87
Hakan Fıstık Avatar answered Nov 09 '22 14:11

Hakan Fıstık