Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kestrel and ASP.NET Core MVC use custom base path

How can you mount your app on a different base path?

For example, my controller's route is /api/keywords, but when running the web server I want the basepath to be /development, so my controller route would be /development/api/keywords. I would rather not have to modify my controllers. In old Web API versions you could mount an OWIN app in a different path so I'm looking to do something similar.

like image 845
ryudice Avatar asked Oct 20 '16 20:10

ryudice


People also ask

Does ASP.NET Core use Kestrel?

Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates.

Which of the following is the default class to configure routes in ASP.NET Core MVC?

MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); Inside the call to UseEndpoints() , we use the MapControllerRoute() method to create a route by giving the name default . MVC configures the default routedefault routeThe default route is generally the address of another router, which treats the packet the same way: if a route matches, the packet is forwarded accordingly, otherwise the packet is forwarded to the default route of that router.https://en.wikipedia.org › wiki › Default_routeDefault route - Wikipedia template as {controller=Home}/{action=Index}/{id?} .

How do I host a .NET Core application in Kestrel?

In the case of the Kestrel web server, the process name that is used to host and run the ASP.NET Core application is the project name. As of now, we are using visual studio to run the ASP.NET Core application. By default, the visual studio uses IIS Express to host and run the ASP.NET Core application.

What is the default directory for static files in ASP.NET Core?

Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method. For more information, see Content root and Web root.


1 Answers

There's a new method called UsePathBase that can do this easily. https://github.com/aspnet/HttpAbstractions/blob/bfa183747f6fb528087554c3d6ec58ef05f1c10a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UsePathBaseExtensions.cs

like image 92
Tratcher Avatar answered Sep 27 '22 23:09

Tratcher