Accessing current page within a class -

mcneil used Ask the Experts™
I am trying to access the current page of this visitor in order to do a response.redirect from within a class. It looks like:

Imports System.Web.HttpContext
Public Class systemSecurity
    Inherits System.Web.UI.Page
    Public Sub checkSecurity(ByVal currentPage As String)
        If HttpContext.Current.Session("userLoggedOn") <> True Then 'prompt for login
        End If
    End Sub
End Class

Perhaps I'm approaching this in the wrong way.  I've had problems before with understanding the httpContext from within a class.  I guess I don't know how to phrase the problem, because I can't find anything on MSDN about issues like this.

Thanks for any help!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

I am not sure if we are in the same area here, but the page object has a user property.

if not Page.User.Isauthenticated then DoSomething()

You can set options in the web.config file on how you want to authenticate and authorize requests, and also what page to send people to to login.

There is a good example on in the tutorials section ubder the heading "building an end to end application"

I getthe feeling your trying something more complicated though...
simply deriving a class from Page does not mean that all the Page objects are instantiated. If you are creating a utility kind of class for your application, then you can get context of the call from anywhere by simply accessing HttpContext object. This context object is accessible from anywhere in the web application.

If you want to see what the current page is then you can check RawUrl property of Request object.


Is this waht you are looking for or something else?


I am looking for how to redirect from within the class.  Looks like httpcontext.current.response.redirect("somewhere.aspx") is what I'm looking for!  Thanks again naveenkohli!  You're a life saver!


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial