mixed MVC routing for MVC app under web forms app - asp.net-mvc

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.

Related

Running MVC application on IIS without domain

My application contains lots of links to the root ("/login/dologin"). When I'm running the application under a domain, there's no problem.
Right now I'm moving to a new server, and I can't test my application. My application sits in "localhost/md", I need the link to go to "localhost/md/login/dologin". Instead, it goes to "localhost/login/dologin", and, ofcourse, the resource cannot be found.
What do I need to configure on my IIS to make this works without domain?
Thanks.
It's just a guess, since you haven't posted any of your configuration.
In your authentication element in the web.config, do you have the route to the login page specified as /login/dologin? could you try ~/login/dologin
The second option, should give you a relative path from the home of the virtual directory application, rather than going to the root of the 'site'
For referencing files (e.g. javascript & css) you could do #Url.Content("~/path/to/file.js")
EDIT: Based on additional comments
in Layout.cshtml...
var SITE_ROOT = '#Url.Content("~/")'
then in your JS file use SITE_ROOT as a prefix in your routes
var url = SITE_ROOT + "Home/Index";

ASP.Net MVC Application cannot find home index page on the server

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.

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.

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