views:

198

answers:

3

I know I've asked this question before, and I know there are plenty of resources out there describing the technique but I cannot for the life of me work it out.

I began by creating a simple WebForms application.

I then added the Views and Controllers folders. I then added home and shared folders to the views and added an Index.aspx and a site.master file.

I created the HomeController.cs file.

I then made the changes to the web.config and added the web.config into the views folder.

I then made the changes to the global.asax page.

The whole thing compiles, routes appear to get registered but I simply cannot open the Home/Index page.

I always get "HTTP Error 404 - Not Found"

Has anyone actually managed to do this? Oh and we're using IIS6 here.

CODE BELOW

Global

public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}.mvc/{action}/{id}",                           // URL with parameters
        new { action = "Index", id = "" }  // Parameter defaults
    );

    routes.MapRoute(
        "Root",
        "",
        new { controller = "Home", action = "Index", id = "" }
      );

}

Web.Config

<compilation debug="true">
      <assemblies>
                <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>


     <pages>
      <controls>
       <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
      <namespaces>
       <add namespace="System.Web.Mvc"/>
       <add namespace="System.Web.Mvc.Html"/>
                <add namespace="System.Web.Routing"/>
       <add namespace="System.Web.Mvc.Ajax"/>
       <add namespace="System.Linq"/>
       <add namespace="System.Collections.Generic"/>
      </namespaces>
     </pages>


     <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
     </httpModules>

Home Controller

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

[HandleError]
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }

    public ActionResult About()
    {
        return View();
    }
}

Home View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MVCSite.master" Inherits="System.Web.Mvc.ViewPage"%>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    MVC Home Page

    <%= Html.TextBox("txtTest") %>
    <%= Html.ActionLink("About Page", "About") %>

</asp:Content>
A: 

Did you set up the wildcard mappings?

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

jfar
No I haven't and to be honest I'm having some difficulty following what to do.
griegs
Well then this is your problem. IIS6 has no idea how to process .mvc links.
jfar
Agreed, this is your problem if you haven't done it.
Odd
Um, I'm saying "this is the problem you have" and not "well its your problem now, sucks, haha". Sorry if it came across that way, I'm just certain your lack wildcard mappings are the source of your problem.
jfar
And furthermore that guide is the best there is out there. I couldn't do any better myself. It tells you exactly what to click on.
jfar
@jfar, cool mate. yeah it's kinda hectic here at the moment with pre-end-of-year project wrap ups. you know the ones. so have little head space for lengthy pages w/ explanations. slack I know. I have added +1 to bring it back to zero.
griegs
Thanks? I'm 100% certain this is your problem: http://stackoverflow.com/questions/1860444/mvc-1-0-doesnt-work-on-iis6/ and I get a 0?
jfar
+1  A: 

I would go the other way and create an MVC application and then add the webforms that you needed. much simpler as the default MVC application has all the neccessary bits already set up for you.

You would need to create a seperate folder where your webforms would live. Then you can include/exclude the folder from the routing engine as needed.

Nathan Fisher
Yeah not a bad idea expect that I am trying to fit mvc into an existing webforms app that is huge. we are attempting to replace bits piece by piece and not all in one shot.
griegs
Definitely easier to start with a working MVC app that is essentially provided for you. You could alway create one and compare it to your app config settings if you really want to know what's broke.
confusedGeek
Yeah I guess I could do that. Has no one actually managed to do this yet?
griegs
A: 

Turns out that the web site needed to be a web application.

I also needed to add the following into the web.config;

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            <remove name="UrlRoutingModule"/>
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing"/>

Thanks and +1 to all that tried to help.

griegs