Creating custom headers and footers in Application level events using global.asax
2007-05-24 15:37
916 查看
Introduction
This is a very simple example that shows how to use global.asax file to create custom header and footers for all your pages.Background
Global.asax file contains a number of events that happens when any asp.net application is running. In this example I am using "Application_BeginRequest" and "Application_EndRequest" events to show how to create custom header and footers. Application_BeginRequest is getting fired whenever the asp.net page is getting a new request to handle. It happens before any page, web service, or any HTTP handler gets the opportunity to process the request. Therefore, I am using it to create my custom Header here. Application_EndRequest is getting fired whenever the request is complete. We can control the application response before handling the event to HTTP handlers. Therefore, I am using it to create my custom footer.Code
The code is very very simple. Therefore, I don't botter to include my test application. Basically, do the following steps: 1- Create a new asp.net application using c#. 2- Visual Studio creates the global.asax file for you. 3- Replace to code of Application_EndRequest and Application_StartRequest events as with the code bellow.protected void Application_BeginRequest(Object sender, EventArgs e) { Response.Write("<H1> Welcome to my website! </H1>" ); Response.Write(" This is my header that comes from Application level " ); Response.Write("<HR>"); } protected void Application_EndRequest(Object sender, EventArgs e) { int yearDate ; string dateStr; yearDate = System.DateTime.Now.Year; dateStr = yearDate.ToString(); Response.Write("<HR>"); Response.Write("Copyright 2002-" + dateStr ); Response.Write("This is my customer footer that from Application level" ); Response.Write("<HR>"); }
That is it. Of course don't forget to keep the layout of your form to "FlowLayout". Run it and you get the custom header and footer as the image above.However, nothing is stopping you of creating a very fancy header and footer and replacing my code.
相关文章推荐
- Creating custom headers and footers in Application level events using global.asax
- Automating Excel 2007 and creating charts using C++ MFC application in Visual Studio 2008
- custom control的使用方法(Creating and Using custom controls in VC++)
- Creating and Using custom controlsin VC++
- Using the Web Services and COM+ Event System in the .Net Application.
- Creating Custom Annotations and Using Them
- Add custom and listview web part to a page in wiki page using powershell
- Creating and Deleting Custom Menus in Visio
- How to load and generate a custom hierarchy in SAP Business Warehouse (SAP BW) without using flat files
- Creating CustomBinding for WCFBasicHTTP for SSL and BasicAuthentication in BizTalk 转载自:http://geekswithblogs.net/mipsen
- SQL Server Database Mirroring - Creating and using Mirror Endpoints in Principal, Mirror and Witness
- Debugging Memory Related Issues in .Net Application Using WinDBG and SOS
- Using Second Level Caching in a JPA Application
- Chapter 22: Using Item Renderers and Item Editors--Creating inline item renderers and editors
- Creating Custom Configuration Sections in Web.config Using .NET 2.0's Configuration API
- (极力推荐)BW:How to load and generate a custom hierarchy in SAP Business Warehouse (SAP BW) without using flat files
- Creating Vista Gadgets: Using HTML, CSS and JavaScript with Examples in RSS, Ajax, ActiveX (COM) and
- Creating and Using Your Own Delegates in Objective-C
- Creating and Using a New Content Type in SharePoint 2007(zhuan:http://www.sharepointproconnections.com/article/sharepoint-portal
- 4.9 Constructing Headers and Footers in Table Views