【问题标题】:ASP.NET 5 Template crashes on first runASP.NET 5 模板在首次运行时崩溃
【发布时间】:2016-03-25 01:18:59
【问题描述】:

我正在 VS 2015 中开始一个新项目。

文件 -> 新建 -> 项目 -> ASP.NET Web 应用程序 -> ASP.NET 5 模板 -> Web API

项目已初始化。我假设如果我使用 IIS Express 运行该项目,那么服务将可用。

它贯穿启动方法。

    public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        // Set up configuration sources.
        var builder = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; set; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseIISPlatformHandler();

        app.UseStaticFiles();

        app.UseMvc();
    }

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

}

但随后它崩溃了。我不知道如何实现全局错误处理。

我看了this example

但是当我尝试使用 System.Net.Http 或 System.Web.Http.ExceptionHandling 时找不到它们。

我还注意到,通过智能感知,它说 Core 5.0 不可用。

这是我要求的 project.json。

{  
   "version":"1.0.0-*",
   "compilationOptions":{  
      "emitEntryPoint":true
   },
   "dependencies":{  
      "Microsoft.AspNet.IISPlatformHandler":"1.0.0-rc1-final",
      "Microsoft.AspNet.Mvc":"6.0.0-rc1-final",
      "Microsoft.AspNet.Server.Kestrel":"1.0.0-rc1-final",
      "Microsoft.AspNet.StaticFiles":"1.0.0-rc1-final",
      "Microsoft.Extensions.Configuration.FileProviderExtensions":"1.0.0-rc1-final",
      "Microsoft.Extensions.Configuration.Json":"1.0.0-rc1-final",
      "Microsoft.Extensions.Logging":"1.0.0-rc1-final",
      "Microsoft.Extensions.Logging.Console":"1.0.0-rc1-final",
      "Microsoft.Extensions.Logging.Debug":"1.0.0-rc1-final"
   },
   "commands":{  
      "web":"Microsoft.AspNet.Server.Kestrel"
   },
   "frameworks":{  
      "dnx451":{  
         "frameworkAssemblies":{  
            "System.Web":"4.0.0.0"
         }
      },
      "dnxcore50":{  

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

【问题讨论】:

  • 你能分享你的project.json吗?你安装了dnvm 吗?并分享dnu build 命令输出。

标签: c# asp.net-web-api asp.net-core


【解决方案1】:

尝试打开 Visual Studio 管理员模式

【讨论】:

    【解决方案2】:

    我想这取决于什么是崩溃 - 从你的描述中不清楚什么崩溃,什么时候崩溃以及它是如何崩溃的。

    您可以使用UseExceptionHandlerUseDeveloperExceptionPage 扩展方法来配置错误处理页面。这个article 更详细地描述了它。 如果在启动期间发生异常,您可能需要使用UseCaptureStartupErrors 扩展方法(最近是renamedCaptureStartupErrors)。 此外,您已经启用了日志记录 - 日志也可能包含一些有用的信息。如果您因为登录到控制台而看不到日志,请考虑登录到文件。

    如果这是 IIS/IISExpress 崩溃检查事件日志。

    【讨论】:

    • 我喜欢你的想法,但是当我尝试使用 UseDeveloperExceptionPage 或任何其他方法时出现编译器错误。看来我缺少依赖项,我不知道如何诊断。 VNext 的依赖关系不同。我没有看到黄色感叹号。
    • 我查看了事件日志,但没有找到任何东西。我运行应用程序并让它崩溃,但事件日志中没有出现任何新内容。我查看了所有文件夹中最近发生的事件。
    • 要使用 UseDeveloperExceptionPage 你需要依赖Microsoft.AspNet.Diagnostics
    【解决方案3】:

    您的运行时版本是什么?

    也许您可以尝试使用AspNet Yeoman generator 构建您的应用程序并比较文件。 我个人更喜欢使用脚手架,因为它通常是最新的。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多