This should be a really, really simple one, I would assume. I’m throwing together a quick POC project in ASP.net — something I’ve done plenty of times before. But this time, for whatever reason, the default landing page (url=localhost:portnumber doesn’t show any content at all. However, requesting localhost:portnumber/home/index works fine. So it sounds like a route registering issue, but I didn’t mess with any of that code. This issue really doesn’t even matter, as it’s just a POC and I’m fine just manually redirecting, but I just wanted to get this one answered for curiosity’s sake.
Below is some relevant code:
From global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
and Index.cshtml for home is here, still with defaults for now:
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
and the index action of home controller (also left as default)
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
Edit: And here is _Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
<body>
<div class="page">
<header>
<div id="title">
<h1>My MVC Application</h1>
</div>
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
</div>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
</ul>
</nav>
</header>
<section id="main">
@RenderBody()
</section>
<footer>
</footer>
</div>
</body>
</html>
The weird thing is that almost everything is left totally default. So it seems like I could expect default behavior, right? I’m sure I’m just missing something silly, but this is frustrating me nonetheless.
Thanks in advance for the help.
Check your project’s web settings. Alt+Enter on project file. Set it to a specific page ‘Home’ and see if that fixes it. You might be on Current Page.