Questions tagged [asp.net-mvc-routing]

Questions about routing within ASP.NET (including MVC).

Filter by
Sorted by
Tagged with
0 votes
0 answers
31 views

ASP.NET CORE - dynamically add a attribute route to an controller with [ApiController]

I'd like to have controllers with default Route URLs and HTTP method generated by custom code and not require any HttpPost|Get|etc attributes (route actions will default to Post). I can do this using ...
David Faivre's user avatar
  • 2,312
0 votes
0 answers
59 views

ASP.NET Core 6 Web API / C# : routing, POST method, how to set default param

Set routing at top of controller: [Route("api/import/v1")] [ApiController] public class ImportController : ControllerBase { // ..... } And setting it on a test function: [...
John's user avatar
  • 4,005
0 votes
0 answers
13 views

MVC Core 6 (Apache, Ubuntu) Redirect from /, //, ///, etc to main Page [duplicate]

give me please advice how I can redirect from "example.com///", "example.com/////" or "example.com////////" to "example.com" because now all of these page give ...
Andrey_G's user avatar
0 votes
1 answer
39 views

Apply different authorization policy on API depending on Http Method

I have an API developed in .NET7 with multiple controllers. Right now all the actions have the same authorization policy so we accomplished it by setting it up in the useendpoints middleware like ...
Curious George's user avatar
0 votes
1 answer
64 views

Why is nullable int id parameter always null in ASP.NET Core web app?

This is an ASP.NET Core 6 MVC web application with the following controller method that isn't working as expected: [Route("Edit/{id:int?}")] [HttpGet] public async Task<ActionResult> ...
geoff swartz's user avatar
  • 5,595
0 votes
0 answers
37 views

ASP.NET MVC 5 - Mapping controller route and proper way to map nested actions

I have a controller called Expense that has the usual (default template generated) actions: Expense/Index Expense/Create/{id} Expense/Details/{id} Expense/Edit/{id} I also have a controller called ...
Nikola's user avatar
  • 1
0 votes
1 answer
39 views

ASP.Net API & Core Search Functionality Issue

In my solution I have an ASP.NET Core Web API project. Skipping to the client side portion, in one of my controllers I am trying to implement a search function (my first time ever trying). When I try ...
acekensei's user avatar
0 votes
0 answers
10 views

Invoke mvc controller action method not by action name but with http method type

Invoke MVC controller action method not with action name but with http method type in ajax call, like below, Note -- the below needs to work in conventional routing and not with attribute based ...
Stack Overflow's user avatar
2 votes
2 answers
58 views

Routing to controller actions in ASP.NET Core with String parameter

I want to set up the routing in my project so that I can have a URL like /Account/Profile/FrankReynolds instead of having to do /Account/Profile?name=FrankReynolds. If I try and hit the URL /Account/...
Bad Dub's user avatar
  • 1,513
0 votes
0 answers
30 views

How a DateTime parameter can be optional in ASP.NET Core MVC attribute routing

I have this controller action method: [HttpGet("GetByUserId/{id:int}/{fechaInicio:datetime?}/{fechaTermino:datetime?}")] public async Task<ApiResult> GetListByWorkerIdAsync(int id, ...
jstuardo's user avatar
  • 4,059
1 vote
1 answer
37 views

Routes behaving weird after update from 3.1 to 6

I have updated an ASP.NET Core 3.1 MVC application to .NET 6, and now the routing is causing many "weird" problems. This used to work: <form asp-route="Resumes.Sections.SetTitle"...
Rene Kolmos's user avatar
0 votes
0 answers
16 views

OData Routing with function on EntityType throws HTTP 404 error

I have a .Net Framework Web application running on .Net framework version 4.7.2. Newly added OData API Route is not resolving to the right controller & action. Attribute routing is not working as ...
Adithya K S's user avatar
0 votes
1 answer
156 views

Umbraco Controller. Routing. Why I have 404 error for all actions?

I have custom controller like this: using System.Web.Mvc; using Umbraco.Web.Mvc; using HttpGetAttribute = System.Web.Mvc.HttpGetAttribute; using RouteAttribute = System.Web.Mvc.RouteAttribute; using ...
Slava Podolskiy's user avatar
0 votes
0 answers
43 views

ASP .NET MVC Routing matches controller from Area instead of looking only in root

I have a MVC project and it has controllers both outside and inside areas. I have this rule in RouteConfig: routes.MapRoute( name: "Default", url: "{...
mike_x_'s user avatar
  • 1,900
0 votes
0 answers
224 views

ASP.NET Razor Pages RedirectToPage without relying on folder structure

I have an ASP.NET Core MVC application which uses internal redirects and looking around razor pages. A little bit of explanation the problem and how I solve it with MVC controllers. Here is how I'm ...
Crypt32's user avatar
  • 13.1k
0 votes
1 answer
62 views

Route-parameter contains parts of route

I have a route that looks like this: /foo/{identifier}/bar/ I have configured the route like this: httpConfiguration.Routes.MapHttpRoute("Foo1", "foo/{identifier}/bar/", new { ...
mamen's user avatar
  • 1,294
0 votes
1 answer
60 views

.NET Core attribute routing with culture specified in url

I'm redirecting application to default culture when is run so URL is https://example.com/en In controller I'm trying to use attribute routing. public class ServicesController : Controller { ...
Carlo's user avatar
  • 13
0 votes
1 answer
44 views

Catch-all route is incorrectly prioritized over defined templates

I'm on dotnet 7.0.203; having a very simple problem, which I believe shouldn't be the case. I have a few routes and one catch-all route, with my expectation being catch-all should be executed with the ...
Mavi Domates's user avatar
  • 4,391
0 votes
0 answers
59 views

RoutePrefix ignored for controller

I have a web API targeting .NET Framework 4.8. This is how the web app is initialized: var httpConfiguration = new HttpConfiguration(); var constraintResolver = new ...
Angela's user avatar
  • 497
0 votes
2 answers
74 views

invalid Url generated for POST action

I think there is a problem with URL generation. Assuming that we have the following controller: [Route("[action]")] public class Home : Controller { [Route("/")] public ...
emdee.pro's user avatar
  • 153
0 votes
1 answer
86 views

Html.ActionLink not aware of current area generates bad links

Context I am migrating an ASP.NET MVC 5 app (running on .NET 4.7.2) to ASP.NET Core 2.2 on .NET 7.0. I am proceeding from a blank project and slowly moving-and-changing files. My current subject is ...
SandRock's user avatar
  • 5,293
0 votes
0 answers
228 views

Pass route parameter with form submit ASP.NET MVC 5

I am building an ASP.NET MVC 5 application (.NET 4.8) and I'm trying to pass an additional route parameter with form submit to a controller method. Why am I doing it like this? In short, as it is a ...
dzenesiz's user avatar
  • 1,408
0 votes
2 answers
1k views

MapControllers() does not find any endpoints

I just migrated from .net core 3.1 to .net 6. My project is an WebApi. All my controllers inherit from ControllerBase and they have an [ApiController] attribute with the appropriate [Route] attribute. ...
Eric's user avatar
  • 230
0 votes
1 answer
32 views

ASP.NET Core MVC : actionlink parameter to use slashes (/) insted of questionmark (?) in a query string

I would like to map a route that would be valid for any number of parameter passed as a query string for any controller and methods. For instance: /Area/Controller/Action?paraA=1&paraB=2 should ...
WorkInProgress's user avatar
0 votes
1 answer
144 views

Why ASP.NET routing add id into the url?

I am making menu with categories, where first menu item is All categories. All items call method Index in controller Auction, however, first item does not send id as a parameter. I am curious, why I ...
Peter Chovanec's user avatar
0 votes
0 answers
41 views

How to notify an ASP.NET Core MVC web app about an event occurred in a third party app

I have a requirement wherein I need to perform certain action in my web application based on phone call receiving event that occurs in a third party application - Knowlarity SR calling app. We are ...
Mayuri Barve's user avatar
1 vote
1 answer
153 views

How to Register Custom IRouter in .Net 7 MVC Application?

I have a custom IRouter implementation and I can't figure out how to register it in a .Net 7 MVC application. What I am trying to accomplish is this: Incoming requests have the form of https://example....
Mats's user avatar
  • 15k
1 vote
2 answers
45 views

ASP.NET MVC Attribute routing parameter issue

I have the following code public class BooksController : Controller { [Route("/Books/{id?}")] public IActionResult Index(string id) { return View(id); } } My problem ...
JackFord's user avatar
  • 113
1 vote
1 answer
756 views

.net 7. Does not see route for a controller

I'm testing .net7 MVC. I have 2 controllers. 1st - default, created during installation and 2nd, copied from the 1st and modified. 1st controller works as expected, 2nd - does not. I've broken up my ...
MikhailF's user avatar
0 votes
0 answers
135 views

SmartBreadCrumbs disable Url encoding RouteValues in .net core

I am trying to set up SmartBreadCrumbs to follow the Url pattern on my website. My category urls should look like this... /shop/Category/4/Ladies/Shoes Shop is the area, Category is the controller, 4 ...
James Andrew Smith's user avatar
0 votes
1 answer
629 views

Does a call to MapRazorPages() constitute a call to UseEndpoints()?

According to the documentation for UseRouting(), we must call UseEndpoints() afterward: A call to UseRouting(IApplicationBuilder) must be followed by a call to UseEndpoints(IApplicationBuilder, ...
InteXX's user avatar
  • 6,137
1 vote
1 answer
75 views

APS.NET MVC request routing using query parameter names

I'm trying to understand attribute routing in ASP.NET MVC. I understand how routing matches on url elements, but not query parameters. For example, say I have a rest-style book lookup service that can ...
Andy Johnson's user avatar
  • 7,957
0 votes
2 answers
133 views

How to properly route unauthenticated user to the Login Page in MVC .NET6

The only users that should see the list of contacts are authenticated users. Inside the Contacts Controllers, I've been testing different file paths to route the unauthenticated users to the login ...
hampden's user avatar
  • 13
0 votes
1 answer
349 views

Host ASP.NET Core MVC app with multiple pathbase in IIS

Is it possible to host an ASP.NET Core MVC web app with different paths? For example: I've an ASP.NET Core MVC web app hosted in IIS, with binding test.com. Is it possible to cover multiple paths (...
Kannan M's user avatar
  • 570
0 votes
1 answer
170 views

URL rewrite for .Net MVC Application

I have .Net MVC 5 application currently running with url like http://www.example.com in production (Hosted in IIS on Windows server). Now we have requirement to change the URL path to like this http://...
Tech learner's user avatar
2 votes
1 answer
785 views

How Can I Get Action Name of Current View while submitting a form?

I have an action method for uploading Image that is used in many Views. after uploading the image I want my method to redirect to the same view. for that I need action name to redirect it and when I ...
Salman Abbas's user avatar
0 votes
2 answers
2k views

Change controller route name in ASP.NET Core MVC 404 error

I want to change the route display name in URL, like below: Access UserController display: https://localhost:7214/admin/login Access CustomerController display: https://localhost:7214/customers/index ...
Howard Hee's user avatar
0 votes
1 answer
250 views

.NET Core - Set custom route URL for the controllers

Scenario - Instead of controllers being routed to the localhost:5555/home/menu (home ==> HomeController and menu ==> action), I wanted to route the APIs to something like localhost:5555/abc/xyz/...
Prateek's user avatar
  • 135
1 vote
2 answers
465 views

MAUI Blazor Routing bug?

My routes work fine in a regular Blazor application, but don't in Blazor MAUI. @page "/" @page "/logitemAdd/{logItemKey?}" My page answers to both of these routes, but in MAUI, ...
Terrence's user avatar
  • 313
1 vote
2 answers
1k views

ASP.NET Core : AddAreaPageRoute - parameter more than one time in the route

What I am trying to do is something like this: services .AddRazorPages() .AddRazorPagesOptions(options => { options.Conventions.AddAreaPageRoute("Products", "/...
user5255727's user avatar
1 vote
1 answer
157 views

ASP.NET MVC Routing with Areas & Languages not working

I have a site with controllers and two other areas with the respective controllers for each. One of the controllers within the area has a language contraint code say en. By default it works perfectly ...
Balaji's user avatar
  • 1,405
0 votes
1 answer
844 views

How to detect reason of wrong routing in ASP.NET Core 6

I try to change existing project and failed. For understanding issue I have write route analyzer, this is simple code App.Use(Async Function(context, [next]) Dim CurrentEndpoint = ...
user avatar
0 votes
1 answer
172 views

ASP.NET MVC routing - part of controller name in url

I need a routing that maps admin/{PartOfControllerName}/{action} to the controller: Admin{PartOfControllerName}Controller For example map admin/post/new to AdminPostController and its New action. ...
Ali Mottaghi Pour's user avatar
1 vote
0 answers
412 views

What is the most universal way to get metadata about defined endpoint parameters?

We can define that some of the endpoint parameters should be bound from query string: [FromQuery(Name= "someParamName")]. Is this mapping information stored anywhere in endpoint metadata? I ...
Pavel Voronin's user avatar
0 votes
1 answer
148 views

Why shouldn't I use attribute routing in a traditional (non API) controller?

I've been using attribute based routing in an API controller project: [HttpGet("products/{productId}")] public async Task<IActionResult> ProductDetails(int productId) { ... return ...
Ben Mills's user avatar
  • 27.7k
0 votes
0 answers
161 views

ASP.NET MVC route only works on server but not on local development machine

When I try to access the Index view of my controller, I get an HTTP 404 error. But if I deploy the app on the server, everything works fine. Even if I access my action by typing in the URL User/Index. ...
Ahad Porkar's user avatar
  • 1,596
0 votes
0 answers
66 views

ASP.NET Core Attribute Routing bug?

All of my routes in ASP.NET Core 3.1 work fine, except this empty one. I should be able to hit this route: /Document/HB89Letter and hit the Show page /Document/HB89Letter/Show works /Document/...
Terrence's user avatar
  • 2,744
0 votes
1 answer
605 views

RouteBuilder vs EndpointRoutBuilder in .Net

I am trying to learn behind the scene of Routing and I find out that WebApplication implements IEndpointRouteBuilder which allows it to define routes for example using MapGet or even the UseEndpoint ...
Mehdi Mowlavi's user avatar
0 votes
1 answer
737 views

.net 6 core mvc return view() static file path gets the view path error : net::ERR_ABORTED 404

There is a problem with .net 6 core mvc when invoking a method of controller by (asp-controller ="test" asp-action="GetTest") static files such as js, css, media files in wwwroot ...
Hafizullah Ozgur's user avatar
0 votes
0 answers
166 views

Url rewriting for static .htm pages in Blazor

I am moving a legacy website with hundreds of well SEO optimized .htm pages. By default, it does not appear as though Blazor can intercept .htm extension files to run custom redirect, routing, or ...
Damian Spaulding's user avatar

1
2 3 4 5
83