Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...
i want code for URL encoding.... when i redirect one page to another page then automatically that page url can be encoded..
i was used this code
XML
String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title=" + Server.UrlEncode("ASP.NET Examples");

Response.Write("<a href=" + MyURL + "> ASP.NET Examples </a>");

but it doesn't works...
please help me...



thank you.....
Posted
Updated 3-Jul-12 1:32am
v2
Comments
pradiprenushe 3-Jul-12 6:53am    
Your code running properly at my sight. What is actually happening at your sight. Wheather page is displaying with link? or Page is displayed but not redirecting?

Can you try HttpServerUtility.UrlEncode(String)

http://msdn.microsoft.com/en-us/library/zttxte6w.aspx[^]

Hope this help!

Avinash
 
Share this answer
 
Comments
NaniCh 3-Jul-12 7:12am    
firstly i was use this code...
but it is not working in my website.....
pradiprenushe 3-Jul-12 7:43am    
Can u give actual behavior what is happening?
 
Share this answer
 
For encoding and decoding strings you can use this, i hope it will help.
C#
    public static string Encrypt(string stringToEncrypt, string sEncryptionKey)
    {
     byte[] key = { };
 
     byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 };
 
        byte[] inputByteArray;
 
        try
        {
            key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
 
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV),               CryptoStreamMode.Write);
 
            cs.Write(inputByteArray, 0, inputByteArray.Length);
 
            cs.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());
 
        }
        catch (System.Exception ex)
        {
            return ex.Message;
 
        }
    }//end of Encrypt



public static string Decrypt(string stringToDecrypt, string sEncryptionKey)
    {
        byte[] key = { };
 
        byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 };
        byte[] inputByteArray = new byte[stringToDecrypt.Length];
 
        try
        {
            key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            inputByteArray = Convert.FromBase64String(stringToDecrypt);
 
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
 
            cs.Write(inputByteArray, 0, inputByteArray.Length);
 
            cs.FlushFinalBlock();
            Encoding encoding = Encoding.UTF8;
            return encoding.GetString(ms.ToArray());
 
        }
        catch (System.Exception ex)
        {
            return ex.Message;
 
        }
    }

http://goldenpearl.blogfa.com/post/4[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900