简体   繁体   English

学习ASP.Net MVC并在'/'应用程序中构建用户管理器服务器错误

[英]Learning ASP.Net MVC and building a user manager Server Error in '/' Application

For one of my classes I'm just getting started in learning how to develop web applications in ASP.Net MVC5. 对于我的一个课程,我刚开始学习如何在ASP.Net MVC5中开发Web应用程序。 One of the things we're required to do is redesign the view of a simple user account manager, with the code already given to us to work with and modify. 我们需要做的一件事是重新设计一个简单的用户帐户管理器的视图,已经提供给我们的代码可以使用和修改。

The problem is, when I actually run the code in Visual Studio, I get 404 error that says Server Error in '/' Application . 问题是,当我在Visual Studio中实际运行代码时,我得到404错误, Server Error in '/' Application

I'm fairly certain the code worked when it was presented in the classroom, but I can't get it to work here. 我相当肯定代码在课堂上呈现时有效,但我不能在这里工作。

Here's the sample code, for those interested: 以下是感兴趣的示例代码:

UserManagerController.cs UserManagerController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CS610W6.Controllers
{
    public class UserManagerController : Controller
    {
        //
        // GET: /UserManager/
        public ActionResult Index()
        {
            //Use the application's DB context to access the Identity framework's users
            var UserList = new CS610W6.Models.ApplicationDbContext().Users.ToList();

            //Pass the UserList to the view
            return View(UserList);
        }
    }
 }

index.cshtml index.cshtml

@model List<CS610W6.Models.ApplicationUser>
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
@foreach (var item in Model)
{
    @item.UserName<br />
    @item.PasswordHash<br />
    @item.Id<br />
    @Html.ActionLink("Edit", "Edit", new { id = item.Id })
}

EDIT: Here is the full text of the error, as shown in the browser, 编辑:这是错误的全文,如浏览器中所示,

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. 说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。 Please review the following URL and make sure that it is spelled correctly. 请查看以下网址,确保拼写正确。

Requested URL: /Views/index.cshtml 请求的URL:/Views/index.cshtml

Version Information: Microsoft .NET Framework Version:4.0.30319; 版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET Version:4.0.30319.34274 ASP.NET版本:4.0.30319.34274

As you're new to MVC, I assume you get this error when you try to run your application at very first time. 由于您是MVC的新手,我假设您在第一次尝试运行应用程序时遇到此错误。

As we can see in your error, requested URL is /Views/index.cshtml . 正如我们在您的错误中看到的,请求的URL是/Views/index.cshtml

This error simply means, application cannot found any route. 这个错误只是意味着,应用程序找不到任何路由。 You can either check with URL yourdomain/UserManager/Index 您可以使用URL yourdomain/UserManager/Index进行检查

Or you can set default action to make change in RouteConfig 或者您可以设置默认操作以在RouteConfig进行更改

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "UserManager", action = "Index", id = UrlParameter.Optional }
            );

Here is also a good document for ASP.NET Routing 这也是ASP.NET Routing的一个很好的文档

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM