在“/”应用程序asp.net的MVC 5中的服务器错误 [英] asp.net mvc 5 Server Error in '/' Application

查看:162
本文介绍了在“/”应用程序asp.net的MVC 5中的服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个asp.net mvc的5和Entity Framework现在,当我要运行这个项目中,我遇到丝毫样本项目这个错误:

在这里输入的形象描述

在我的电脑上安装了.NET 4.5和4.5.1和我的IIS版本8了。

这是我的控制器:

 使用系统;
使用System.Collections.Generic;
使用System.Data这;
使用System.Data.Entity的;
使用System.Linq的;
使用System.Net;
使用的System.Web;
使用System.Web.Mvc;
使用mvcWebApp01.Models;命名空间mvcWebApp01.Controllers
{
    公共类HomeControllers:控制器
    {
        私人DataBaseContext DB =新DataBaseContext();        // GET:HomeControllers
        公众的ActionResult指数()
        {
            返回查看(db.People.ToList());
        }        // GET:HomeControllers /详细资料/ 5
        公众的ActionResult详细信息(INT?ID)
        {
            如果(ID == NULL)
            {
                返回新的HTTPStatus codeResult(的HTTPStatus code.BadRequest);
            }
            人人= db.People.Find(ID);
            如果(人== NULL)
            {
                返回HttpNotFound();
            }
            返回查看(人);
        }        // GET:HomeControllers /创建
        公众的ActionResult的Create()
        {
            返回查看();
        }        // POST:HomeControllers /创建
        //从overposting攻击保护,请启用要绑定到特定的属性,
        //更多详情请参阅http://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        公众的ActionResult创建([绑定(包括=ID,全名)]人的人)
        {
            如果(ModelState.IsValid)
            {
                db.People.Add(人);
                db.SaveChanges();
                返回RedirectToAction(「指数」);
            }            返回查看(人);
        }        // GET:HomeControllers /编辑/ 5
        公众的ActionResult编辑(INT?ID)
        {
            如果(ID == NULL)
            {
                返回新的HTTPStatus codeResult(的HTTPStatus code.BadRequest);
            }
            人人= db.People.Find(ID);
            如果(人== NULL)
            {
                返回HttpNotFound();
            }
            返回查看(人);
        }        // POST:HomeControllers /编辑/ 5
        //从overposting攻击保护,请启用要绑定到特定的属性,
        //更多详情请参阅http://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        公众的ActionResult编辑([绑定(包括=ID,全名)]人的人)
        {
            如果(ModelState.IsValid)
            {
                db.Entry(人)= .STATE EntityState.Modified;
                db.SaveChanges();
                返回RedirectToAction(「指数」);
            }
            返回查看(人);
        }        // GET:HomeControllers /删除/ 5
        公众的ActionResult删除(INT?ID)
        {
            如果(ID == NULL)
            {
                返回新的HTTPStatus codeResult(的HTTPStatus code.BadRequest);
            }
            人人= db.People.Find(ID);
            如果(人== NULL)
            {
                返回HttpNotFound();
            }
            返回查看(人);
        }        // POST:HomeControllers /删除/ 5
        [HttpPost,ActionName(删除)]
        [ValidateAntiForgeryToken]
        公众的ActionResult DeleteConfirmed(INT ID)
        {
            人人= db.People.Find(ID);
            db.People.Remove(人);
            db.SaveChanges();
            返回RedirectToAction(「指数」);
        }        保护覆盖无效的Dispose(BOOL处置)
        {
            如果(处置)
            {
                db.Dispose();
            }
            base.Dispose(处置);
        }
    }
}


解决方案

ASP.NET遵循约定优于配置的方法。这意味着,例如,以实例化控制器,默认的控制器工厂将尝试寻找类的命名约定&LT以下;名称>控制器。如果你不喜欢这种方式,你可以编写自己的控制器厂(见这里为例),但总的来说这是没有必要的。

因此​​,要解决你的问题,你应该重新命名 HomeControllers 的HomeController

i create sample project with asp.net mvc 5 and entity framework now when i want to run this project i encounter whit this error :

in my computer is installed .net 4.5 and 4.5.1 and my iis version is 8 too.

this my controller :

    using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using mvcWebApp01.Models;

namespace mvcWebApp01.Controllers
{
    public class HomeControllers : Controller
    {
        private DataBaseContext db = new DataBaseContext();

        // GET: HomeControllers
        public ActionResult Index()
        {
            return View(db.People.ToList());
        }

        // GET: HomeControllers/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person person = db.People.Find(id);
            if (person == null)
            {
                return HttpNotFound();
            }
            return View(person);
        }

        // GET: HomeControllers/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: HomeControllers/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,FullName")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(person);
        }

        // GET: HomeControllers/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person person = db.People.Find(id);
            if (person == null)
            {
                return HttpNotFound();
            }
            return View(person);
        }

        // POST: HomeControllers/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "Id,FullName")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Entry(person).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(person);
        }

        // GET: HomeControllers/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person person = db.People.Find(id);
            if (person == null)
            {
                return HttpNotFound();
            }
            return View(person);
        }

        // POST: HomeControllers/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Person person = db.People.Find(id);
            db.People.Remove(person);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

解决方案

ASP.NET follows a "convention over configuration" approach. This means that, for instance, in order to instantiate your controllers, the default controller factory will try to look for classes following the naming convention <Name>Controller. If you don't like this approach you can write your own Controller Factory (see here for example), but in general this is not necessary.

So to fix your problem you should rename HomeControllers to HomeController.

这篇关于在“/”应用程序asp.net的MVC 5中的服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆