Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you use response object & sessions in .vb files? 1

Status
Not open for further replies.

meckeard

Programmer
Aug 17, 2001
619
US
What import do I need to use to be able to use response.redirect and read session variables within a class file (.vb)?

Thanks,
Mark
 
Use
System.Web.HttpContext.Current.Session
and
System.Web.HttpContext.Current.Response
to get a reference to the Session and Response objects form within a class.
 
LV,

VS says import cannot be found for either of them.

Any ideas?

Thanks.
 
Make sure you have a reference to System.Web for that project.
 
Here is the entire class file:

Imports Microsoft.VisualBasic
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Web.HttpBrowserCapabilities
Imports System.Web.HttpContext.Current.Session
Imports System.Web.HttpRequest
Imports System.Web.HttpResponse

Namespace CheckSession

Public Class CheckSession

Inherits System.ComponentModel.Component

Public Sub CheckUserSession()

If Session("UserID") = "" Then
Response.Redirect("")
End If

End Sub

End Class

End Namespace

It doens't like Imports System.Web.HttpContext.Current.Session.

Thanks.
 
Delete line Imports System.Web.HttpContext.Current.Session

If System.Web.HttpContext.Current.Session
("UserID").ToString = "" Then
System.Web.HttpContext.Current.Response.Redirect("myPage.aspx")
End If

Not sure though if it'll do a redirect from within the class, never tried that.
 
I just changed the function to return true or false and then redirect in the code-behind page.

It wasn't worth the extra time trying to figure out if it was possible.

Thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top