2010-05-18 670 views
1

我有一個混合的asp.net web窗體/ mvc應用程序,我最近使用mvc2將其轉換爲.net 4。我已經設置了該應用程序在IIS 7.5上運行(在Windows 7上),並且該網站的Web表單部分運行正常,但MVC部分不是。每當我嘗試訪問需要通過路由引擎的頁面時,我都會得到指定的目錄或文件在Web服務器上不存在

HTTP錯誤404.0 - 未找到
您正在查找的資源已被刪除,名稱已更改或暫時不可用。
模塊IIS Web核心
通知MapRequestHandler
處理器StaticFile
錯誤代碼0x80070002

我調試通過VS2010這個網站(所以我設置它爲使用IIS的,而不是卡西尼)和當我在Application_Start函數中放置一個斷點時,它永遠不會被打到,所以路由永遠不會被註冊。當我在其中一個aspx頁面代碼後面的Page_Load函數中放置一個斷點時,它會被擊中。所以問題似乎是路由沒有被註冊。

我錯過了什麼?

+1

如果您的應用程序池的管理流水線模式設置爲經典模式而不是集成模式,也會發生此錯誤。 – 2010-11-01 15:04:40

回答

1

根據我對ASP.NET MVC的經驗,我看到一個Default.aspx頁面是IIS正常運行所必需的頁面。我正在使用包含在ASP.NET MVC 1模板中的頁面。不幸的是,ASP.NET MVC 2不包括此頁面(據我所知),所以你應該添加以下項目:

的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. --%> 

的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); 
     } 
    } 
} 
0

我記得在某處讀到Global.asax事件沒有發射的類似問題。嘗試刪除Global.asax文件並再次添加(只記得重新添加所需的路由代碼)。

+0

這不是針對該問題的正確解決方案。它只是拒絕問題的方式。生產服務器環境如何?如果用戶將登錄頁面設置爲默認值,並且在Globle.asax中路由並且仍然無法訪問,並且我們需要數百個設置才能運行應用程序......它僅僅是公牛表格......由微軟部署每次製作過程都需要進行一次,每次新的IIS後都需要進行研發。 – 2012-05-15 12:06:38

0

我有一個WebForms,當我添加API文件時,我也需要更改我的global.asax文件。我所做的只是創建一個新的空白API項目,然後複製文件。 當您在global.asax文件中添加文本時,會獲知您需要的其他庫(例如WebApiConfig)。只需追蹤蹤跡。

相關問題