[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1441
  • Last Modified:

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

0
glit
Asked:
glit
  • 7
  • 5
  • 5
  • +2
4 Solutions
 
Alfred A.Commented:
Try the following:

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

Or,

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

0
 
glitAuthor Commented:
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")
0
 
Pratima PharandeCommented:
try

 Request.QueryString.Get("pid")
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
mayank_joshiCommented:
i think the problem is in the redirect which is landing on the above page.
can you show from where it is being redirected to the above page?
0
 
Alfred A.Commented:
if you are not getting anything from Request.QueryString("pid"), it means that there is no "pid" value inserted in the querystring.

Have you tried to capture the "pid" querystring through the content page itself rather than the master page?  I noticed that you are trying to get the querystring in the master page.  If for example, you are calling sample.aspx content page and execute it like this,

http://localhost/sample.aspx?pid=test123

In sample.aspx, page load, you could then do this

Dim pid As String = Request.QueryString("pid")  ''pid would be test123.
0
 
glitAuthor Commented:
the redirect occurs in the master page as well.
0
 
mayank_joshiCommented:
can you give an example of the complete url which the user will hit?
0
 
Alfred A.Commented:
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?

0
 
glitAuthor Commented:
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=
0
 
glitAuthor Commented:
obtaining pid and the redirect all occurs in the master page as shown in the code above
0
 
Alfred A.Commented:
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?
0
 
glitAuthor Commented:
its just a html link in an email that is sent to a user
0
 
Pratima PharandeCommented:
have you debug and check

Dim pid As String = HttpContext.Current.Request.QueryString("pid")


whether you are getting value here or not ?
0
 
glitAuthor Commented:
I have.  I am not getting anything.  

pid = NOTHING
0
 
mayank_joshiCommented:
have you written any code in page load of content page?

page load of content page fires before the page load of its master page.

0
 
Alfred A.Commented:
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.
0
 
mayank_joshiCommented:

1

gfgfdfdfgdf
njgh
jukhjh
0
 
mayank_joshiCommented:
sorry the last comment happened by mistake!
0
 
CodeCruiserCommented:
Did you try getting pid in the projectdetails.aspx page itself? Does it work?
0
 
glitAuthor Commented:
Thanks guys, I placed the code in the content page as well and it's all working now.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
  • 5
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now