14

I got a problem migrating from VS.Net 2008 / MVC 1 to VS.NET 2010 (+C# 4.0) / MVC 2

The web.config has been updated, the site runs well in Cassini, but my problem now is deploying on IIS 6.

I updated the web site to run using ASP.Net 4, but whatever URL I try, I always have a 404 error. It's as if the routing was not taken into account (yes, the wildcard mapping has been done).

I do not understand this mess and could not google anything interesting... Thanks for your suggestions !

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Mose
  • 1,781
  • 3
  • 16
  • 35
  • I tried to deploy the default project created using 'add new project...' and encountered the same problems. Still googling for answers, but hoping for your advices.... – Mose Feb 23 '10 at 15:56
  • 1
    I always got screwed with the wildcard mapping and that goddamn "verify file exists" checkbox. Scrub everything, start from square one, and follow this: http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/ and when I say scrub everything, I mean SCRUB EVERYTHING. Don't assume something is correct. Start at square one and triple check everything. –  Feb 23 '10 at 15:59
  • I did it again but it's still not working. The application I'm working with is working perfectly in MVC 1, but since I passed to .Net 4 / MVC 2, routing is broken... As I said in my previous comment I tried with the sample app and cannot make it work. Thanks for your help. Any other suggestion ? – Mose Feb 23 '10 at 16:42
  • I have the same problem, I'm getting a 404 on everything and I started from square one – Jack Marchetti Mar 03 '10 at 19:24
  • it is worth noting that with .NET 4, it is no longer necessary to have an isapi wildcard mapping to get extensionless urls to work in IIS6. http://blogs.msdn.com/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static-requests.aspx – Mark Glasgow Apr 15 '10 at 15:16

4 Answers4

15

Ok I got y answer (thanks to a colleague)

When migrating from ASP.Net 2.0 to ASP.Net4.0, if you meet the same problem, then check in Web Service Extension if ASP.Net v4 is Allowed.

In my case, after installing the .Net framework 4, it was prohibited.

Will & Mark : thanks for your help, hope it will helps others.

Mose
  • 1,781
  • 3
  • 16
  • 35
6

I think I know what's happening: on IIS6, as well as the wildcard mapping you will need a default document (Default.aspx) that routes folder requests to the MVC handler.

There was one included with the MVC1 project templates, but it has been removed in MVC2.

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNameSpace._Default" %>

<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>

and Default.aspx.cs:

using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace YourNameSpace
{
    public partial class _Default : Page
    {
        public void Page_Load(object sender, System.EventArgs e)
        {
            // Change the current path so that the Routing handler can correctly interpret
            // the request, then restore the original path so that the OutputCache module
            // can correctly process the response (if caching is enabled).

            string originalPath = Request.Path;
            HttpContext.Current.RewritePath(Request.ApplicationPath, false);
            IHttpHandler httpHandler = new MvcHttpHandler();
            httpHandler.ProcessRequest(HttpContext.Current);
            HttpContext.Current.RewritePath(originalPath, false);
        }
    }
}

When you say "It's as if the routing was not taken into account", I suspect that it actually isn't, and this is your problem.

Mark Bell
  • 28,985
  • 26
  • 118
  • 145
  • Thanks for your answer. Unfortunately, I already had a Default.aspx with almost the same code-behind. I tried to use you code (the only difference was the ending Rewritepath back to the original path), but it's still not working. Nonetheless, I got a BIG CLUE : when i try my root url (or any url for that application), IIS returns me the 404 error VERY QUICKLY, event after a iisreset or a server reboot. I suppose it does not load anything ! Checking for issues in that way with C# 4.0. (FYI, the url is http://push.widgetbooster.com) – Mose Feb 23 '10 at 16:55
  • Wow I was going crazy with this issue (I use mvc 2 in .net 3.5 w/ IIS 6) but this solved it! thanks! – Francisco Oct 21 '10 at 14:48
2

This finally fixed it for me:

I commented earlier, and a wee bit prematurely. My comment to Mark B's post was getting my initial Index view to show up, but then I kept getting the 404 errors whenever I navigated to any other view.

I was also distracted by the green check mark approved solution in this particular forum, but I could not even see the web server extensions folder in IIS 6 on my desktop; therefore, I had no control from that stand point of enabling aspnet 4.0, though I made sure it was installed by performing running the following command line:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -i

Now for the actual piece that finally allowed me to navigate to the other views besides just my Home/Index:

In the Global.asax.cs file of your VS 2010 Solution, you will see code as follows in the RegisterRoutes method:

  routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}/{id}", // URL with parameters
      new { controller = "Home", action = "Index", id = UrlParameter.Optional });

I simply added ".aspx" after the {action} section of the tag as follows:

  routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}.aspx/{id}", // URL with parameters
      new { controller = "Home", action = "Index", id = UrlParameter.Optional });

And ahla wahla Peanut Butter and Jelly sandwiches. :0)

Mark Bell
  • 28,985
  • 26
  • 118
  • 145
0

If you want to do it in C#, just add the System.DirectoryServices reference and this piece should do the job nicely.

DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/W3SVC");
w3svc.Invoke("EnableWebServiceExtension", "ASP.NET v4.0.30319");
w3svc.CommitChanges();

HTH

Spooles
  • 785
  • 6
  • 16