How to use global. asax in ASP. net2.0

Source: Internet
Author: User


global. asax in Visual Studio 2005

In Visual Studio 2003, the global. asax consisted of two files: Global. asax (design-time html) and global. asax. XX (language-specific code-behind ). the class was also named global by default and cocould be referenced accordingly througout the application. since global. asax was an incarnation of httpapplication at runtime, I added application-level properties and methods to the global class. the global. asax in Visual Studio 2005, however, is much different by default. when adding a new 'Global application class' to your project, you'll get the global. asax, but no code-behind. this really isn't a big deal because vs2005 has intelliisense in the design-time HTML files now, but there are still differences. I want to describe some of those differences here for those that are used to global. asax circa vs2002/2003. designer viewglobal. asax seems to no longer have a designer view. with this view, you cocould drag items from Server Explorer, such as Event Log, into your project. I never really used this feature, so that's all I 've got to say about that. importing namespacesi began coding global. asax as I had always done in global. asax. CS (C # Is my language of choice), but the using statement for importing namespaces caused a compile error. instead you have to use the @ import directive: <% @ import namespace = "system. workflow. runtime "%> // an error occurs when this entry is added. I wonder if the version is different. Article A little old global class nameI suppose global. asax wocould get compiled into an anonymously named class, but I cocould not find a class reference that contained the properties/methods I had coded. at this point, I began searching for a better solution to my need for a global class. my first solution was to create a new class, global. asax. CS (in the app_code folder ). I then made this file the code-behind for global. asax with the codebehind attribute of the @ application directive: <% @ application language = "C #" codebehind = "Global. asax. CS "%> this worked out OK, but something still didn't feel right. the global class (in global. asax. CS) inherits system. object, but the global. asax still functioned as an instance of httpapplication because code in application_start and application_end wocould run accordingly. my second and final attempt normalized the class hierarchy between these two files. in global. asax. CS, I changed the global class to inherit httpapplication. I then replaced the codebehind attribute of the @ application directive in global. asax with the inherits attribute: <% @ application language = "C #" inherits = "Global" %> // codebehind = "Global. asax. CS "and inherits =" Global "should be put together now the class hierarchy matched the usage and I had the familiar global class to program against.

posted @ Monday, November 14,200 am

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.