redirect in global.asax

  • Thread starter Thread starter george d lake
  • Start date Start date
G

george d lake

Hi,
I know I cant redirect in the global.asax. I need to count how many
users are connected to my intranet site, and once I reach a given number, I
need to redirect to an error page. Can I do this form the Global.asax? or do
I have to add the session var there and then redirect on each page? (or add
a user control to each page that does the check and redirect)
 
Hi george,

What you can do is to create an Application-level variable in your
Application_OnStart, increment it in the Session_OnStart, and decrement it
in the Session_OnEnd. Then you can access that Application-level variable
from any page and do your redirect from the page. If you want to get really
OOP and efficient about it, create a custom Page class that inherits
System.Web.UI.Page, and add the code to check for the value of the variable
(and redirect if necessary) in that class. Then inherit that class in all of
your pages.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
mmmmm
That is one thing I have never been able to get to work. (creating a class
that I can inherit in a page)
Could you explain that? or point me to a site that has a good example?
 
Not much to it. In C#:

public class MyPage : System.Web.UI.Page

In VB.Net

Public Class MyPage
Inherits System.Web.UI.Page

Then you can inherit that class instead of System.Web.UI.Page (in your
CodeBehind class definition). It will have all the aspects of the Page
class, plus any additional aspects that you add.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top