I have a global header and footer that has a Database connection and a disconnection in the header and footer and need to convert this to ASP.NET – this needs to be done before any HTML is output and after any HTML is output for the footer.
I cannot seem to find any easy way to do this, like in Classic ASP – if possible post an example or link to one instead of stating a given technique, thanks.
A bit more detail is that I have an SQL Connection string then a single SQL object I want to use throughout all the pages on the website – with the connection string and declarations in the header, and the disconnection in the footer.
Your use of the terms Header and Footer leads many to believe you actually intend to create HTML that forms a visible header and footer in the output. Hence the number of references to Master pages in the answers.
However I’m going to guess in a different direction. You have a classic ASP page which includes inline code from an include file, then sequentially the body in the main ASP page uses stuff created in the include, then there is final include file at the bottom which tidies up stuff created in the first include.
In ASP.NET you can’t treat the content of the page as if it were a purely sequential script as you could in ASP. If you really must you could confgure stuff in the
Page_Loadevent then tidy up inPage_Unload.Do you really want to port the app without re-engineering it?. I can see little to gain by trying to copy the infrastructure of an old ASP app in ASP.NET. The goal surely is to deliver the same UI and functions (or better) to the client using ASP.NET in the way ASP.NET was intended to be used. This gives you a platform to move forward rather than create a strange looking ASP.NET app which starts life already a legacy piece of code.