Tuesday, December 21, 2010

Call an aspx page from a vb class

Re: How to call an aspx page from a vb class?
You can pass the Request and Response objects from the ASPX page into the DLL. Then your DLL can use those objects.
Code:
Public Class MyWebHelper
Private m_Server As HttpServerUtility = Nothing
Private m_Request As HttpRequest = Nothing
Private m_Response As HttpResponse = Nothing

Public Sub New(server As HttpServerUtility, request As HttpRequest, response As HttpResponse)
m_Server = server
m_Request = request
m_Response = response
End Sub

Public Sub RedirectToLogin()
m_Response.Redirect("mylogin.aspx")
End Sub
End Class
In ASPX class:
Code:
Private Sub Page_Load(...)
If (Not IsLoggedIn) Then
Dim hlpr As New MyWebHelper(Server, Request, Response)
hlpr.RedirectToLogin()
End
End Sub

Private Function IsLoggedIn() As Boolean
' validate user
End Function
__________________
Good Luck,
-Cool Bizs

[Check out my free software site: Tutorials Hut]

#5
May 24th, 2005, 08:23 PM
subdigital
Member

Join Date: Jan 2004
Location: Houston
Posts: 54

Re: How to call an aspx page from a vb class?
no, that is completetly unnecessary.

If you can be sure that the code will be running withing a web request (ie, this class/method will not be used by any win forms code) then you can ALWAYS get access to the current request by doing this:

Code:
System.Web.HttpContext.Current
This will give you access to the Request/Response objects, as well as Session, Application, and cookies.

No comments:

Post a Comment