This invention relates to web applications, and more specifically to a framework that provides centralized code that can be accessed by multiple web applications.
ASP.NET provides a framework through which web-based applications may be developed. The ASP.NET framework includes a System.Web.HttpApplication class that provides a wide variety of functionality that can be accessed by ASP.NET applications. Each ASP.NET application includes a Global.asax file that may be used to define global code associated with the application, and/or to override or customize functions that are available through the System.Web.HttpApplication class.
While a Global.asax file supports application-specific code, the code associated with the System.Web.HttpApplication is part of the ASP.NET framework, and can not be modified by a developer. Therefore, if a developer wants to customize a particular function to be used in multiple applications, code duplication becomes a necessity. That is, the customized code can be added to each application's Global.asax file. This type of code duplication becomes difficult to maintain, for example, for a company that provides several web-based applications, all with a consistent look and feel. Accordingly, a need exists for a framework that enables developers to create centralized code that can be accessed by multiple ASP.NET web applications.
Techniques for enabling and maintaining code that may be accessed by multiple web-based applications are described. Rather than being duplicated and associated with multiple web-based application-specific classes, global code is maintained as part of a class associated with a web application framework. The web-based application-specific classes are then modified to inherit from the web application framework class.
a is a block diagram that illustrates source code examples for two web-based applications before implementation of a web application framework.
b is a block diagram that illustrates source code examples for the two web-based applications shown in
Overview
The embodiments described below provide a framework for enabling and maintaining centralized code that can be accessed by multiple web-based applications. In the described implementation, code that is to be shared across multiple web-based applications is stored in a web application framework. According to the current ASP.NET framework, the global class found in an application's Global.asax file is a descendent of the System.Web.HttpApplication class, which is part of the ASP.NET runtime environment. As such, by default, the global subclass inherits state and methods from the System.Web.HttpApplication class. In the described implementation, the global class is modified to inherit from a Microsoft.MsnTv.Web.WebGlobal class that is configured to inherit from the System.Web.HttpApplication class. As such, System.Web.HttpApplication methods can be overridden in the Microsoft.MsnTv.Web.WebGlobal class, which is then accessible by any web application that has a global class defined to inherit from the Microsoft.MsnTv.Web.WebGlobal class.
In a typical web-based application, code can be added to the global class to override or customize code that is in the System.Web.HttpApplication class. Similarly, when using the web application framework, code in the web application framework can override or customize code that is in the System.Web.HttpApplication class and code in the global class can override or customize code that is in the Microsoft.MsnTv.Web.WebGlobal class or code that is in the System.Web.HttpApplication class.
Network Environment
Client devices 104 may be implemented as any type of client device capable of accessing web-based applications over the Internet (or other type of network). Example client devices may include, but are not limited to, a personal computer, a handheld computing device, a personal digital assistant (PDA), a television set-top box, and so on.
Web server 102 includes one or more web-based applications 108(1), 108(2), . . . , 108(M), an ASP.NET framework 110, and a web application framework 112. In the illustrated example, web-based applications 108 are implemented using ASP.NET. As such, each web-based application 108 includes a Global.asax file 114(1), 114(2), . . . 114(M), which is an ASP.NET application requirement. By default, based on the ASP.NET framework, an application's Global.asax file includes a global class that inherits from an System.Web.HttpApplication class that is part of the ASP.NET framework 110.
Web application framework 112 may be implemented, for example, to include a webglobal class. The webglobal class is defined to inherit from the System.Web.HttpApplication class. Similar to a Global.asax file that inherits from the System.Web.HttpApplication class, the webglobal class can be used to override or customize code that is available through the System.Web.HttpApplication class. Furthermore, like an application-specific global class, the webglobal class can include additional code that is not available through the System.Web.HttpApplication class. The webglobal class may also include code that calls other code stored, for example, as a dynamic link library (DLL).
One or more of the web-based applications 114 can be modified to take advantage of code that is maintained in web application framework 112. For example, the global class in Global.asax file 114 can be modified to inherit from the webglobal class of web application framework 112 instead of from the System.Web.HttpApplication class of the ASP.NET framework. Because the webglobal class is defined to inherit from the System.Web.HttpApplication class, web-based application 108(1) will still have access to the code found in the System.Web.HttpApplication class of the ASP.NET framework, provided it has not been overridden by code in either the Global.asax file 114(1) or the global class of the web application framework 112.
Web server 102 may also include other components that are not illustrated in
Web application framework 112 includes webglobal class 210, which is defined to inherit from System.Web.HttpApplication class 202. Web-based application 212 also has a Global.asax file 214. Global.asax file 214 differs from Global.asax file 206 in that global class 216 is defined to inherit from webglobal class 210 rather than from System.Web.HttpApplication class 202. As such, custom code not available in the System.Web.HttpApplication class 202 can be maintained in the webglobal class 210 and accessed by web-based application 212. Similarly, web-based application 218 includes Global.asax file 220, which includes global class 222 defined to inherit from webglobal class 210. As such, web applications 212 and 218 can both take advantage of global code stored in the webglobal class 210.
Furthermore, another class similar to webglobal class 210 may be defined to support another group of applications. For example, webglobal class 210 may include code that applies to web-based applications 212 and 218 while a webgloball class (not shown) may be configured to also inherit from System.Web.HttpApplication class 202, but include code that applies to another group of web-based applications (not shown).
Exemplary Web Application Framework
a and 3b illustrate how the web application framework described herein can be used to reduce duplicate code across multiple web-based applications. Box 302 (shown in
Similarly, box 304 illustrates an example portion of code that may be included in a Global.asax file associated with a second web application (WebApplication2). The illustrated code sample indicates that the global class associated with WebApplication2 also includes a customized AuthenticateRequest method. The customized AuthenticateRequest method includes four commands (command1, command2, command3, and command4) in addition to the commands found in the System.Web.HttpApplication.authenticate method (not shown).
Boxes 306, 308, and 310 (shown in
Utilizing the Web Application Framework
At block 402, a developer creates a class associated with the web application framework (e.g., a webglobal class). The webglobal class is defined to inherit from the System.Web.HttpApplication class associated with the ASP.NET framework.
At block 404, the developer replaces the keyword “System.Web.HttpApplication” with the keyword “webglobal” in the application-specific Global.asax file. This will cause the ASP.NET runtime to look first to the webglobal class before looking to the System.Web.HttpApplication class for global code.
At block 406, code that is duplicated across multiple applications or code that the developer desires to make available to multiple applications is pulled out of the application-specific global class and added to the web application framework webglobal class.
Block 408 indicates that the modifications performed with respect to blocks 404 and 406 are repeated for each additional web-based application that is to be configured to utilize the web application framework.
Conclusion
The techniques described above provide a framework in which centralized code can be maintained and accessed by multiple web-based applications. Although the invention has been described in language specific to structural features and/or methodological steps, it is to be understood that the invention defined in the appended claims is not necessarily limited to the specific features or steps described. Rather, the specific features and steps are disclosed as preferred forms of implementing the claimed invention.