开发者

Deploying Asp.Net MVC 2 /C# 4.0 application on IIS 6

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 acco开发者_开发知识库unt (yes, the wildcard mapping has been done).

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


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.


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.


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜