Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a code run on all aspx pages?

Tags:

c#

asp.net

I need to create a code that reads the QueryString and set a value on the Session and on the end of the page I need to clear the Session.

How can I make a code like this to run on all .aspx pages?

like image 341
BrunoLM Avatar asked Nov 27 '25 16:11

BrunoLM


2 Answers

Two possibilities are:

  • Create a class that inherits from System.Web.UI.Page. Insert your code there and all your pages inherit from that class instead of System.Web.UI.Page.
  • Create a HttpModule
like image 68
citronas Avatar answered Nov 29 '25 05:11

citronas


well as i see it you got 2 solutions

  1. Use a master page and do it there

  2. Inherit Page and use that as base class on all your pages

One question why must it be stored in a session? this will give your problems if the same user executes 2 pages at the same time (the first to finish will clear the sesson for the other page)

if you only need the data while the page runs you can just save it in a normal variable, else use the viewState!

like image 31
Peter Avatar answered Nov 29 '25 04:11

Peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!