Default.aspx page in asp.net MVC - asp.net-mvc

What is the Default.aspx page for in an MVC app? Does this actually execute? Does this page have anything to do with the "Default" route in the global.asax?

If you take a look at the comments at the top of Default.aspx
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.
Basically, it acts as an override for the possibility of a different default page being loaded by IIS. In IIS6 if you have an index.html in the same directory as your MVC application, it can sometimes render that file instead of looking for the default blank route in your application. Default.aspx prevents that from happening.

Related

IIS Sub-application root

I have an existing Web Application hosted in IIS which an ASP.NET MVC application. Now I want to add a sub application,But when I deploy, some relative paths like "~/" or "/" will be imported back to my parent application.
Example:
The URL of the parent application is https://www.example.com/
Then my sub application is https://www.example.com/subApp/
When I try to click on the "subApp/test" page, it should be directed to https://www.example.com/subApp/test, but he still leads back to https://www.example.com/test.
How can I solve it?
Can it be modified through Web.Config instead of going to each page one by one
check your URL rewriting module. if it is there?

How do I get the site root to return the correct page w/ ASP.NET MVC + WebForms + ISS 6 Wildcard mapping?

Currently, I'm converting a web application from web forms to ASP.NET MVC. The project has been converted and IIS 6 is setup w/ wildcard mapping. I also have made one MVC view/controller that works just fine. There is one problem though. When accessing the the site root, the routing engine kicks in and redirects the user to the default controller, instead of the default page setup in IIS. Is there a way to have IIS use the default page, before the routing engine kicks in?
If not...
I have tried to have the default controller just redirect the user to the default page (LoginPage.aspx). That works except that web.config authorization seems to think that the path is not authorized, thus it redirects to path that looks like http://dev01/SampleWebApp/LoginPage.aspx?ReturnUrl=%2fSampleWebApp
If go to the default controller directly (http://dev01/SampleWebApp/default/) the user gets re-directed to the login page with the correct path.
So is there a way to get the site root to by pass web.config authorization and redirect to the login page w/o the ReturnUrl?
Any help is greatly appreciated.
Thanks,
Darren
at the top of the routes config in global.asax:
routes.IgnoreRoute("LoginPage.aspx");
or:
routes.IgnoreRoute("/");
haven't tried it, but one of those 2 options should work.
So the solution my problem was to use url mappings in the web.config under the system.web tag:
<urlMappings enabled="true">
<add url="~/" mappedUrl="~/LoginPage.aspx"/>
<add url="~" mappedUrl="~/LoginPage.aspx"/>
</urlMappings>
"~/" will re-direct the http://dev01/SampleWebApp/ path.
"~" will re-direct the http://dev01/SampleWebApp path.

ASP.NET MVC app not browsing to pages only Index.aspx on root

I have an MVC 1.0 app just setup but it only shows the Index.aspx page
of Home.
Seems like the routing engine is not being engaged.
I get a 404 error when i try to browse other pages.
Any ideas why this might be?
Malcolm
It's probably that the ASP.NET DLL isn't being called for your request. If you are talking about IIS, Phil Haack has a great article on how to sort it out. Note: Scroll down for .* version :)
Essentially, you are telling IIS that for every extension, it should look use the .NET DLL to run it, but don't check to see if the file exists first (because in MVC, the files don't exist).

asp.net MVC routeengine doesn't kick in

i'm having a bit of a weird problem.
I programmed a asp.net mvc app and runned locally at http://localhost:1234/ it works fine.
i have a route for /employee and this route kicks in.
But when i move it to my webserver at http://myapp.mydomain.nl (it is at a subdomain 'myapp') the /employee route doesn't kick in (i get a 404).
i have installed the RouteDebug.RouteDebugger component and normally it shows you the yellow and white page to show you which route kicks in, and if you type an invalid uri you see that no route kicks in. But now it doesn't show me this page, but just a 404, so it looks that the mvc doesn't 'kick in' when i navigate to http://myapp.mydomain.nl/employee, but my server treats my request as a normal request so it loos for the nonexisting folder 'employee'.
It is on a server that has not the mvc framework installed so i manually copied the System.Web.Mvc.dll to the bin folder.
Michel
You will need ASP.NET MVC installed and also setup the wildcard mappings to be able to view MVC routes properly (if using IIS5/6).
Here's a link to setting up ASP.NET MVC with IIS 5 and 6.
http://blogs.microsoft.co.il/blogs/dorony/archive/2007/12/15/using-asp-net-mvc-on-iis-5.aspx
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

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