Quick Search for:  in language:    
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 140,189. lines
 Jobs: 425. postings

 How to support the site

Sponsored by:

You are in:

Does your code think in ink?

Latest Code Ticker for .Net.
Click here to see a screenshot of this code!C# to VB.NET Converter
By MAJED_SINJAB on 12/30

(Screen Shot)

Click here to see a screenshot of this code!DX9 Ortho Projection
By Created by: X on 12/30

(Screen Shot)

By Mähr Stefan on 12/30

Click here to see a screenshot of this code!GnuCli
By Mähr Stefan on 12/30

(Screen Shot)

By Mähr Stefan on 12/30

A__Start and End a Process__A
By Yuri Vishnevsky on 12/29

Web Custom Control (Credit Card)
By Tahir Naveed on 12/29

By SpaceMonkey on 12/27

Credit Card Verification XML Web Service
By Tahir Naveed on 12/27

Click here to put this ticker on your site!

Add this ticker to your desktop!

Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites


Tutorial on How To Disguise URLs of your Website


Submitted on: 5/10/2003 2:40:35 AM
By: dotNETJunkie 
Level: Intermediate
User Rating: By 10 Users
Compatibility:VB.NET, ASP.NET

Users have accessed this article 3827 times.
(About the author)
     The purpose of this article is to show you how to disguise the url of your webpage. This is great for masking your webpage extension to not give away your server and development platform to potential hackers. You can also mask any parameters passed through the query string.<br>Please Vote!

Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
I uploaded the source code for this, and it is at http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=1204&lngWId;=10
The method used to change the url is the RewritePath method. Let's begin with the tutorial.
Create a new webproject.
Add a class to the project.
Name it Rewriter
Add Imports statements for System and System.Web.
We will write 2 methods(procedures/functions)
The first will be a Private Function returning a String. This function will act as a translator for our URL.

Public Function GetSubstitution(ByVal zPath As String) As String
'This first string check is to see if the word test is in the URL
'If So, return show.aspx
'show.aspx is the actual page
and zPath is what is displayed in the browser and passed to the server through links

If InStr(zPath, "test") > 0 Then
Return "show.aspx"
End If

'This second string validation checks the URL
for the extension htm
'If it is, replace the extension with aspx

If InStr(zPath, ".htm") > 0 Then
Dim intMarker As Integer
Dim strTemp As String
intMarker = Len(zPath) - 4
strTemp = Mid(zPath, 1, intMarker)
Return strTemp & ".aspx"
End If

'The third check will show us how we can pass a query string

If IsNumeric(Left(zPath,Len(zPath)-4)) = True
Dim strValue() As String
strValue = Left(zPath,Len(zPath)-4)
Return "show.aspx?ID=" & strValue
End If
'After all string checks were perforemed
'and none of the criteria didn't match
'Return the original string
Return zPath
End Function

The second will be a Public Sub Procedure and include the Shared statement (this will be called from our web project).

Public Shared Sub ReplaceURL()
Create an instance of the class
Dim objRewrite As ReWriter = New urlReWriter()
Create a string variable for our URL substitution
Dim strSubst As String
Set the substitution string to our first function GetSubstitution
'We will pass the URL being sent to the browser
'through the function to get it's replacement

strSubst = objRewrite.GetSubstitution(HttpContext.Current.Request.Path)
'If the length of our new URL is greater than zero
'Rewrite the URL path

If strSubst.Length > 0 Then
End If
End Sub

Now in order to implement this, we need to call our class and put it to work.
In the Application_BeginRequest of the Global.asax file, call the ReplaceURL function.

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub

This won't work yet. There's one more thing we have to do. That is tell the webserver how to handle our extensions.

open the IIS management console.
Open the properties of our webproject.
Click configuration button on the directory tab.
Add new extension
In the executable page, enter C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll
For extensions, enter the extensions you will be using, for this example, lets use .*
Under Verbs, select Limit to, and enter GET,HEAD,POST
Check that file exists
Click Ok, and apply settings. Now let's test it out.
Add a web form to the project. Name it show.aspx, and another named 5.aspx
In both pages in the page load add the line Response.Write("Page= " & Request.Url.ToString)

Now add an HTML page. Call it what you wish. Add links to 5.tst and text.htm and test.zzz

The ReWrite function will be called on request of the pages, and will tell the server which page to load.

Other 6 submission(s) by this author


Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Your Vote!

What do you think of this article(in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
Other User Comments
5/10/2003 1:31:37 PM:
Very good idea! 5 from me! I wonder if you could compile it into DLL and load it from "ISAPI Filters" tab.
Keep the Planet clean! If this comment was disrespectful, please report it:

5/12/2003 9:52:38 AM:undercodex
Well good example, can be used to write a reverse proxy in example.
Keep the Planet clean! If this comment was disrespectful, please report it:

5/15/2003 10:51:32 AM:Shane Bauer
very nice
Keep the Planet clean! If this comment was disrespectful, please report it:

Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.


Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | .Net Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.