.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Routing MVC2

Posted By:      Posted Date: October 24, 2010    Points: 0   Category :ASP.Net

I have a url


 I wanted to route the and make it 

  http://localhost:2151/Classified/London/                    here  cid =1 ,=> London

To accomplish this I written this code in Global.asax

            new { controller = "Classified", action = "citycatadd", id ="city"  }  );

and this code in HTML

<%= Html.ActionLink(objaddcity.city1, "citycatadd"

View Complete Post

More Related Resource Links

ASP.NET MVC2 Custom routing with wildcard or free text url


I have a requirement to add specific functionality to an asp.net mvc2 web site to provide addtional SEO capability, as follows:

The incoming URL is plain text, perhaps a containing a sentence as follows

"http://somesite.com/welcome-to-our-web-site" or "http://somesite.com/cool things/check-out-this-awesome-video"

In the MVC pipeline, I would like to take this URL, strip off the website name, look up the remaining portion in a database table and call an appropriate controller/view based on the content of the data in the table. All controllers will simply take a single parameter bieng the unique id from the lookup table. A different controller may be used depnding on different urls, but this must be derieved from the database.

If the url cannot be resolved a 404 error needs to be provided, if the url is found but obsolete then a 302 redirect needs to be provided.

Where the url is resolved it must be retained in the browser address bar.

I have had a look at the routing model, and custom routing and can't quite work out how to do it using these, as the controller would not be predefined, based on a simple route. I am also unsure of what to do to provide 404, 302 back to the headers also. Perhpas I need a custom httpmodule or similar but going there went beyond my understanding.

This must be possible someho

Routing for Web Forms in ASP.NET 4.0

posted a prototype demonstrating how one could use Routing within Web Forms. This is something you can do today with ASP.NET 3.5 SP1, because of the work we did to separate Routing from ASP.NET MVC. I would have liked to include Web Form Routing as part of the Routing feature when we were working on SP1, but we didn't have the time to do so in a robust manner before SP1 was locked down.

What's new in ASP.NET 4.0 - Part II - Routing in Webforms

This post covers one such feature which is Routing in Webforms. Although Routing was available even in .NET 3.5 SP1, (check this excellent post by Phil Haack on implementing Routing in ASP.NET 3.5 with .NET 3.5 SP1), it was kind of less known. Also the plumbing work was too much for getting it implemented.

ASP.NET 4.0: WebForm Routing (quick n dirty version)

One of the things we're adding in ASP.NET 4.0 is built-in support for using Routing together with WebForms. Now, I'm totally aware that this is possible to do already and that a number of people have posted ways of doing this with the Web Routing feature which shipped with ASP.NET 3.5 SP1. We're just adding some features to make it easier to do

MVC2 issue - Stuck. Trying to create a cms with nested partials


I am currently trying to display multiple items on a single page. I am not sure as to how to tackle this. What I have is a database table that has all the page data in. I have this run as a PagesController and this works fine. However what I would like to do is, if say the Products page is selected via the menu, I want to pull back not only the Products page html but also get all the products, and even be able to pull them through via category. I was trying to use a partial view, but I can't get it to work. The same would be for other pages, having partial views to display the other content, ie if Gallery is selected, the page html for Gallery shows and it then can push to a partial view that pulls all the gallery images from the gallery db table and so on. 

Maybe I am tackling this the wrong way. I have the pages stored in the db to allow for a CMS system I have setup. Maybe I need to use models for all the other items(Products, Gallery, Videos and such) and use the partial for the page html?

Any help would be greatly appreciated as I am confused.

Problem upgrading to MVC3 - System.Web.Routing



I'm trying to upgrade to .NET 4 and MVC 3.

When trying to compile my project, I get the error:

Error 1 The type or namespace name 'Routing' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) C:\Users\spencer\Desktop\weblauncher\Common\MVCConfig.cs 4 18 Common

The type or namespace name 'Routing' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

I do have the System.Web.Routing in my references for the project.

BUT - when I try to view System.Web.Routing in the OBJECT BROWSER, nothing is inside!  The System.Web.Routing namespace is not in there - the entire thing is empty!  Could it that the dll is corrupted?  I tried to reinstall the .NET 4 and MVC 3 stuff, but its still empty!

The dll is coming from here:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Routing.dll

and the runti

areas mvc2 iis 6.0


hi all,

i have another problem. I am trying to deploy my MVC2 website on iis 6.0. I have added the following to my global.asax:


routes.MapRoute("Default","{controller}.mvc/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional } );

I added the ".mvc" extention because i read that iis 6 needs this. And it works. BUT!! I also use areas, and this is something iis 6 does not understand.

I have the following:
No Areapath: Home.mvc/Index (works fine, no area used)
Areapath: Projects/Overview/Index (does not work!!)

I don't now how to solve this, i hope somebody can help me.




Routing in dynamic data applications


Im using ASP.Net 4. I tried to modified the code according to following video tutorial. http://www.asp.net/aspnet-in-net-35-sp1/videos/how-to-enable-table-specific-routing-in-dynamic-data-applications

But Product page directs only to ListDetails.aspx page.

This is my code :

<%@ Application Language="C#" %>
<%@ Import Namespace="System.ComponentModel.DataAnnotations" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.DynamicData" %>

<script RunAt="server">
    private static MetaModel s_defaultModel = new MetaModel();
    public static MetaModel DefaultModel {
        get {
            return s_defaultModel;

    public static void RegisterRoutes(RouteCollection routes) {

        DefaultModel.RegisterContext(typeof(NorthwindDataContext), new ContextConfiguration() { ScaffoldAllTables = true });


URL Routing and Existing HttpHandler problems


Hello everyone,

I have a problem:

I am currently using 2 features: 

1. HttpHandler

Registering the path="res.aspx" verb="*"

2. URL Routing:

Registering with this pattern: "Company/Edit/{*companyId}","~/CompanyEdit.aspx"

In my CompanyEdit.aspx page, I used httphandler res.aspx to generate some images at client.

  • res.aspx?img=1
  • res.aspx?img=3

Now the problem is here, the page is load success with companyId = "12345", but when the images was loaded at client, it loaded the CompanyEdit.aspx again and show error with wrong id.  

I have debug and find the problem that because when image's urls were generated to client with url=res.aspx?img=1, url=res.aspx?img=3, the asp.net will understand that they are Company/Edit/res.aspx?img=1, Company/Edit/res.aspx?img=3 when it maps with URL Routing pattern.

=> So the CompanyEdit.aspx was load again with wrong id (id now is "res.aspx"). 

So, do you have any ideas to solve this problem, or other design.

Thanks, and best regard

Extreme ASP.NET: Routing with ASP.NET Web Forms


See how to get the benefits of rerouting while alleviating the risks with this in-depth look at URL rewriting in ASP.NET.

Scott Allen

MSDN Magazine January 2009

Tip #107 Did you know . How to improve debugging performance for MVC2 application in Visual Studio 2

VS2010 Ultimate included IntelliTrace functionality by default.  IntelliTrace captures events (e.g. exceptions), and can affect performance of debugging. The typical performance hit is about 5% in the default mode (collection can be increased to...(read more)

How to switch between HTTP and HTTPS in ASP.NET MVC2


ASP.NET MVC2 has the new RequireHttpsAttribute that you can use to decorate any action to force any non-secure request to come through HTTPS (SSL).  It can be used as simply as this:

        public ActionResult LogOn()

Now any request to the LogOn action that is not over HTTPS will automatically be redirected back to itself over HTTPS.  This is very useful and easy to implement.

Unfortunately though, once the scheme is changed to HTTPS, all following requests will also be under HTTPS, which is not necessarily what you want.  In most cases you do not need all requests to your site to be secure but only certain ones such as the logon page or pages that accept credit card information. 

To handle this you can override the Controller.OnAuthorization method.  From within this method, you can check to see if the RequireHttps attribute is set on the Controller Action by searching the Attributes collection of the ActionDescriptor object. If the RequireHttpsAttribute is not set AND the request is under SSL, then return a redirect result to the HTTP (no

routing fails



I am trying to compile and run an asp.net application and am getting the following errors

 HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

I have a starting URL of http://localhost:61431/WebSuds/Suds/Welcome and routing code

"Default",                                 // Route name
"{controller}/{action}/{page}",            // URL with parameters
new { controller = "Suds", action = "Welcome",

ModelBinders obsolete in MVC2?



I have a shopping cart that uses MVC 1 (guide from the book "Pro ASP.NET MVC Framework" by Steve Sanderson). Now that MVC 2 and VS2010 are released, the shopping cart no longer works.

Is there any changes about the ModelBinders.Binders.Add(), is it obsolete in MVC2? The code binder below wasn't hit at all in Application_Start(). Sad


    Sub Application_Start()

ModelBinders.Binders.Add(GetType(ShoppingCart.Model.Cart), New CartModelBinder)
End Sub


Imports System.Web.Mvc

Public Class CartModelBinder
Implements System.Web.Mvc.IModelBinder

Private Const cartSessionKey As String = "_cart"

Public Function BindModel(ByVal controllerContext As ControllerContext, ByVal bindingContext As ModelBindingContext) As Object Implements IModelBinder.BindModel
If (Not (bindingContext.Model) Is Nothing) Then
Throw New InvalidOperationException("Cannot update instances")
End If
Dim cart As ShoppingCart.Model.Cart = CType(controller

Multiple forms on the same page MVC2: how to handle (including validation from model)



It should be simple; although I'm having a hard time to figure out the best way to do it. I've MVC2 pages with multiple forms on the same page having different functionalities.

What's the best way to handle this; including the MVC2 way of validation from the model?


Strange URL Routing Problem, participially working


I am setting up URL Routing on my existing project. I am not using mvc.

The routing only working like this: http://www.example.com/sdevil.m

not working with single word like this: http://www.example.com/sdevil

I am getting error message:The resource cannot be found.

Looks like when I using single word, application think that is folder?

How can i fix this? Thank you for any helps.

MVC2 Music Store - How to get store controller - store.aspx working {genre names displayed}



<p>Select from <%: Model.NumberOfGenres %> genres:</p><ul> <% foreach (string genreName in Model.Genres) { %>

<li> <%: genreName %> </li>

<% } %>


MOST PEOPLE WILL BE USING VISUAL STUDIO 2008 sp1, to get this to work change the <%:, ONLY WITH SEMI COLONS, TO <%=

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend