kay786, Indeed, it is possible. There are three basic ways that I can think of to do such a task. You could create an HttpHandler, HttpModule, or use the Application_BeginRequest of you global.asax file. Either technique will allow you to interpret and rewrite
the path. The path will remain "hidden" as its entered state. The technique is very useful and often used to bypass the outward use of querystrings, which sometimes halt search engine spiders from indexing a site completely. Spammers also sometimes use the
technique garble the address in an e-mail link (where one's own e-mail address is an encrypted string that looks like a folder or page; so when someone clicks on the link, he or she launches a page that decrypts and flags the address as existing). This is
also an often un-talked about way of "templating" by directing various traffic to centralized locations while preserving unique URL displays.
Typical Example 0. Page renders its encrypted links. 1. User clicks on "Products." 2. Link takes user to "www.abc.com/encryptedstring.aspx" (or any extension aspnet/iis handles) 3. Handling technique parses and decrypts the string. 4. Handling interprets
and rewrites the path to get an existing page from "www.abc.com/products.aspx" or "www.abc.com/products.aspx?id=1" (whatever you want). 5. Page is shown as "www.abc.com/encryptedstring" in the address bar but its data is from "www.abc.com/products.aspx?id=1"
If you just need to do something simple where all of your encrypted strings are routed to the same page but with different querystrings or to the page with the same name as its decrypted name, you could use your global.asax. The following is just an exmaple
I made. It will make any named aspx page use your root products.aspx page for testing. To add the decryption, do so where noted in the comments. There are countless ways to do the logic behind it.
Example Code - for your global.asax -----------------------------------------------------
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim strPath, strFilename, strExtension, strDirectory, strRealName, strNewPath As String
strPath = Request.Url.AbsolutePath
strFilename = System.IO.Path.GetFileNameWithoutExtension(strPath).ToLower.Trim
strExtension = System.IO.Path.GetExtension(strPath).ToLower.Trim
' // Logic can be handled in numerous ways. You could also make a call to check whether the
' // file should even be handled, based on the directory or file name, so that not all files are used.
' // However, I'll keep it simple for this example.
' // Below line is where you call to decrypt
' strRealName = YourCryptography.Decrypt(strFilename)
' // Use the line below just to test. It will redirect all aspx pages to your root products aspx page.
strRealName = "products"
strNewPath = String.Format("/{0}{1}", strRealName, strExtension)
' // You could also use the directories and names to associate a rewrite with a querstring
' // Let's say the filename is "products_100" ..You could then use querystrings by
' // Splitting it into the name and ID and formatting to ("/{0}{1}?id={2}", strRealName, strExtension, strRealID)
Context.RewritePath(strNewPath)
End Sub
ADVIZR
Member
95 Points
19 Posts
Re: Hide page's name in URL
Oct 09, 2003 04:39 PM|LINK
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) Dim strPath, strFilename, strExtension, strDirectory, strRealName, strNewPath As String strPath = Request.Url.AbsolutePath strFilename = System.IO.Path.GetFileNameWithoutExtension(strPath).ToLower.Trim strExtension = System.IO.Path.GetExtension(strPath).ToLower.Trim ' // Logic can be handled in numerous ways. You could also make a call to check whether the ' // file should even be handled, based on the directory or file name, so that not all files are used. ' // However, I'll keep it simple for this example. ' // Below line is where you call to decrypt ' strRealName = YourCryptography.Decrypt(strFilename) ' // Use the line below just to test. It will redirect all aspx pages to your root products aspx page. strRealName = "products" strNewPath = String.Format("/{0}{1}", strRealName, strExtension) ' // You could also use the directories and names to associate a rewrite with a querstring ' // Let's say the filename is "products_100" ..You could then use querystrings by ' // Splitting it into the name and ID and formatting to ("/{0}{1}?id={2}", strRealName, strExtension, strRealID) Context.RewritePath(strNewPath) End Sub----------------------------------------------------- If you need something more advanced, be sure to search for some tutorials on HttpHandlers and HttpModules. 1. Google > "asp.net" HttpHandlers 2. Google > "asp.net" HttpModules