ASP.Net MVC Application cannot find home index page on the server - asp.net-mvc

I deployed a MVC web application with razor view to godaddy.com. My application works fine on localhost, but after deployed, it cannot route to my home page when I typed in the domain name. I have the following route registered in my Global.axcs file.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "HomePage", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Godaddy's technical supports asked me to add an index.html file in the root. I did add one and comment the default route in Global. And it loads the index.html. But I really want to display my /HomePage/Index
Does anyone know why this happens, and any suggestions?

I also faced a similar issue in the past.
One issue here might be that your server does not have MVC installed (as in my case).
Resolution : I followed the post to bin deploy the MVC assemblies together with my web application.
http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx
It worked for me.
Give it a try and I think it should work.

Related

MVC 5 in VS2012

I have installed ASP.NET and Web Tools 2013.1 for Visual Studio 2012 which has the MVC 5 templates for Visual Studio 2012. In Project Templates I am able to find the "ASP.NET MVC5 Empty Project" however after creating the Project, if I try to open the same project in the Internet Explorer by Pressing Ctrl+F5 it gives an error saying,
Server Error in '/' Application.
But When I create a MVC 4 Web Application and try to run it the Application works fine and shows the default page of the MVC 4 App.
Is there any other configuration needed to be done on the Visual Studio 2012 to make it run?
An Empty application is just that. Empty. There is no default page. It's an empty project that you have to create the content for.
Microsoft did not supply a default application template for MVC5 in VS2012. VS2013 does have a default template though.
Since it is an empty template it doesn't have a landing page and hence it was throwing the error
Server Error in '/' Application.
if you append the Controller name and view name just like below
localhost:port/[Controller]/[View]
It will show the contents of view.
you can try either edit your routing.config file, or change your url. Usually it will default to index.
This is an example of a route you can maybe add in as a class, if you do not have one already. This controller just means that it defaults to the Home controller, at the action called index.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
I hope this somewhat helps .

Setting up the root url in IIS7 for asp.net mvc 2

I have a bit of a strange question. I'm building a multi tenant website with Asp.net MVC 2 and running it on IIS7. I'm trying to get my dev environment setup properly for testing but I'm having a weird issue though.
I created the website in IIS and pointed the directory to the location of my source code. I have just the basic HomeController along with an Index view setup. I have a binding in IIS on my website (and setup in my hosts file) for www.mydomain.com (this is so I can test the multi-tenant stuff).
When I run the site and I navigate to www.mydomain.com/home or www.mydomain.com/home/index everything pulls up fine. But navigating to www.mydomain.com gives me the IIS7 logo page. Is there something special I need to configure to get the root url to show me the Home/index page by default?
You need to configure a route like this:
routes.MapRoute("home", "",
new { controller = "home", action = "index" });
or this:
routes.MapRoute("home", "{action}",
new { controller = "home", action = "index" });
Your application must be running in IIS7's integrated pipeline mode. Otherwise you're going to need that default.aspx from the default ASP.NET MVC 1 project template.

blank pages/routing issue with asp.net mvc 2 iis7 integrated windows7 vs2010

I've been searching though a number of posts and still can't seem to get a straight answer or at least one that works for me. From what I can tell is is some kind of routing issue. In fact I'm pretty certain of it. When I visit any of my web pages it comes back as a blank page with no data.
Also I am using VS2010 asp.net mvc2 on window7 using iis7 integrated. The purpose of using iis7 integrated is because when I publish the site to my godaddy hosting provider I want to be able to replicate the security permissions locally so after publishing the site should not have any surprise issues that pop up.
I tried using the Default.aspx trick described here ASP.net MVC on IIS 7 returning blank page but the same problem only the root page gets displayed and no other routes are available.
I have also tried crating a empty route described here
routing to blank request in mvc asp.net using IIS 6.0
and here
I am getting a blank page while deploying MVC application on IIS
I am also using the Route debugger found here
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
Using the Route debugger when I visit http://localhost/ I still get a blank page with no data. But When I visit http://localhost/Home.aspx the route debugger then kicks in and displays the fallowing
http://j.imagehost.org/0476/routes.png
When I add
routes.MapRoute("Default2", "", new { controller = "Home", action = "Index" });
above or below the catchall route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // Parameter defaults
it does the same thing blank page when I visit http://localhost/ I still get a blank page with no data. And when I visit http://localhost/Home.aspx the route debugger kicks in and displays the fallowing
http://a.imagehost.org/0115/routes2.png
Is there anything else that I can try to get my pages to display properly? Seems like a lot of people are having the same issue but with iis6 classic or older mvc versions have have seen very few posts about people having blank page issue with my configuration of VS2010 asp.net mvc2 on window7 using iis7 integrated.
Any help is greatly apreciated!
"HTTP Errors" and "HTTP Redirection" services must be added to "Web Server (IIS) role. If you wan't to get static content like CSS and Javascript working, too, enable "Static Content" service as well.

mixed MVC routing for MVC app under web forms app

I have an instance of BlogEngine.net installed at the root of my hosted server. I wanted to play with ASP.Net MVC to write a small app and installed that app under a folder off the root.
I am able to see the http://example.com/testApp/ but the the routed pages like http://example.com/testApp/edit are giving 404's.
I have searched around and I'm just not clear what is needed to get the routing right. Do I need to set something in BlogEngine's web.config or do I need to be doing something in my applications settings?
The host is WinHost.com and it is IIS7
Edit/Update
So I understand that the http://example.com/testApp gets served because there is a default.aspx under that directory and that the routed pages don't get served because they don't have physical aspx's. The /edit gets routed to the edit view just fine when I launch it under Visual Studio.
I am guessing that the BlogEngine.net's global.asax is trying to map these pages to the BlogEngine world and not routing them to my testApp.
If that is the case then my question is how do I get BlogEngine to forward the requests to my testApp? I was hoping that I was missing something simple in the web.config because if I have to add stuff to BlogEngine's global.asax to do routing then won't I need to rebuild BlogEngine?
Based on the information I found in the MVC tutorial, I have discovered why my routing wasn't working.
My request processing mode on the hosted server was configured to use the Classic .NET AppPool not Integrated mode. To get it to work in classic mode you need to either modify the route table to use file extensions or create a wild card script map.
I was able to keep BlogEngine working using integrated mode so all that I needed to resolve this issue was to change the mode.
Hope this helps someone...
Do you have a Edit.aspx file existing in your application for your testApp controller? The way the default route works is:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
So by default, when you access Home/Index, ASP.NET MVC looks for Index.aspx
In your case, your routing consists of (I just made this up):
routes.MapRoute(
"CustomRoute", // Route name
"{controller}/{action}/{id}", // URL with parameters, id is optional.
new { controller = "testApp", action = "Edit", id = "" } // Parameter defaults
);
Where you are trying to use Edit.aspx
Inside of your Global.asax file is where all your custom routing exists, have you touched that file at all or no? The rule of thumb that I have heard about is that you want to write all the custom routing first prior to the default.
EDIT:
I also stumbled across this, might be helpful
There are four sections in the configuration file that are relevant to routing: the system.web.httpModules section, the system.web.httpHandlers section, the system.webserver.modules section, and the system.webserver.handlers section. Be careful not to delete these sections because without these sections routing will no longer work.
Taking from here
Good luck, hope this helps.

How do I set up a route for the home page of an ASP.NET MVC site?

I'm working with an ASP.NET MVC site which will use a CMS controller for all pages of the site except for the home page. Here's the idea:
Home controller:
www.site.com
www.site.com/default.aspx
CMS Controller:
www.site.com/about
www.site.com/agenda/schedule
www.site.com/monkey/eats/spaghetti
(pretty much anything else)
This page lists some options on how to set up a default page routing:
Leave Default.aspx unrouted and unredirected as the entry point to your application - with static links that take your users into the MVC portion of the app (or other static content).
Redirect Default.aspx in the code behind, either using the Page_Load event handler code, or use Response.Redirect("~/home") to send them to the Home controller (although this is a round-trip redirect).
Rename or delete Default.aspx. Despite the warning in the markup that says that default.aspx is required to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request... it's not actually needed in either the VS dev server, or IIS7. The default request will remain an application root request "/" and will be caught by the default route and sent to the home controller.
I guess one other option is to just use one controller with some logic that detects the home page case, but that seems to be fighting the concept.
How do you recommend setting up a specific route for the site home page?
www.site.com can be handled by an root map route
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
Put the following in page load of Default.aspx
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
This rewrites the request to root and handled by the map route above.
BTW, you can actually find the code from the MVC template project.
If hosting on IIS7 integrated mode, I suggest just getting rid of default.aspx. As I understand it, it's only necessary for activation on IIS6 and IIS7 classic mode.
I think option #1 is easiest. I probably will stick to it until finding a strong reason to move or finding the alternative. The default template uses this approach.
[UPDATE] Canton beat me to it

Resources