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

前端 未结 4 621
深忆病人
深忆病人 2020-12-28 19:03

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

The web.confi

4条回答
  •  清酒与你
    2020-12-28 19:30

    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.

提交回复
热议问题