asp.net-core-routing

The constraint reference 'slugify' could not be resolved to a type

ε祈祈猫儿з 提交于 2020-01-02 12:01:53
问题 ASP.NET Core 2.2 has introduced an option for slugifying routing url using Parameter transformer as follows: routes.MapRoute( name: "default", template: "{controller=Home:slugify}/{action=Index:slugify}/{id?}"); I have done the same thing as follows: routes.MapRoute( name: "default", template: "{controller:slugify}/{action:slugify}/{id?}", defaults: new { controller = "Home", action = "Index" }); My routing configuration in the ConfigureServices method as follows: services.AddRouting(option =

asp.net core web api center routing

流过昼夜 提交于 2019-12-24 07:39:06
问题 I have an issue related with asp.net core center routing . I know we could use Attribute Routing, but I did not find anything related with center routing like asp.net web api. Something like below: routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); Could you share me how to achieve above function in asp.net core? If there is no built-in function, could custom routing service achieve this? Regards, Edward 回答1:

how to implement Multi-Tenant functionality in asp.net-core

徘徊边缘 提交于 2019-12-23 04:16:56
问题 I have an Asp.net Core application I want to be able to allow multiple/ different Tenant(Client)to access the same application but using different url's. I have common database for all tenant(client). So It is the main part I want to host my application in a domain say... www.myapplication.com then allow different Tenant(client) to access the same application using 1.www.TenantOne.myapplication.com 2.www.TenanatTwo.myapplication.com. 3.www.{TENANCY_NAME}.myapplication.com I can't find any

Different domain in the same app ASP.NET Core 2.0

纵饮孤独 提交于 2019-12-18 11:35:05
问题 I have ASP.NET Core 2.0 app hosted in Azure web app. This app have configured domain domainA.com . I have one route in my app for example domainA.com/route . Now I want to pin other domain only to this route for example domainB.com . What is the best way to do this? 回答1: One way to accomplish this is to make a custom route constraint to specify which routes function for each domain name. DomainConstraint public class DomainConstraint : IRouteConstraint { private readonly string[] domains;

Add text to URLs instead of int ID

核能气质少年 提交于 2019-12-12 15:35:27
问题 At the moment our permalinks are not correct and hinder searching e.g. https://example.com/en/blogs/19 - this should have words in the URL that Google can pick up in the search, instead of a int id that is used to retrieve from Db. Let's say an article for 'The Automotive Industry Latest' Google will give more weight in the algorithm if we had the ability to edit the link that included keywords. For example: https://example.com/en/blogs/news/The_Automotive_Industry_Latest - this link should

.NET Core (2.1) web API controller accepting all that follows within the request url as parameter

孤人 提交于 2019-12-11 09:02:08
问题 What I have is a .NET Core 2.1 web API controller (in the following the TestController) that should generate redirects to other urls when receiving GET requests. Example: The controller is called like: http://localhost/api/v1/Test/somedir/somesubdir/filename.extension and it should return a redirect to https://example-domain.com/somedir/somesubdir/filename.extension My example controller for this question looks like: [Authorize] [Route("api/v1/[controller]")] public class TestController :

How to write a middleware as custom router in asp.net core?

亡梦爱人 提交于 2019-12-08 04:00:27
问题 I want to transform this code: var trackPackageRouteHandler = new RouteHandler(context => { var routeValues = context.GetRouteData().Values; return context.Response.WriteAsync( $"Hello! Route values: {string.Join(", ", routeValues)}"); }); var routeBuilder = new RouteBuilder(app, trackPackageRouteHandler); routeBuilder.MapRoute( "Track Package Route", "package/{operation:regex(^track|create|detonate$)}/{id:int}"); routeBuilder.MapGet("hello/{name}", context => { var name = context

How to write a middleware as custom router in asp.net core?

穿精又带淫゛_ 提交于 2019-12-07 20:37:31
I want to transform this code: var trackPackageRouteHandler = new RouteHandler(context => { var routeValues = context.GetRouteData().Values; return context.Response.WriteAsync( $"Hello! Route values: {string.Join(", ", routeValues)}"); }); var routeBuilder = new RouteBuilder(app, trackPackageRouteHandler); routeBuilder.MapRoute( "Track Package Route", "package/{operation:regex(^track|create|detonate$)}/{id:int}"); routeBuilder.MapGet("hello/{name}", context => { var name = context.GetRouteValue("name"); // This is the route handler when HTTP GET "hello/<anything>" matches // To match HTTP GET

how to implement Multi-Tenant functionality in asp.net-core

孤人 提交于 2019-12-07 02:26:27
I have an Asp.net Core application I want to be able to allow multiple/ different Tenant(Client)to access the same application but using different url's. I have common database for all tenant(client). So It is the main part I want to host my application in a domain say... www.myapplication.com then allow different Tenant(client) to access the same application using 1.www.TenantOne.myapplication.com 2.www.TenanatTwo.myapplication.com. 3.www.{TENANCY_NAME}.myapplication.com I can't find any info on how to do this and I'm stuck. How to do it? Please provide the code. Thanks. Sorry,you have to get

The constraint reference 'slugify' could not be resolved to a type

浪尽此生 提交于 2019-12-06 11:17:34
ASP.NET Core 2.2 has introduced an option for slugifying routing url using Parameter transformer as follows: routes.MapRoute( name: "default", template: "{controller=Home:slugify}/{action=Index:slugify}/{id?}"); I have done the same thing as follows: routes.MapRoute( name: "default", template: "{controller:slugify}/{action:slugify}/{id?}", defaults: new { controller = "Home", action = "Index" }); My routing configuration in the ConfigureServices method as follows: services.AddRouting(option => { option.LowercaseUrls = true; }); but getting the following errors: InvalidOperationException: The