Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Encode URL

Posted on 2011-09-11
4
Medium Priority
?
872 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:Adam
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:
Adam earned 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline

886 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