2013-11-25 104 views
0

这是我的主屏幕:Visual Studio中:在“/” Application.The资源服务器错误无法找到

enter image description here

当我打的Log On右侧,我达到这个:

Server Error in '/' Application. 

The resource cannot be found. 

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /HelloWorld/LogOn 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929 

这是我的项目在Visual Studio 2012的层次结构:

enter image description here

这是_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>Welcome to our MVC Movies Application     
       </h1>    
      </div> 
      <div id="logindisplay"> 
       <!-- My TEST Comment --> 
       <!-- 
        From here we go into to log-on page , furthermore if the user is 
        not listed , then we go straight into registration 
        --> 
       [ <a href="/HelloWorld/LogOn">Log On</a> ] @*This is just a non-working stub that would be changed later on*@ 
      </div> 
      <nav> 
       <ul id="menu"> 
        <!-- format is as follows 
         [the name of the presented tab] 
         [the name of the file in the Search Solution] 
         [the folder in Search Solution where the file above is located] 
         --> 
        <li>@Html.ActionLink("Home Tab", "Index", "Movies")</li> 
        <li>@Html.ActionLink("Search Tab", "SearchIndex", "Movies")</li> 
        <li>@Html.ActionLink("Hello World Tab", "Index", "HelloWorld")</li> 
       </ul> 
      </nav> 
     </header> 
     <section id="main"> 
      @RenderBody() 
     </section> 
     <footer> 
     </footer> 
    </div> 
</body> 
</html> 

这是LogOn.cshtml内容:

@model Mvc3ToolsUpdateWeb_Default.Models.LogOnModel 

@{ 
    ViewBag.Title = "LogOn"; 
} 

<h2>Log On</h2> 
<p> 
    Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don't have an account. 
</p> 

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> 
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") 

@using (Html.BeginForm()) { 
    <div> 
     <fieldset> 
      <legend>Account Information</legend> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.UserName) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.UserName) 
       @Html.ValidationMessageFor(m => m.UserName) 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.Password) 
      </div> 
      <div class="editor-field"> 
       @Html.PasswordFor(m => m.Password) 
       @Html.ValidationMessageFor(m => m.Password) 
      </div> 

      <div class="editor-label"> 
       @Html.CheckBoxFor(m => m.RememberMe) 
       @Html.LabelFor(m => m.RememberMe) 
      </div> 

      <p> 
       <input type="submit" value="Log On" /> 
      </p> 
     </fieldset> 
    </div> 
} 

任何想法,我究竟错在这里做什么?什么导致404?

我想这东西是错误的布局文件的路径:

<a href="/HelloWorld/LogOn">Log On</a> 

非常感谢

编辑:

HelloWorldController.cs:

using System.Web; 
using System.Web.Mvc; 

namespace MvcMovie.Controllers { 
    public class HelloWorldController : Controller { 
     public ActionResult Index() { 
      return View(); 
     } 

     public ActionResult Welcome(string name, int numTimes = 1) { 
      ViewBag.Message = "Hello " + name; 
      ViewBag.NumTimes = numTimes; 

      return View(); 
     } 
    } 
} 
+0

你有一个'HelloWorldController'和一个名为'LogOn'的方法吗? – CodeCaster

+0

@CodeCaster:我有控制器,但没有方法。我在帖子中编辑了代码。 – ron

+0

既然你打电话给'/ HelloWorld/LogOn',你必须。你确定'LogOn'需要这个路径,或者你可以改变它指向实际上包含'LogOn'方法的控制器吗? – CodeCaster

回答

1

你需要添加这个...

using System.Web; 
using System.Web.Mvc; 

namespace MvcMovie.Controllers 
{ 
    public class HelloWorldController : Controller 
    { 
     public ActionResult Index() 
     { 
      return View(); 
     } 

     public ActionResult Welcome(string name, int numTimes = 1) 
     { 
      ViewBag.Message = "Hello " + name; 
      ViewBag.NumTimes = numTimes; 

      return View(); 
     } 

     [AllowAnonymous] 
     public ActionResult LogOn(string returnUrl) 
     { 
      ViewBag.ReturnUrl = returnUrl; 
      return View(); 
     } 

     // 
     // POST: /Account/Login 

     [HttpPost] 
     [AllowAnonymous] 
     [ValidateAntiForgeryToken] 
     public ActionResult LogOn(LoginModel model, string returnUrl) 
     { 
      if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) 
      { 
       return RedirectToLocal(returnUrl); 
      } 

      // If we got this far, something failed, redisplay form 
      ModelState.AddModelError("", "The user name or password provided is incorrect."); 
      return View(model); 
     } 
    } 
} 

你需要一个动作做显示登录页面(如果需要),而另一种在用户凭据。

编辑:我添加了新的MVC项目的默认Login行动。

0

改为使用./HelloWorld../。很多时候,服务器不会接受/HelloWorld

+0

这与'/'是否是某种形式的根路径有关? – jozxyqk

0

我猜你正在使用Visual Studio Development Server。您可以在Solution Explorer中的解决方案名称下右键单击您的项目。在那里,你可以选择IIS Express。

相关问题