Questions tagged [asp.net-mvc-routing]

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

The ASP.NET Routing module is responsible for mapping incoming browser requests to particular ASP.NET handlers. It is commonly used to map ASP.NET MVC controller actions, but routing is also used with ASP.NET Web Forms, ASP.NET Web API, route attribute (Web API2) and custom handlers.

Learn more about ASP.NET Routing on MSDN

4079 questions
240
votes
10 answers

Is it possible to make an ASP.NET MVC route based on a subdomain?

Is it possible to have an ASP.NET MVC route that uses subdomain information to determine its route? For example: user1.domain.com goes to one place user2.domain.com goes to another? Or, can I make it so both of these go to the same…
Dan Esparza
  • 26,944
  • 28
  • 97
  • 124
146
votes
15 answers

Ensure that HttpConfiguration.EnsureInitialized()

I've installed Visual Studio 2013 and when I run my app I get the error below. I've got no idea as to where I'm to initialized this object. What to do? Server Error in '/' Application. The object has not yet been initialized. Ensure that…
135
votes
5 answers

ASP.NET MVC ambiguous action methods

I have two action methods that are conflicting. Basically, I want to be able to get to the same view using two different routes, either by an item's ID or by the item's name and its parent's (items can have the same name across different parents). …
Jonathan Freeland
  • 4,905
  • 3
  • 25
  • 38
118
votes
10 answers

Routing for custom ASP.NET MVC 404 Error page

I am trying to make a custom HTTP 404 error page when someone types in a URL that doesn't invoke a valid action or controller in ASP.NET MVC, instead of it displaying the generic "Resource Not Found" ASP.NET error. I don't want to use the web.config…
110
votes
9 answers

Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287

The URL I'm trying to let work is one in the style of: http://somedomain.com/api/people/staff.33311 (just like sites as LAST.FM allow all sort of signs in their RESTFul & WebPage urls, for example "http://www.last.fm/artist/psy'aviah" is a valid url…
106
votes
8 answers

Set "Homepage" in Asp.Net MVC

In asp.net MVC the "homepage" (ie the route that displays when hitting www.foo.com) is set to Home/Index . Where is this value stored? How can I change the "homepage"? Is there anything more elegant than using RedirectToRoute() in the Index…
NikolaiDante
  • 17,673
  • 14
  • 75
  • 112
97
votes
5 answers

What is routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

What is routes.IgnoreRoute("{resource}.axd/{*pathInfo}") I cannot find any .axd file in my project, can I remove this route rule?
Eric Yin
  • 7,959
  • 17
  • 68
  • 111
95
votes
5 answers

How do you request static .html files under the ~/Views folder in ASP.NET MVC?

I want to be able to request static .html files which are located in the ~/Views folder. According to the documentation, the routing system checks to see if a URL matches a disk file before evaluating the application's routes. But when I request the…
alex.mironov
  • 2,554
  • 3
  • 25
  • 33
90
votes
3 answers

Force all Areas to use same Layout

I have the following project structure: /Views/Shared/_Layout; /Areas/Area1/Views/ControllerName/Index; ... /Areas/AreaN/Views/ControllerName/Index. Is there any way to force all areas to use the _Layout as a base layout? Is there any way to do…
Mikhail
  • 8,851
  • 4
  • 31
  • 48
70
votes
7 answers

MVC 3 Can't pass string as a View's model?

I have a strange problem with my model passed to the View Controller [Authorize] public ActionResult Sth() { return View("~/Views/Sth/Sth.cshtml", "abc"); } View @model string @{ ViewBag.Title = "lorem"; Layout =…
Tony
  • 11,443
  • 32
  • 119
  • 213
70
votes
8 answers

How to use an Area in ASP.NET Core

How do I use an Area in ASP.NET Core? I have an app that needs an Admin section. This section requires its Views to be placed in that area. All requests that start with Admin/ will need to be redirected to that area.
68
votes
4 answers

URLs with slash in parameter?

Question: I am creating a wiki software, basically a clone of wikipedia/mediawiki, but in ASP.NET MVC (the MVC is the point, so don't recommend me ScrewTurn). Now I have a question: I use this route mapping, to route a URL…
Stefan Steiger
  • 68,404
  • 63
  • 337
  • 408
68
votes
2 answers

Difference between "MapHttpRoute" and "MapRoute"?

Why using "MapRoute" for "Default" routing, while using "MapHttpRoute" for "DefaultApi" routing? routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}" ); routes.MapRoute( name: "Default", url:…
Dean
  • 1,251
  • 3
  • 15
  • 22
59
votes
17 answers

The view 'Index' or its master was not found.

The view 'Index' or its master was not found. The following locations were searched: ~/Views/ControllerName/Index.aspx ~/Views/ControllerName/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx I got this error when using ASP.Net mvc…
Fitzchak Yitzchaki
  • 8,867
  • 7
  • 51
  • 94
59
votes
3 answers

ApiController returns 404 when ID contains period

I have an ApiController and I want to use email addresses as the ID parameter for requests: // GET api/employees/email@address.com public CompactEmployee Get(string id) { var email = id; return GetEmployeeByEmail(email); } However, I cannot…
Jonathan Freeland
  • 4,905
  • 3
  • 25
  • 38
1
2 3
99 100