It may be that your production IIS doesn't have the MVC reference files loaded for your site. I ran into the same issue when I loaded a MVC site to a host that said "we fully support MVC." You can try publishing using the "all project files" option. I believe the issue can also be resolved by going into your references folder and selecting the mvc references. I'm not at my developer machine right now but I believe you change a certain property for the references to have them included in your published files.
There's a few things that could be causing the error:
Issue with the MVC libraries
The production server might not have the MVC libraries stored in the GAC. To fix this, all you have to do is go into your MVC project's References
pane/folder and find System.Web.Mvc
, System.Web.Routing
, and System.Web.Abstractions
. Now, select them by Ctrl clicking on them, and set Copy Local to true in the Properties window.
It's hard to know before you publish to a server whether or not this is the case, so I recommend just setting the assemblies to copy local all the time.
Landing Page
Your landing page may have issues. From my experience with ASP.NET MVC, I've seen that a landing page is required for IIS to function correctly. I'm using the page that was included in the ASP.NET MVC 2 template. You should compare mine to yours to see if you have everything that's needed:
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);
}
}
}
Permissions
Based on the first HTTP status code you got, there may be a permissions problem. The folder containing your MVC application must be defined as an application and set to the appropriate permissions.
It's quite easy to do both those things through IIS. However, you probably don't have access to IIS; if you do, you're very lucky!
Otherwise, you can change the permissions through FTP using the chmod
command. You can connect through Filezilla, a very good open-source FTP client, a just do it through a right-click + dialog box.
As for defining the folder as an application, you should check whether you can do it through any of the IIS things provided to you by the host. If not, contact them and ask them to set it up.
Good luck! Hope I helped.
Try pre-compiling your application. In visual studio setup a Deployment project and then deploy it in release mode.
Because it's pre-compiled you aren't relying on IIS to compile the project for you to run it. This is what I always do these days as IIS on the production server can be a pain if I need to force it to re-compile or update..
Based on the comments and replies above, I ended up exploring wildcard application mapping by asking my web host if they support it. Here is what I got in response:
Wildcard mapping is not supported by our services.
If you would like to use URL re-writing, which is the same as rerouting please use the example bellow.
Example of using URL rewrite map where the following URL
/default.aspx?id=1 will be replaced with /default.aspx?id=25
<rewrite>
<rewriteMaps>
<rewriteMap name="/default.aspx?id=1">
<add key="1" value="25" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Rewrite rule1 for /default.aspx?id=1">
<match url=".*" />
<conditions>
<add input="{/default.aspx?id=1:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
- If what you are trying to do is not URL re-writing but is URL redirection please use the example bellow.
To redirect your web site using ASP create file "default.asp".
Place the following code inside:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>
To redirect your web site using HTML:
<HTML><HEAD>
<META HTTP-EQUIV=Pragma Content="No-Cache">
<META HTTP-EQUIV=Refresh Content="5;URL=http://YOURURLWHEREYOUWANTTOREDIRECT">
</HEAD>
Will any of the stuff above even work?. Seriously, should it be this hard publish an MVC project? I'm really starting to get frustrated ... :(
Should I just look for a new web host? Would that make a difference?