Link to home
Start Free TrialLog in
Avatar of glit
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 -
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

Open in new window

Avatar of Alfred A.
Alfred A.
Flag of Australia image

Try the following:

 Response.Redirect("~/login.aspx?err=1&pid=" & pid)

Or,

 Response.Redirect(ResolveUrl("~/login.aspx?err=1&pid=" & pid), True)

Avatar of glit
glit

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.Request.QueryString("pid")

I have also tried -

Dim pid As String = Request.QueryString("pid")
Avatar of Pratima
try

 Request.QueryString.Get("pid")
ASKER CERTIFIED SOLUTION
Avatar of mayank_joshi
mayank_joshi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of glit

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("WebForm2.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?

Avatar of glit

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=
Avatar of glit

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?
Avatar of glit

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.Request.QueryString("pid")


whether you are getting value here or not ?
Avatar of glit

ASKER

I have.  I am not getting anything.  

pid = NOTHING
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

1

gfgfdfdfgdf
njgh
jukhjh
sorry the last comment happened by mistake!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of glit

ASKER

Thanks guys, I placed the code in the content page as well and it's all working now.