views:

3549

answers:

6

Hi,

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 !

O.

+5  A: 

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 B
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
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
+11  A: 

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
A: 

Hi,

I'm having the same issue can you go into some more detail about your solution, is this a setting in IIS 6?

Many thanks

Simon

SImon
Yes it is : http://screencast.com/t/YTQwNjI5Y then http://screencast.com/t/NDg1MDcz
Mose
A: 

Hi Simon,

Did you solve the IIS issue ? We are facing the same problem, our application didn't work on IIS 6. We used Asp.net MVC 2.0 and visual studio 2010. Please let me know.

Thanks

B. Mavi

B. Mavi
A: 

I'm not supplying an answer but just wanted to let others know that I was having the same issue and implementing the solution propsed by Mark B fixed the problem like a charm:

  1. Added a Default.aspx web form to my MVC 2 application in the root directory of the app.
  2. Copied the code from Mark B's suggestion into the Page Load event
  3. Added "using System.Web.Mvc;" the compiled site.
  4. Copied site files to deployment directory.
  5. Viewed Virtual Directory properties for the site and under the Documents tab, added Default.aspx and moved it to the top of the list.
  6. Then I simply navigated via the browser to http://local/"Site Directory", and PRESTO!

Thanks, Mark, for the solution.

Joe

Joe de la Forms
A: 

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)

Joe de la Forms