URL Rewriting
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront
Current Tip:
URL Rewriting
 
[prev. Lesson]  Refrencing the Root Path/URL [next Lesson]  Error Reporting
URL Rewriting  by: Salman

If you don't like having meaningless URL's for your visitors (i.e index.aspx?id=3&pid=3932), consider URL Re-writing. With URL rewriting, you can store all your content in the database while having user-friendly URL's. Here's a code snippet to do just this:

void Application_BeginRequest(Object sender, EventArgs e) 
{
 String strCurrentPath;
 String strCustomPath;
 strCurrentPath = Request.Path;
 strCurrentPath = strCurrentPath.ToLower();
 // the URL contains this folder name
 if (strCurrentPath.IndexOf( "/SomeSubFolder/" ) > -1) 
 {
  strCustomPath = "getContent.aspx?id=" + 
Path.GetFileNameWithoutExtension( strCurrentPath );
  
  // rewrite the URL
  Context.RewritePath( strCustomPath );
 }
}

The getContent.aspx will take the page name as a parameter and do a lookup in the database and return the content for the page.  I have left the details out because the point of the code snippet is to show how to rewrite the URL and get the data from the database.

Reference:

  • Rewrite Path method

    Related Links:

  • Rewrite.NET -- A URL Rewriting Engine for .NET

  •    
    Current Tip:
    URL Rewriting
     
    [prev. Lesson]  Refrencing the Root Path/URL [next Lesson]  Error Reporting



    Today's Top Movers

    Yesterday Top Movers


    Monthly Leaders

    Top Members

    Great Offers
    .net hosting
    Go To My Pc
    Remote Pc Control
    C#
    ad server
    snadtech GoToMyPc

    Top of Page

    Advertise | SiteMap | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center