Solved

Encode URL

Posted on 2011-09-11
4
806 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now