A: 

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.

James Santiago
That's a good thought, though I think I already tried that. Maybe I did it wrong. What I did was (1) include the following references in the project:System.Web.Routing.dllSystem.Web.Abstractions.dllSystem.Web.ExtensionsSystem.Web.Mvc... and (2), set the "Copy Local" property on these references to "True."Does that sound like what you were suggesting, or could I have done it incorrectly?
campbelt
+3  A: 

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.

Maxim Zaslavsky
Holy ... You are a literal genius. I had already tried the first steps you suggested, reagrdig refernces. Your second suggestion was the magical one. I CANNOT express to you how relieved I am at this moment. Now, I'm going to really dig in and understand what the problem was and how your solution helped.Thanks again!
campbelt
Ahhhh... dang it. I was really excited because the home page loaded, which had never worked before. But, while the home page did successfully load, every link I click is taking me to an Error 404 page. Do you happen to have any thoughts on what could be causing this?
campbelt
Check Rup's comment, it's the wildcard application mapping that's not set correctly.
ZippyV
Thanks, ZippyV. I'll see if I can get that information out of my web host, who has been ... less than helpful so far, unfortunately.
campbelt
I spoke with my web host about this, and they said the don't support wildcard mapping. I posted details from their response in an answer, below ...Should it be this hard publish an MVC project? Should I just look for a new web host? Would that make a difference?
campbelt
I ended up resolving this by simply quitting my web server host and getting a new one. So, in the end, I don't really know what the answer to this problem was, but I am going to mark this response as the accept one because it brought me closest to the solution, and sent me in the right direction.
campbelt
@campbelt glad to hear that your new host is better. Just curious, what host did you use before? I don't want to ever buy hosting from them! :)
Maxim Zaslavsky
A: 

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

Markive
A: 

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>
  1. 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"&gt;
</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?

campbelt
You already confirmed that navigating to the root of your site works (because it executes default.aspx). As a quick fix you can change your routing from "{controller}/{action}/id" to "default.aspx/{controller}/{action}/id". That should fix it.
ZippyV
@ZippyV's tip should probably work. But you're right, it shouldn't be this hard to publish an MVC site. Personally, I use GoDaddy - publishing is just Build --> Publish (as long as you copied the MVC DLLs locally) and FTP.
Maxim Zaslavsky
Maxim Z., thank you for your comment. You have to do more than Build -> Publish? You have to FTP some files as well? U haven't been doing that, could that be my problem? Anyway, I think I am going to go ahead and see if I can get one month of hosting from GoDaddy and see if have more success there.
campbelt
ZippyV, thank you for your suggestion. I tried that, and it allowed me to access some of my pages, but not all. I didn't dig into it enough to determine which ones, or why some and not others. Though, the ones that did load seemed to do so without any of the CSS styling applied. I don't recall exactly, but I think I read somewhere that can occur when the routing is trying to access static files or something ...
campbelt