Force all Areas to use same Layout

You just have to add a file named: _ViewStart.cshtml Under each area views folder: /Areas/Area1/Views/_ViewStart.cshtml And edit the file to point to the root layout like this: @{ Layout = “~/Views/Shared/_Layout.cshtml”; } In order for this to work, you do not have to specify a value in the view’s layout property, if you do, you … Read more

How do you request static .html files under the ~/Views folder in ASP.NET MVC?

I want to be able to request static .html files which are located in the ‘~/Views’ folder. You can’t. There’s a web.config file in this folder which explicitly forbids accessing any file from it. If you want to be able to access files from the client those files should not be placed in the Views … Read more

Set “Homepage” in Asp.Net MVC

Look at the Default.aspx/Default.aspx.cs and the Global.asax.cs You can set up a default route: routes.MapRoute( “Default”, // Route name “”, // URL with parameters new { controller = “Home”, action = “Index”} // Parameter defaults ); Just change the Controller/Action names to your desired default. That should be the last route in the Routing Table.

Routing for custom ASP.NET MVC 404 Error page

I’ve tried to enable custom errors on production server for 3 hours, seems I found final solution how to do this in ASP.NET MVC without any routes. To enable custom errors in ASP.NET MVC application we need (IIS 7+): Configure custom pages in web config under system.web section: <customErrors mode=”RemoteOnly” defaultRedirect=”~/error”> <error statusCode=”404″ redirect=”~/error/Error404″ /> … Read more

ASP.NET MVC ambiguous action methods

MVC doesn’t support method overloading based solely on signature, so this will fail: public ActionResult MyMethod(int someInt) { /* … */ } public ActionResult MyMethod(string someString) { /* … */ } However, it does support method overloading based on attribute: [RequireRequestValue(“someInt”)] public ActionResult MyMethod(int someInt) { /* … */ } [RequireRequestValue(“someString”)] public ActionResult MyMethod(string someString) … Read more

Is it possible to make an ASP.NET MVC route based on a subdomain?

You can do it by creating a new route and adding it to the routes collection in RegisterRoutes in your global.asax. Below is a very simple example of a custom Route: public class ExampleRoute : RouteBase { public override RouteData GetRouteData(HttpContextBase httpContext) { var url = httpContext.Request.Headers[“HOST”]; var index = url.IndexOf(“.”); if (index < 0) … Read more