how to encode and decode url when using query string in asp.net 2.0

Last post 05-14-2008 11:28 AM by jalal. 6 replies.

Sort Posts:

  • how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 10:27 AM

     Hi can some one tell me how to use server.encodeurl and server.decodeurl

    to hide the query string variable from url. in asp.net2.0.

     

    Thankyou

    siri 

     

     

  • Re: how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 10:37 AM
    • Loading...
    • ramblor
    • Joined on 03-13-2008, 10:03 AM
    • Posts 1,005
    Server.UrlEncode and Server.UrlDecode won't hide the querystring, they're used to encode a string (and decode it back again) so that it's safe to pass in a url. What are you trying to do?
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
  • Re: how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 10:44 AM

     Iam trying to hide the variable  iam sending from one page to other page using query string in the url.

    do u know how to hide the variable.

     

    Thankyou.

    siri 

  • Re: how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 10:50 AM
    • Loading...
    • ramblor
    • Joined on 03-13-2008, 10:03 AM
    • Posts 1,005

    If you send it in the querystring you won't be able to hide it easily. You'd be better off saving the variable in the Session I think.

    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
  • Re: how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 11:08 AM

     Hi

    Yes I can use session but session is creating some problems so its compulsory that i should use querystring.

    please tell if u have any idea about that.

    Thankyou,

    siri 

  • Re: how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 11:11 AM
    • Loading...
    • ramblor
    • Joined on 03-13-2008, 10:03 AM
    • Posts 1,005

    I think you want to encrypt your querystring, not encode it. Take a look at this other thread which might help.

    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
  • Re: how to encode and decode url when using query string in asp.net 2.0

    05-14-2008, 11:28 AM
    Answer
    • Loading...
    • jalal
    • Joined on 06-18-2007, 9:22 AM
    • Dhaka, Bangladesh
    • Posts 26

    Actually what do you mean by hide? if you use query string to pass information your variables will be always visible. but you can encrypt the variable names also to make them not understandable. so your data will be safe. this is what you can do at most.

     you can do something like this -

     

     

    string[] variableNames = {"var1", "var2", "var3" };
    
    string[] variableValues = { "val1", "val2", "val3" };
    
    // Creating the query string to pass
    string encryptedData = encryptMyData(variableNames, variableValues);
    
    Response.Redirect(www.gotothispage.aspx? + encryptedData);
    
     
    // Method to create the query string
    public string encryptMyData(string[] variableNames, string[] variableValues)
    {
    
       string encryptedUrl = String.Empty;
       for(int i=0;i< variableNames.Count; i++)
       {
          if(i==0)
            encryptedUrl += "?";
          else
            encryptedUrl += "&";
          
          // using desired encryption algorith to encrypt both variable name and value
          encryptedUrl += myEncryptionAlgo(variableNames[i]) + "=" + myEncryptionAlgo(variableValues[i]);
       }
       // encoding the encrypted url to make sure it is http compatible
       return HttpUtility.UrlEncode(encryptedUrl);
    }
    
    
    
    now read the values on other page like - 
    
    // using the same encryption algorithm to again encrypt the variable name
    // as we have to use it to capture the valuel from query string
    string encryptedVarName1 = myEncryptionAlgo("var1");
    string myVal1 = Request.QueryString[encryptedVarName1].ToString();
    
    //decrypting the data for that variable
    myVal1 = myDecryptionAlgo(myVal1);
    ....
    ....
    ....
    ....
    
    // this way reading all the data
    string encryptedVarName3 = myEncryptionAlgo("var3");
    string myVal3 = Request.QueryString[encryptedVarName3].ToString();
    
    
    myVal3 = myDecryptionAlgo(myVal3);
    
    
    
     
    If you get correct answer, mark it as "Answered" to help others
    www.thecodemaker.com
Page 1 of 1 (7 items)
Microsoft Communities
Page view counter