Home > ASP.NET, IIS, MVC > Getting ASP.NET MVC 3 to work with ASP.NET Website project

Getting ASP.NET MVC 3 to work with ASP.NET Website project

There are numerous blog posts on how to get MVC to work with ASP.NET Web Applications. However there are still scenarios where developers are using normal ASP.NET website projects rather than Web Application projects.

Below are the steps to enable MVC 3 with an asp.net website project

1. Install ASP.NET MVC 3

2. Modify web.config

Open up web.config in Visual Studio and add the following lines inside the <compilation><assemblies> section

<add assembly="System.Web.Abstractions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

3. Modify global.asax

Next you will need to add in the code for MVC triggers inside global.asax (create one if it does not exist)

Add the following lines after <%@ Application Language="C#" %>

<%@ Import Namespace="System.Web.Mvc" %>
<%@ Import Namespace="System.Web.Routing" %>

Add the following after <script runat="server">

public void RegisterGlobalFilters(GlobalFilterCollection filters)
filters.Add(new HandleErrorAttribute());

public static void RegisterRoutes(RouteCollection routes)

new { controller = "Home", action = "Index", id = UrlParameter.Optional });}

add the following inside application_start


At this point, your global.asax should look like

4. Creating the controller

Because this is a website project, compilation is at runtime, so you will have to create your controllers inside the App_Code folder rather than the normal Controller folder in the main site

Note that your controller class needs to end with the Controller keyword. In the example, with a controller = “Home”, the classname for the controller needs to be HomeController

To add your first controller, right click on the App_Code folder and create a new class with the file name as HomeController.cs

Paste the following code into the HomeController.cs (replace everything)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

public partial class HomeController : Controller
    protected override void Execute(System.Web.Routing.RequestContext requestContext)

    public ActionResult Index()
        var r = new ContentResult();
        r.Content = "Hello World";
        return r;


5. Test the site

Now that you have generated the routing and created the controller, browse to localhost/home. You should see “Hello World”


Categories: ASP.NET, IIS, MVC
  1. May 3, 2012 at 11:25 am

    This is great. Thanks. But how do you add a View?

    If I put it in the App_Code folder, it doesn’t find it at run time. If I don’t put it in the App_Code folder, it says “The name ‘ViewBag’ does not esict in the current context

  2. July 19, 2013 at 2:21 pm

    can i create a view and can i show it?

  3. Michael Chaney
    November 6, 2013 at 2:18 am

    Russell/baha –

    I’m sure you figured this out by now, but put a Views folder in the root of your site just like you would see in a normal MVC 3 web app project. You will need to add a web.config in that Views folder (just copy the one from the Views folder in regular MVC3 web app project). BTW you will need to references to the System.Web.Razor and System.Web.WebPages if you want Razor support…

  4. February 5, 2014 at 6:43 pm

    Thanks for your marvelous posting! I truly enjoyed reading it, you can be
    a great author. I will make certain to bookmark your blog and definitely will come back from
    now on. I want to encourage you to ultimately continue
    your great work, have a nice afternoon!

  5. yassine
    June 24, 2014 at 10:10 pm

    Does anyone know how to enable visual studio for mvc tooling/templates in asp.net website project

  6. nadavdb56
    August 21, 2014 at 4:19 pm

    Thanks a lot.
    Used this great article to integrate MVC 5.0 in existing ASP.NET 4.5.1 web site.
    Also note: before all steps install NuGet:
    – Microsoft ASP.NET MVC
    – WebGrease

  7. Rag
    October 29, 2014 at 11:55 pm

    Hi nadavdb56,
    Can you please let me know where you have created ur view and the model structure that will be great

    • December 29, 2014 at 8:07 am


      the views are in the same view folder, model would be in app_code because that needs to be compiled

      At the end of the day, Controllers and Model are defined based on certain criteria, controllers should always be in the format xxxController where xxx is the name of the controller. The corresponding view folder for that controller would be xxx. e.g a controller named HelpMeController (note that the C is in caps) will need a view folder called HelpMe

    • December 29, 2014 at 3:34 pm

      As kwanann wrote,
      The view folder is under the root of site and all other MVC classes (Controllers & Models are under the App_Code folder).

  8. October 27, 2015 at 5:55 pm

    The reason why there is no further steps on adding view is simply because its a simple step of adding a VIEW folder inside your asp.net web application

    MVC in ASP.NET works in very straightforward terms, so if you have created a brand new MVC app, you will have realized the folder structure. You simply need to replicate it to the web-forms site and you are done

    For those looking for the original question: http://stackoverflow.com/questions/32646126/mix-mvc-4-with-asp-net-websitenot-web-application

    And in reply to your question, what is happening is your Razor DLL might not be updated, so either create a new MVC app and copy those DLL over or use nuget to update the references

  1. November 30, 2013 at 10:37 pm
  2. September 18, 2015 at 3:28 pm
  3. September 19, 2015 at 7:18 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: