我需要一个文件的Global.asax.cs在所有如果我使用的是OWIN Startup.cs类,并把所有的配置呢? [英] Do I need a Global.asax.cs file at all if I'm using an OWIN Startup.cs class and move all configuration there?

查看:2974
本文介绍了我需要一个文件的Global.asax.cs在所有如果我使用的是OWIN Startup.cs类,并把所有的配置呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让说,例如在一个全新的ASP.NET MVC应用程序5从MVCW¯¯做出/个人帐户的模板,如果我删除的Global.asax.cs 类移动它的配置code到 Startup.cs 配置()方法如下,有什么缺点?

Let's say for example in a brand new ASP.NET MVC 5 application made from the MVC w/ Individual Accounts template, if I delete the Global.asax.cs class and move it's configuration code to Startup.cs Configuration() method as follow, what are the downsides?

public partial class Startup
{
     public void Configuration(IAppBuilder app)
     {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        ConfigureAuth(app);
    }
}

对我有利的一面是,升级ASP.NET 4时应用ASP.NET 5和使用,现在必须在Startup.cs类配置块,我不这样做的依赖注入和其它配置在两个不同的类这似乎与启动和配置。

The upsides for me is that when upgrading ASP.NET 4 applications to ASP.NET 5 and using pieces that now must be configured in the Startup.cs class, I'm not doing dependency injection and other configuration in two different classes that seem related to starting up, and configuration.

推荐答案

Startup.Configuration被调用略晚的Application_Start,但我不认为差异在大多数情况下,很多重要。

Startup.Configuration gets called slightly later than Application_Start, but I don't think the difference will matter much in most cases.

我相信,我们一直在Global.asax中其他code的主要理由是:

I believe the major reasons we kept the other code in Global.asax are:


  1. 一致性与MVC的previous版本。 (这就是大家目前预计找到这个code)

  2. 能够添加其他的事件处理程序。在Global.asax中,你可以处理其他的方法,如在session_start和的Application_Error。

  3. 正确性在多种认证方案。如果你在你的bin目录中有Microsoft.Owin.Host.SystemWeb.dll的Startup.Configuration方法只调用。如果删除此DLL,它会悄悄地停止调用Startup.Configuration,这可能是很难理解的。

我觉得第三个原因是,我们没有采取默认这种做法,因为某些情况下不包括有这个DLL最重要的一条,这是很好的能够改变身份验证的方法,而不失效的位置,无关code(如路由注册)放置。

I think the third reason is the most important one we didn't take this approach by default, since some scenarios don't include having this DLL, and it's nice to be able to change authentication approaches without invalidating the location where unrelated code (like route registration) is placed.

但是,如果没有这些原因,在方案中应用,我想你会使用这种方法很好。

But if none of those reasons apply in your scenario, I think you'd be fine using this approach.

这篇关于我需要一个文件的Global.asax.cs在所有如果我使用的是OWIN Startup.cs类,并把所有的配置呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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