views:

42

answers:

3

My client wants to pass values through the query string, but they don't want the query string to be displayed in the browser's address bar. The values being passed are for tracking purposes. I know that postback doesn't happen after you click on href link.

Is there any way I can get the value out of the query string without displaying it in the browser's address bar? I think this may be impossible, but I may be wrong; I'm hoping to see if anyone has any answers.

A: 

No, if it's in the query string, it will be visible to the end user via the address bar. That's standard behavior for HTTP GET requests.

If you are using WebForms, look into the LinkButton control. This will perform an actual postback, which is a POST operation. You'll respond to the LinkButton's OnClick event in your .NET code-behind, and you're pretty much set to go.

John Rudy
A: 

It sounds like you need to store a string in a place other than the querystring. How about using state management for this, for example, storing this value in session, that way it will be available to you in the new page that opens after the person clicks on a link.

Adding it to the Querystring:

"http://yoursite.com/yourpage?id=123"

Store it in session instead:

Use a server control, such as a LinkButton or a button to redirect the user to the new page and then save the string value to session.

protected void LinkButton_Click(object sender, EventArgs e)
    {
        Session["Id"] = 123;
        Response.Redirect("yourpage.aspx", false);
    }

To get the string value from your session use:

Session["id"].ToString();

To learn more about about state management and see other options, go here

Different Solution

Encrypt the querystring value before you add it to the URL and then decrypt it. If you go this route, look at this article for details on encrypting/decrypting values.

http://www.codeproject.com/KB/security/DotNetCrypto.aspx

Ricardo
I cannot use session.We use a content management server anybody can add the querystring and i dont think I would be able to track all of them using session.
Dotnet Rocks
Updated my answer to include a new solution
Ricardo
A: 

It depends on what you're trying to track. If you're trying to track the user on the fly as they move through your site, you'd be better of putting a small token into session - as Ricardo states in his answer.

If you want to track how particular links are performing on your site, or which links a user is following, then you'll need to use some JavaScript:

Basically, you'll need to create an onclick event on the <a> tags that calls into a service (or similar) on your server to track/log the fact that this click has happened.

If this method returns true, then control will return to the browser, and the original href will be requested.

This example assumes the use of jQuery, but other libraries will allow you to perform similar things - you could use all native ASP.NET tools, I just had this code to hand:

<a href="/someUrl.aspx" onClick="javascript:TrackThis(this);return true;">text</a>

<script type="text/javascript">
  function TrackThis(link){
     $.ajax({
        url: "/WebServices/ClickTracker.asmx/Track",
        type: "POST",
        dataType: "json",
        data: "{\"url\":\"" + link + "\", \"page\":\"" + window.location + "\"}"
        contentType: "application/json; charset=utf-8"
    });
  }

Then you can create a simple web service that takes the values you're passing in (in this case the value of the link the user clicked on, and the url of page they were on at the time), performs its processing, and keeps out of the way.

Google do something very similar to this with their search results - the URL in the browsers status bar and that you arrive at is the one from the indexed site, but in the middle you visit a tracking page on Google's servers to say that you clicked on it, which uses the onclick event.

Zhaph - Ben Duguid