Why won't my MVC project work after publication?

I recently posted my first MVC 2 project on a commercial web server running Windows 2008 and which supposedly supports other MVC sites without problems, but is experiencing some problems. Here is the high-level structure of the project. As you can see, this is very simple:

directories.jpg

But, after publishing the site, and I go to the URL, I get the error message HTTP 403.14 - Forbidden: the web server is configured so as not to display the contents of this directory. "

So, I contacted the web host about this, and I was told that I need to enable the default landing page, such as Default.aspx, Index.aspx, etc. I doubted that this answer was accurate, because I thought MVC Routing took care of this, but I did everything that was suggested by adding a redirect to my home controller in the Default.aspx.cs code, but got an HTTP 404 error I added that redirecting to a tip similar to what is contained in this article: http://www.58bits.com/blog/CommentView,guid,10b2ddfa-057c-41d0-bdc7-564b212ce896.aspx .

I’m going back and forth with the web host about this for more than a week, after about a dozen different answers and answers, but I could not find a solution to this. I am sure this is a simple thing to solve, but I have no idea what to try next or what to offer the web hosting support that they tried next.

Soooo ... knowing that the StackOverflow community is smarter than me and the support technicians of my web hosting company in the aggregate, a thousand times, I hope you can help me work on the resolution here, so I can successfully publish my project and gain access to him without errors.

+6
asp.net-mvc windows-server-2008 publish
source share
5 answers

There are several things that can cause an error:


Problem with MVC Libraries

A production server may not have MVC libraries stored in the GAC. . To fix this, you just need to go into your MVC project References pane / folder and find System.Web.Mvc , System.Web.Routing and System.Web.Abstractions . Now select them with Ctrl by clicking on them and set the Copy Local option to true in the Properties window.

It is difficult to know before publishing to the server whether this is true, so I recommend just installing assemblies for local copying all the time.


Landing page

Your landing page may have problems. From my experience with ASP.NET MVC, I have seen that IIS requires the correct landing page. I am using a page that was included in the ASP.NET MVC 2 template. You must compare mine with yours to see if you have everything you need:

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

Access rights

Based on the first HTTP status code you received, a permission issue may occur. The folder containing your MVC application must be defined as the application and installed with the appropriate permissions .

This is very easy to do using IIS. However, you probably do not have access to IIS; if you do, you are very lucky!

Otherwise, you can change permissions via FTP using the chmod . You can connect via Filezilla, a very good open source FTP client, just do it using the right-click + dialog.

Regarding defining a folder as an application, you should check to see if you can do this using any of the IIS objects provided by the host. If not, contact them and ask them to configure it.


Good luck Hope I helped.

+6
source share

Your IIS product may not have the MVC link files uploaded for your site. I ran into the same problem when I uploaded the MVC site to a host that said, "We fully support MVC." You can try publishing using the "all project files" option. I believe that the problem can also be solved by going to your help folder and selecting mvc links. I am not on my computer for developers right now, but I believe that you have changed a specific property for links to include them in published files.

0
source share

Try precompiling your application . In Visual Studio, configure the deployment project, and then deploy it in release mode.

Since it is precompiled, you do not rely on IIS to compile the project for you to run it. This is what I always do these days, since IIS on the production server can be painful if I need to get it to recompile or update.

0
source share

Based on the comments and answers above, I ended up exploring matching wildcard applications 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 want to re-write the URL, the same as redirecting, please use the example below.

Example rewrite map URL where the following URL

/default.aspx?id=1 will be replaced by /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 rewrite the URL, but redirect the URL, please use the example below.

To redirect your website using ASP, create the file "default.asp".

Paste the following code inside:

 <% Response.Status="301 Moved Permanently" Response.AddHeader "Location","http://www.new-url.com/" %> 

To redirect your website using HTML:

 <HTML><HEAD> <META HTTP-EQUIV=Pragma Content="No-Cache"> <META HTTP-EQUIV=Refresh Content="5;URL=http://YOURURLWHEREYOUWANTTOREDIRECT"> </HEAD> 

Will there be any material above? Seriously, should it be hard to publish an MVC project? I'm really starting to get upset ... :(

Should I just search for a new web hosting? Will it make a difference?

0
source share

The following request is sent: http://stackoverflow.com?variableValue=87

redirect page using variable values ​​in query string: -

Dim variablevalue

variableValue = Request.QueryString ("Occassion")

if variableValue = 87 then

Response.Status = "301 moved forever"

Response.AddHeader "Location", " http://www.google.com "

end if

0
source share

All Articles