空白应用程序上的MVC 6 HTTP 500错误

时间:2016-01-11 11:44:30

标签: c# asp.net-mvc asp.net-core-mvc

我正在尝试关注this教程。

我已经到了添加HomeController.cs和相应Index.cshtml的步骤。当我运行应用程序时,它只会加载一个空白页面,它会点击HomeController上的索引操作并返回视图。如果我看一下我得到的Http请求:

  

HTTP / 1.1 500内部服务器错误

我似乎无法找出原因。

Startup.cs

public class Startup
{
        public Startup(IHostingEnvironment env)
        {

        }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }   


        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UseIISPlatformHandler();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

        // Entry point for the application.
        public static void Main(string[] args) => WebApplication.Run<Startup>(args);
    }

project.json

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",

  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Microsoft.Web.Administration": "7.0.0.0"
      }
    },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ],

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

更新

这是我得到的例外:

  

处理请求时发生未处理的异常。

     

InvalidOperationException:无法解析类型&#39; Microsoft.Dnx.Compilation.ILibraryExporter&#39;的服务。在尝试激活Microsoft.AspNet.Mvc.Razor.Compilation.RoslynCompilationService&#39;时。   Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider,ISet`1 callSiteChain,ParameterInfo [] parameters,Boolean throwIfCallSiteNotFound)

2 个答案:

答案 0 :(得分:0)

根据例外情况在github中查看此问题https://github.com/aspnet/Home/issues/515看起来您可能没有在dnx中运行相同的project.json版本,运行dnvm list并检查project.json中使用的版本是否相同,如果不是同一次运行dnvm use 1.0.0-rc1-final

答案 1 :(得分:0)

我有类似的问题。在我的情况下,我的Index.cshtml文件是错误的。 我有

@{Hello there !!!} 

而不是

@{}Hello there !!!

您的问题可能完全不同。你在使用布局文件吗?