How to Use a URL Rewriter in Global.Asax in Vb.Net

The ASP.NET "Global.asax" file lets you set pre-rendering code that runs before the user sees your Web page in the browser. A URL rewrite function changes a user-friendly URL to the actual URL needed to display dynamic information. User-friendly URLs use a naming scheme that makes it easier for visitors to recognize and remember a website's address. The URL is not an actual page on the server, so you use the Global.asax file to point the server to the actual page address.

Instructions

    • 1

      Click the Windows "Start" button, and select "All Programs." Click "Microsoft .NET," then click "Visual Studio" to open the software. Open the .NET Web project after VS opens.

    • 2

      Double-click the "Global.asax" file displayed in "Solution Explorer" on the right side of the window. The file opens in an editor, which is where you type the URL rewrite modification.

    • 3

      Type the following code in the file's editor:

      Dim http As System.Web.HttpContext = HttpContext.Current

      Dim URL As String = URL.Request.Path.ToLower()

      http.RewritePath("page.aspx?ID=333")

      The preceding code retrieves the current URL and stores it into the "URL" variable. The "RewritePath" function performs the URL rewrite and directs the server to process the "page.aspx" file. Replace the page and ID with your own values.

Related Searches:

References

Comments

Related Ads

Featured