glit
asked on
Request.QueryString not working in master page
My program uses a master page and also has a login.
If a user attempts to open a certain project via a URL link which includes the project id (pid) in the query string and they are not logged in, they will be redirected to the login page. What I want is for the user to then be able to login and then be taken to the page initially requested.
The only problem I am having is that I cannot seem to obtain the part of the query string that I need from when the user enters the URL.
The code I am using is below -
If a user attempts to open a certain project via a URL link which includes the project id (pid) in the query string and they are not logged in, they will be redirected to the login page. What I want is for the user to then be able to login and then be taken to the page initially requested.
The only problem I am having is that I cannot seem to obtain the part of the query string that I need from when the user enters the URL.
The code I am using is below -
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim pid As String = HttpContext.Current.Request.QueryString("pid")
If Session("AccessGranted") = True Then
ASPxMenu1.Visible = True
FullNameLabel.Text = Session("FullName")
FullNameLabel.Visible = True
WelcomeLabel.Visible = True
LogOffASPxButton.Visible = True
Else
ASPxMenu1.Visible = False
FullNameLabel.Visible = False
WelcomeLabel.Visible = False
LogOffASPxButton.Visible = False
End If
If (Session("AccessGranted") = False) And Page.GetType().Name <> "login_aspx" Then
Response.Redirect("~\login.aspx?err=1&pid=" & pid)
End If
End Sub
ASKER
Thanks although none of them worked.
It seems as if the following line is not picking up the pid correctly and a blank instead -
Dim pid As String = HttpContext.Current.Reques t.QueryStr ing("pid")
I have also tried -
Dim pid As String = Request.QueryString("pid")
It seems as if the following line is not picking up the pid correctly and a blank instead -
Dim pid As String = HttpContext.Current.Reques
I have also tried -
Dim pid As String = Request.QueryString("pid")
try
Request.QueryString.Get("p id")
Request.QueryString.Get("p
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the redirect occurs in the master page as well.
can you give an example of the complete url which the user will hit?
OK. How do you populate the value of "pid" in the first place. I tried multiple combinations of sending the following test redirect:
Response.Redirect("WebForm 2.aspx?pid =test123")
and capture the value in WebForm2.aspx in page load using
Dim pid As String = Request.QueryString("pid")
and it works perfectly. I tried it in a Master Page (Site.Master) Page Load being used by Content Page WebForm1.aspx and tried it as well using WebForm1.aspx.cs Page Load to redirect to WebForm2.aspx. Everything works.
So, how do you populate your value of "pid"? Can you provide additional code snippet to see how you do it?
Response.Redirect("WebForm
and capture the value in WebForm2.aspx in page load using
Dim pid As String = Request.QueryString("pid")
and it works perfectly. I tried it in a Master Page (Site.Master) Page Load being used by Content Page WebForm1.aspx and tried it as well using WebForm1.aspx.cs Page Load to redirect to WebForm2.aspx. Everything works.
So, how do you populate your value of "pid"? Can you provide additional code snippet to see how you do it?
ASKER
The user will attempt to hit this -
https://projects.mywebsite.com.au/projects/projectdetails.aspx?pid=2862
If they are not logged in it will redirect them to the login page which should be this -
https://projects.mywebsite.com.au/projects/login.aspx?err=1&pid=2862
But instead it is this -
https://projects.mywebsite.com.au/projects/login.aspx?err=1&pid=
https://projects.mywebsite.com.au/projects/projectdetails.aspx?pid=2862
If they are not logged in it will redirect them to the login page which should be this -
https://projects.mywebsite.com.au/projects/login.aspx?err=1&pid=2862
But instead it is this -
https://projects.mywebsite.com.au/projects/login.aspx?err=1&pid=
ASKER
obtaining pid and the redirect all occurs in the master page as shown in the code above
When the user hit the first link, are you using an HTML anchor tag or are you using an ASP.NET Control such as a HyperLink or LinkButton? Have you tried to capture the QueryString pid value using one of the events of the control if it is an ASP.NET control?
ASKER
its just a html link in an email that is sent to a user
have you debug and check
Dim pid As String = HttpContext.Current.Reques t.QueryStr ing("pid")
whether you are getting value here or not ?
Dim pid As String = HttpContext.Current.Reques
whether you are getting value here or not ?
ASKER
I have. I am not getting anything.
pid = NOTHING
pid = NOTHING
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK. I tried to reproduce it. I setup a html link in an email automatically and send the email to myself. Click on the url link with PID information in it. Captured it in my test website and voila! I got the PID displayed in another page using a Response.Redirect.
Note: I used http rather than https. The secured site must have something to do with the pid value missing.
Note: I used http rather than https. The secured site must have something to do with the pid value missing.
1
gfgfdfdfgdfnjgh
jukhjh
sorry the last comment happened by mistake!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys, I placed the code in the content page as well and it's all working now.
Response.Redirect("~/login
Or,
Response.Redirect(ResolveU