Questions about routing within ASP.NET (including MVC).
160
votes
5answers
31k views
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 ...
25
votes
3answers
8k views
ASP.NET MVC custom routing for search
Here is my scenario. For the example lets say that I need to return a list of cars based on a search criteria. I would like to have a single View to display the results since the output will be the ...
69
votes
4answers
13k views
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 ...
28
votes
3answers
7k views
How can I create a friendly URL in ASP.NET MVC?
How do I generate friendly URLs within the ASP.NET MVC Framework? For example, we've got a URL that looks like this:
http://site/catalogue/BrowseByStyleLevel/1
The 1 is Id of the study level (Higher ...
19
votes
2answers
10k views
How does a method in MVC WebApi map to an http verb?
In the 5-minute video at the following link, at the 1:10 mark, Jon Galloway says that adding a method called DeleteComment to his CommentsController controller class will by convention map ...
10
votes
4answers
6k views
ASP.NET MVC Routing - add .html extension to routes
i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's.
a task that is a bit over me since i have no experience.
ok, lets talk a bit of code:
routes.MapRoute(
...
58
votes
9answers
54k views
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 ...
5
votes
1answer
2k views
How to reuse Areas, Controllers, Views, Models, Routes in multiple apps or websites
I have a test solution which only has one area called Admin.
I would like to reuse Admin across a number of other web applications.
I have a web application setup in IIS, I have then added a virtual ...
11
votes
4answers
5k views
asp.net mvc complex routing for tree path
I am wondering how can I define a routing map like this:
{TreePath}/{Action}{Id}
TreeMap is dynamically loaded from a database like this:
'Gallery/GalleryA/SubGalleryA/View/3'
26
votes
4answers
9k views
jQuery Mobile/MVC: Getting the browser URL to change with RedirectToAction
My first post...
When I use RedirectToAction the url in the browser doesn't change. How can I achieve this?
I'm switching over to ASP.NET MVC 3.0 (also using jQuery Mobile) after 10+ years using web ...
20
votes
6answers
8k views
ASP.Net MVC RouteData and arrays
If I have an Action like this:
public ActionResult DoStuff(List<string> stuff)
{
...
ViewData["stuff"] = stuff;
...
return View();
}
I can hit it with the following URL:
...
11
votes
4answers
4k views
Infinite URL Parameters for ASP.NET MVC Route
I need an implementation where I can get infinite parameters on my ASP.NET Controller. It will be better if I give you an example :
Let's assume that I will have following urls :
...
6
votes
4answers
4k views
MVC 2 AreaRegistration Routes Order
I noticed that in MVC 2 Preview 2, AreaRegistration is loading the routes for each area in an arbitrary order. Is there a good way to get one before the other?
For example, I have two areas - "Site" ...
3
votes
2answers
4k views
ASP.Net MVC routing legacy URLs passing querystring Ids to controller actions
We're currently running on IIS6, but hoping to move to IIS 7 soon.
We're moving an existing web forms site over to ASP.Net MVC. We have quite a few legacy pages which we need to redirect to the new ...
8
votes
4answers
23k views
ASP.NET MVC Default route?
I created a new ASP.NET MVC project and implemented a site authorization filter.
When I map the routes to the {controller}/{action} pair, I pass a role = "SomeRole" default to the route.
It works ...
9
votes
1answer
15k views
Implementing “Remember Me” Feature in ASP.NET MVC
I'm trying to implement a "remember me" feature to my login form. I am using ASP.NET MVC as my web application. I managed to get the cookie stuff working, but I failed to automatically login the user ...
18
votes
1answer
9k views
Routing in Asp.net Mvc 4 and Web Api
Can I use the following two route rule together ?
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = ...
13
votes
1answer
9k views
ASP.net MVC custom route handler/constraint
I need to implement an MVC site with urls per below:
category1/product/1/wiki
category1/product/2/wiki
category1/sub-category2/product/3/wiki
category1/sub-category2/sub-category3/product/4/wiki
...
25
votes
4answers
3k views
How can I create a route constraint of type System.Guid?
Can anyone point me in the right direction on how to map a route which requires two guids?
ie. http://blah.com/somecontroller/someaction/{firstGuid}/{secondGuid}
where both firstGuid and secondGuid ...
18
votes
4answers
8k views
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?
13
votes
2answers
8k views
How to get RouteData by URL?
I need to get RoutData by given URL string in ASP.NET MVC application.
I've found the way that I need to mock HttpContextBase based on my URL string and then pass it to ...
13
votes
5answers
8k views
Trailing slash on an ASP.NET MVC route
In the latest MVC preview, I'm using this route for a legacy URL:
routes.MapRoute(
"Legacy-Firefox", // Route name
"Firefox-Extension/", // URL with parameters
new { controller = "Home", action = ...
6
votes
2answers
2k views
.NET WebAPI Attribute Routing and inheritance
I am playing around with the idea of having a base controller that uses a generic repository to provide the basic CRUD methods for my API controllers so that I don't have to duplicate the same basic ...
3
votes
2answers
3k views
Route with Two optional parameters in MVC3 not working
I have a following types of url used in my Application.
localhost/admin/userdetail/id
localhost/admin/userdetail/id/true
localhost/admin/userdetail/id/true/success
Here is my Admin ...
2
votes
1answer
269 views
ASP.NET MVC Route with values before the controller and no trailing slash
This is probably a simple question but I just can't get it to work.
I've got this route specified in my RouteConfig
routes.MapRoute(
name: "DefaultSiteRoute",
url: ...
39
votes
5answers
19k views
How to get current controller and action from inside Child action?
I have a portion of my view that is rendered via RenderAction calling a child action. How can I get the Parent controller and Action from inside this Child Action.
When I use..
...
12
votes
3answers
6k views
How to achieve a dynamic controller and action method in ASP.NET MVC?
In Asp.net MVC the url structure goes like
http://mysite.com/{controller}/{action}/{id}
For each "controller", say http://mysite.com/blog, there is a BlogController.
But my {controller} portion of ...
14
votes
4answers
3k views
Can Areas in an ASP.NET MVC 2 application map to a subdomain?
Is there a way to map the Areas within an ASP.NET MVC 2 application to subdomains such as
movies.example.com/Theater/View/2
instead of
example.com/Movies/Theater/View/2
where { area = "Movies", ...
12
votes
2answers
2k views
Lower case URLs in ASP.NET MVC
Is it possible to force/extend the routing engine to generate URLs in lower case, giving /controller/action instead of /Controller/Action?
17
votes
4answers
3k views
Plus (+) in MVC Argument causes 404 on IIS 7.0
I have an MVC route that is giving me hell on a staging server running IIS. I am running Visual Studio 2010's development server locally.
Here is a sample URL that actually works on my dev box:
...
23
votes
2answers
7k views
ASP.NET MVC: 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 ...
10
votes
1answer
2k views
How to determine if an arbitrary URL matches a defined route
How can I tell if a string matches a particular named route?
I have a route like this:
routes.MapRoute(
"FindYourNewRental",
"find-your-new-rental/{market}/{community}.html",
new { ...
11
votes
1answer
4k views
How to make IRouteConstraint filter route
I wrote a custom route constraint, but its filter just doesn't get recognized. Does anyone have an example working use of IRouteConstraint ?
Also, note to developers: I get double display of the ...
11
votes
1answer
4k views
How can I check if a route (ASP.NET MVC) exists for a given path?
I have a list of local URL’s and I need to determine if they are “valid MVC paths”. How can I check if a URL (path) maps to a MVC controller?
Phil Haack's Route Debugger will find a route that match ...
3
votes
3answers
744 views
asp.NET: Unknown length MVC paths
I am building a MVC application in asp.NET for a web portal. I have prepared a series of controllers, and mapped all the paths that don't macth to this to a Page controller, which will render the ...
14
votes
3answers
873 views
Possible Bug With ASP.NET MVC 3 Routing?
Normally i wouldn't put a title like this in the question, but i'm pretty sure it's a bug (or by design?)
I created a brand new ASP.NET MVC 3 Web Application.
Then i went to the /Home/About page.
...
5
votes
2answers
4k views
Differentiate Guid and string Parameters in MVC 3
Using the out-of-the-box method locators in ASP.NET MVC (3 or 4DP), is there a way to have the MVC framework differentiate between a string and Guid without needing to parse the parameter in the ...
2
votes
7answers
2k views
Dot character in ASP.NET MVC 3 route parameters
I have no custom routes in my application, only the default one. If i try to open localhost/myapp/controller/action/bla.bla it works fine on my machine (Windows 7 x32, both Cassini and IIS) but fails ...
7
votes
4answers
4k views
How can I get controller type and action info from a url or from route data?
How can I get the controller action (method) and controller type that will be called, given the System.Web.Routing.RouteData?
My scenario is this - I want to be able to do perform certain actions (or ...
6
votes
2answers
666 views
Can anyone recreate the following bug I'm experiencing in routes with 2 or more optional parameters, in .NET 4.0 / MVC3?
I know that if you think you found a bug in the .NET framework you are most likely wrong, but that's why I'm writing this question, so please hear me out.
I am fairly certain that there is a ...
3
votes
2answers
7k views
How do I use Server.Transfer method in asp.net MVC?
I am trying to use it for Login page.
if (Session["UserID"] == null)
Server.Transfer("/Account/Login", true);
But I get The Exception -> Error executing child request /Account/Login.
2
votes
2answers
2k views
url with extension not getting handled by routing
I've been folowing the advice from this article for setting up a robots.txt file in asp.net mvc3 for using a controller to handle the server response, and IIS 8.0 express is returning a file not found ...
2
votes
1answer
3k views
Considerations when turning on RouteExistingFiles
I am looking to generate some CSS files dynamically in my Content folder.
At the moment, this folder has an ignore route (routes.IgnoreRoute("Content/{*wildcard}");) and, I'd like that to remain, as ...
1
vote
2answers
2k views
AreaRegistration.RegisterAllAreas() is not Registering Rules For Area
I have an MVC 4 web application which consists some areas. I have a problem with the routing rules of an area named "Catalog". The RouteConfig.cs file is:
public static void ...
4
votes
4answers
3k views
How to make ASP.NET Routing escape route values?
I have an ASP.NET MVC site where I want routes like /{controller}/{id}/{action}/{date}, where "date" is the mm/dd/yyyy portion of a date/time. (I'm dealing with time-dimensioned data, so I need both ...
2
votes
2answers
1k views
Dynamically modify RouteValueDictionary
As a followup of this question, I'm trying to implement a custom route constraint in order to dynamically modify the RouteValueDictionary for a specific route.
I'm 95% of the way there: I can match ...
0
votes
2answers
735 views
need help canonicalizing an HTTP GET form in asp.net mvc
I have a form in an asp.net mvc site that serves 3 purposes: paging, sorting, and searching. These items should all be rendered in the same form, since returning the correct search results depends on ...
5
votes
3answers
2k views
Handle Invalid URL in MVC
How to handle invalid URLs in MVC?
For ex.: When the user enters http://localhost/User/MyProfile instead of
http://localhost/User/Profile, it will throw an exception.
How to handle this request?
11
votes
2answers
5k views
asp.net mvc multilanguage urls/routing
This is a two part question regarding asp.net mvc multilanguage urls/routing and SEO best practices/benefits…
Question Part 1)
I’m being asked to create a new ASP.NET MVC website that will support a ...
25
votes
2answers
5k views
How to prevent Url.RouteUrl(…) from inheriting route values from the current request
Note: I'm answering my own question immediately below
Lets say you have an action method to display products in a shopping cart
// ProductsController.cs
public ActionMethod Index(string gender) {
...