[英]Adding MVC to an empty ASP.NET 5 project in VS2015: Empty 500 Responses
I'm trying to create a minimal MVC6 (I guess MVC Core now?) project in Visual Studio 2015, by starting with an empty project and adding the MVC bits - I don't need a lot of the extra guff that's added as part of the "Web App" project, and I want to learn by doing, so am trying the following method. 我正在尝试在Visual Studio 2015中创建一个最小的MVC6(我猜MVC Core?)项目,从一个空项目开始并添加MVC位 - 我不需要添加很多额外的guff作为部分“Web App”项目,我想通过实践来学习,所以我尝试以下方法。 Unfortunately every request to this web app results in a 500 internal error response with no further details.
不幸的是,对此Web应用程序的每个请求都会导致500内部错误响应而无需进一步详细信息
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
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); }
public class HomeController : Controller { // GET: /<controller>/ public IActionResult Index() { return View(); } }
@{ Layout = "_Layout"; }
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>My Test App</title> </head> <body> <div> Testing </div> </body> </html>
@{ ViewBag.Title = "My Test App"; } <div>Testing</div>
But when I run this, I get a 500 Internal error response for every request, with no error messages or content that I can see to indicate what might be wrong? 但是当我运行这个时,我得到每个请求的500内部错误响应,没有错误消息或内容我可以看到表明可能出错的地方? Any ideas what may be wrong here?
任何想法在这里可能是错的?
Well, I have my answer to this. 好吧,我有我的答案。 I actually found it as I putting the finalising touchs on the question, so I thought I'd post them if anyone else has similar issues.
事实上,当我对问题进行最终确定时,我发现了它,所以如果其他人有类似的问题,我想我会发布它们。 It seems that if you forget to put a @RenderBody call in _Layout.cshtml, then you get a 500 internal error and nothing obvious that tells you what is wrong!
似乎如果你忘记在_Layout.cshtml中放置一个@RenderBody调用,那么你会得到一个500内部错误,没有任何明显的错误告诉你什么是错的! The fix was just to add the @RenderBody() to _Layout.cshtml:
修复只是将@RenderBody()添加到_Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>My Test App</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.