Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Redirecting to another page

Hi,

I have a development server which has a virtual path "http://localhost/proj1" as root, and there is another testing server which as virtual path as "http://localhost/sys/proj1". The difference is that the "proj1" is put under the "/sys" in testing server while it is not exist in the development server.

In order to aviod changing the path info of links in every web page, says from "http://localhost/proj1/form1.aspx" to ""http://localhost/sys/proj1/form1.aspx" , I write a public shared function in a class object, says CmnObj, which could be called by all web pages. The function look like this:

Public Shared Function Redirect(ByVal WebLink As String) As Boolean
Dim Request As System.Web.HttpRequest
Dim ServerLink As String = Request.path
ServerLink = ServerLink & "/" & WebLink
System.Web.HttpContext.Current.Server.Transfer(ServerLink)
End Function

In the web form, it calls the function like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CmnObj.Functions.Redirect("webform2.aspx")
End Sub

However, when executing the function, it always return me with "Nothing" in the variable "Request", so it will fail to get the Request.Path value. Could anyone give me some hints? Thank you.
[1376 byte] By [THL] at [2007-11-11 7:38:59]
# 1 Re: Redirecting to another page
Try defining Request as the following:

Dim Request As System.Web.HttpRequest = System.Web.HttpContext.Current.Request
pclement at 2007-11-11 23:13:43 >