简体   繁体   English

MVC .Net Web应用程序-组合web.config和global.asax-或不使用web.config进行部署

[英]MVC .Net web app - Combine web.config and global.asax - or deploy without web.config

I have a MVC .NET application. 我有一个MVC .NET应用程序。 I thought I could deploy just web.config in the root folder. 我以为我可以只在根文件夹中部署web.config。 And of course also all the sub directories like VIEWS, etc. Oops. 当然还有所有子目录,例如VIEWS等。糟糕。 As soon as I copied the global.asax, it worked. 一旦我复制global.asax,它就起作用了。

Is it possible to combine the web.config and the global.asax ? 是否可以将web.config和global.asax结合在一起? Then I can only have a web.config in the root directory. 然后,我只能在根目录中有一个web.config。

Or, set up IIS differently ? 或者,以其他方式设置IIS? I am using IIS 7.5 我正在使用IIS 7.5

Is there ea way ? 有办法吗?

Thanks 谢谢

I'm not sure why you want to do that, but here is some explanation with the hope it will help you in your decision: 我不确定您为什么要这样做,但是这里有一些解释,希望对您的决定有所帮助:

web.config and the global.asax are completely two different things and have completely different rolls in ASP.Net applications. web.configglobal.asax是完全不同的两件事,它们在ASP.Net应用程序中的作用完全不同。

web.config , as the name suggests, provides the necessary configurations for the application. 顾名思义, web.config为应用程序提供了必要的配置。 It is required for the application to run. 运行该应用程序是必需的。

global.asax provides events to control the application (eg application_start , application_end , session_start , etc). global.asax提供事件来控制应用程序(例如application_startapplication_endsession_start等)。 It is not strictly required, so you don't have to include it unless you need the functionality. 并非严格要求它,因此除非需要功能,否则不必包括它。 MVC projects tend to have some code in global.asax , but it does not need to be that way. MVC项目倾向于在global.asax中包含一些代码,但是不必那样做。 Depending on you application's needs, you may be able to move all the code in global.asax to somewhere else and then remove the file completely. 根据您应用程序的需求,您可以将global.asax中的所有代码移至其他位置,然后将其完全删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM