asp.net-core-routing

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

ASP.NET Core Routing works in VS IIS Express but not in IIS 10

╄→гoц情女王★ 提交于 2019-12-06 10:20:03
问题 I am developing ASP.NET Core web API. here I have a situation like I have to use multiple get functions which get data from SQL server DB. So for that, I'm doing custom attribute routes. below are my codes [Route("api/[controller]")] public class MeController : Controller { private readonly ITechRepository _tech; private readonly IPageOptions _page; public MeController(ITechRepository tech,IPageOptions page) { _tech = tech; _page = page; } [Route("getTech")] public IEnumerable<TechStack> Get(

Route Name for HttpGet attribute Name for base generic controller class in asp.net core 2

依然范特西╮ 提交于 2019-12-05 12:45:36
问题 I have a generic controller, which have several derived controller classes. but I cannot figure out how to handle the HttpGet's route name since it require constant. [HttpGet("{id}", Name ="should not hard coded here for derived class")] public virtual async Task<IActionResult> Get(int id) I need the route name because in my HttpPost function I want to return CreatedAtRoute() which require HttpGet's route name The route name cannot be hard coded because all the derived class need to have a

Route Name for HttpGet attribute Name for base generic controller class in asp.net core 2

人走茶凉 提交于 2019-12-03 23:34:57
I have a generic controller, which have several derived controller classes. but I cannot figure out how to handle the HttpGet's route name since it require constant. [HttpGet("{id}", Name ="should not hard coded here for derived class")] public virtual async Task<IActionResult> Get(int id) I need the route name because in my HttpPost function I want to return CreatedAtRoute() which require HttpGet's route name The route name cannot be hard coded because all the derived class need to have a different route name. here is the base controller public abstract class BaseController<TEntity, TContext>

Routing in MVC 6

我与影子孤独终老i 提交于 2019-12-01 04:58:31
问题 I have a super simple controller with 2 methods: public IActionResult Users(long id) { return Json(new { name = "Example User" }); } public IActionResult Users() { return Json(new { list = new List<User>() }); } One to select all users and the other to return all users. In web api 2 I could user the following route and everything worked fine: config.Routes.MapHttpRoute( name: "Users", routeTemplate: "v1/Users", defaults: new { action = "Users", controller = "Users" }, constraints: null,

工具导航Map