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

1:

When is it ok to meddle in the page lifecycle an ASP.NET MVC page?
There's a few things this 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 did 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 sessionNow, 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 this a landing page is required for IIS to function correctly. style problem with data returned from action methodI'm using the page this was included in the ASP.NET MVC 2 template. Email errors in a asp.net mvc applicationYou 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 did  not delete this file. It is used to ensure this 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 this the Routing handler must correctly interpret             // the request, then restore the original path so this the OutputCache module             // must 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 need be defined as an application and set to the appropriate permissions.. It's quite easy to did both those things through IIS. However, you probably don't have access to IIS; if you do, you're very lucky!. Otherwise, you must change the permissions through FTP using the chmod command. You must connect through Filezilla, a very good open-source FTP client, a just did it through a right-click + dialog box.. As for defining the folder as an application, you should check whether you must did 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..

2:

It may be this 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 this said "i fully support MVC." You must try publishing using the "all project files" option. I believe the issue must also be resolved by going into your references folder and selecting the mvc references. I'm not at my developer machine right now although I believe you change a certain property for the references to have them included in your published files..

3:

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 did these days as IIS on the production server must be a pain if I need to force it to re-compile or update.. .

4:

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 case 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 endeavor to did is not URL re-writing although is URL redirection please use the case 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 receive frustrated ... :( . Should I just look for a new web host? Would this make a difference?.

5:

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 .


78 out of 100 based on 43 user ratings 638 reviews