yad4u Why won't my MVC project work after publishing it?

Why won't my MVC project work after publishing it?

I recently published my first MVC 2 project to a commercial web server, running Windows 2008, and which purportedly supports other MVC sites without issue, but have been experiencing some problems. Here is the high-level structure of the project. As you can see, it is very simple:

But, after the site is published, and I navigate to the URL, I get "HTTP Error 403.14 - Forbidden: The Web server is configured to not list the contents of this directory."

So, I contacted the web host about it and was told I had to include a default landing page, such as Default.aspx, Index.aspx, etc. I doubted this response was accurate because I thought MVC Routing would have taken care of this, but I did as suggested anyway, adding a redirect to my home controller in the Default.aspx.cs codebehind, but got an HTTP Error 404. I added that redirect per advice similar to that found in this article: http://www.58bits.com/blog/CommentView,guid,10b2ddfa-057c-41d0-bdc7-564b212ce896.aspx.

I've been going back and forth with the web host about this for over a week, across about a dozen different responses and answers, yet I have not been able to find a resolution to this. I am sure this is a simple thing to resolve, but I have no idea what to try next, or what to suggest to the web hosting support that they try next.

Soooo ... knowing that the StackOverflow community is smarter than me and the support techs for my web hosting company combined, a thousand times over, I'm hoping you can help me work toward a resolution here, so I can successfully publish my project and access it without error.

Pulling a View from a database rather than a file


When is it ok to meddle in the page lifecycle an ASP.NET MVC page?
There's a few things that could be causing the error:.
Significant advantages of ASP.NET MVC

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.

ASP.NET MVC application fires Session_Start multiple times for a single session
Now, select them by Ctrl clicking on them, and set Copy Local to true in the Properties window..
Asp.net MVC Binding
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..
Deploy ASP.NET website alongside ASP.NET MVC website

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.

style problem with data returned from action method
I'm using the page that was included in the ASP.NET MVC 2 template.

Email errors in a asp.net mvc application
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.

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


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


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


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

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


The following request is sent: http://stackoverflow.com?variableValue=87. redirect page using variable values in a Query String :-. Dim variableValue. variableValue = Request.QueryString("Occassion"). if variableValue = 87 then. Response.Status="301 Moved Permanently". Response.AddHeader "Location","http://www.google.com". end if .

88 out of 100 based on 68 user ratings 718 reviews