Tutorial on How To Disguise URLs of your Website

Submitted on: 1/1/2015 8:02:00 PM
By: dotNETJunkie (from psc cd)  
Level: Intermediate
User Rating: By 15 Users
Compatibility: VB.NET, ASP.NET
Views: 2627
     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.
Please Vote!

				I uploaded the source code for this, and it is at
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.

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

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

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.