I'm trying to deploy my ASP.NET MVC 2 website from VS2010 beta 2 to IIS7. The publish works fine but none of the routes work, so when I go to the URL http://localhost/myapp/Home/Index I get the error:
HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I'm deploying to a virtual directory which is using an app pool configured for the .NET 4 framework with managed pipeline mode set to integrated. Also, if I go Basic Settings->Test Connection, both tests pass. From 开发者_Python百科what I understand, it should just work?
I don't have any problems deploying Nerd Dinner from VS2008, that works fine.
Are you including the right MVC dll in your publish?
When ever I've had problems browsing my MVC applications it's been because I didn't include the MVC dll in the bin folder.
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);
}
}
}
精彩评论