【发布时间】:2016-02-11 07:58:34
【问题描述】:
我正在尝试在 Visual Studio 2015 中创建一个最小的 MVC6(我猜是 MVC 核心?)项目,从一个空项目开始并添加 MVC 位 - 我不需要很多额外的花言巧语添加为“Web App”项目的一部分,我想边做边学,所以正在尝试以下方法。不幸的是,对这个 Web 应用程序的每个请求都会导致 500 内部错误响应,没有进一步的细节。
- 创建一个新的 ASP.NET 5 空 Web 项目。这从“Hello World!”开始。响应所有请求
- 将以下行添加到 project.json:
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
- 修改Startup.cs中的代码如下:
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // ADDED } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); // REMOVED // app.Run(async (context) => // { // await context.Response.WriteAsync("Hello World!"); // }); app.UseMvc(config => { config.MapRoute("Default", "{controller}/{action}/{id?}", new { controller = "Home", action = "Index" }); }); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); }
- 使用 HomeController.cs 添加一个 Controllers 文件夹:
public class HomeController : Controller { // GET: /<controller>/ public IActionResult Index() { return View(); } }
- 添加一个 Views 文件夹,根目录中包含 _Viewstart.cshtml:
@{ Layout = "_Layout"; }
- 使用 _Layout.cshtml 添加 Views/Shared 文件夹(我的实际应用是 angular2 应用,因此静态内容比这多得多)
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>My Test App</title> </head> <body> <div> Testing </div> </body> </html>
- 添加 Views/Home/Index.cshtml 的内容:
@{ ViewBag.Title = "My Test App"; } <div>Testing</div>
但是当我运行它时,我会为每个请求得到一个 500 内部错误响应,而我看不到任何错误消息或内容来指示可能有什么问题?任何想法这里可能有什么问题?
【问题讨论】:
标签: asp.net-mvc visual-studio-2015 asp.net-core