DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Rewrite URL In ASP .NET

  • submit to reddit
        // code below replaces URL like page.aspx?id=12345 to real URL from DB
// URL displayed in address bar is page.aspx?id=12345
// place in global.asax

protected void Application_BeginRequest(object sender, EventArgs e){
    HttpContext context = HttpContext.Current;
    object obj = context.Request["id"];
    if(obj != null){
        int id = (int)obj;
        string url = GetPageUrlFromId(id);