The directory or file specified does not exist on the Web server
I have a hybrid asp.net web forms / mvc application that I recently converted to .net 4 with mvc2. I have set-up that application to run on IIS 7.5 (on Windows 7) and the web forms part of the site is running okay but the MVC part is not. Whenever I try and access a page that needs to go through the routing engine I get
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Module IIS Web Core Notification MapRe开发者_如何学JAVAquestHandler Handler StaticFile Error Code 0x80070002I'm debugging this web site through VS2010 (so I've set-it-up to use IIS instead of Cassini) and when I put a break point in the Application_Start function it is never hit so the routes are never registered. When I put a break point in the Page_Load function in one of the aspx page code-behinds it gets hit. So it seems that the problem is that the route is not being registered.
What am I missing?
From my experience with ASP.NET MVC, I've seen that a Default.aspx
page is required for IIS to function correctly. I'm using the page that was included in the ASP.NET MVC 1 template. Unfortunately, the ASP.NET MVC 2 does not include this page (to the best of my knowledge), so you should add the following to your project:
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);
}
}
}
I remember reading somewhere about a similar problem that Global.asax events weren't firing. Try to remove the Global.asax file and add it again (just remember to re-add the needed routes code).
I had a WebForms, and when I added the API files I needed to change my global.asax file too. All I did was create a new blank API project and then copy the files across. When you add the text in the global.asax file, you get told of other libraries you need (such as WebApiConfig). Simply follow the trail.
精彩评论