Solved

Encode URL

Posted on 2011-09-11
4
833 Views
Last Modified: 2012-05-12
I have a master page and links like this:

<asp:Hyperlink .... NavigateURL = "default.aspx?PageId=9" />

My coworker says we need to encode the URL. I've found these 2 links but still not sure how to do it.

1. http://forums.asp.net/t/1303095.aspx
   This one has Response.Redirect("default.aspx?data=" + HttpUtility.UrlEncode(value));

 but I need to add "pageId=9" to it

2. http://forums.asp.net/t/1530950.aspx
Scroll down, says to encode and decode and redirect in a separate page.

3. http://www.4guysfromrolla.com/articles/083105-1.aspx
That one has a live demo with code to tamper proof a URL.

How can I do encode a URL?
0
Comment
Question by:Camillia
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Cyber-spy
ID: 36519976
If you mean URL Encoding (removing any illegal characters - & ?, <space> etc) this is only necessary in the actual data.
In your example, you only use the digit '9', which doesn't need encoding - what you have already is fine.

However, you have also posted a link to a page about tamper proof URL's. If you want to mask the fact the number is a page ID, then try using a longer code for the page ID - a GUID would be most secure, but a random sequence of 5 or 6 letters/numbers would make it hard to guess other page id's. However, if users guessing other page id's is ok, but you just want to make sure the id can't be misused, then just some server side validation to make sure the ID is really a number, and then is an actual page id should be enough.
0
 
LVL 7

Author Comment

by:Camillia
ID: 36520056
ah, yeah, i don't want users typing id 8 or id 7 in URL and change the page like that. Yes, having a random sequence of numbers is a better idea. Thanks.
0
 
LVL 7

Author Comment

by:Camillia
ID: 36520071
so it's ok if i display http://whatever.com?pageId=9

i guess it is. For example, for this question, i see this URL
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27302315.html

so it displays the question id....
0
 
LVL 12

Accepted Solution

by:
Cyber-spy earned 500 total points
ID: 36520218
URL Rewriting is a technique to mask ID's such as the one you are using. It has the additional benefit that it improves SEO.

If you are using IIS6, you need a third party component - See http://www.helicontech.com/isapi_rewrite/
For, IIS7, it is supported natively - see http://www.iis.net/download/urlrewrite for an intro
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question