Friday, January 7, 2011

Basic URL rewriting without file extension

You have to add this code in Global.asax file:
    void Application_BeginRequest(object sender, EventArgs e)
    {
         string curruntpath = Request.Path.ToLower().Trim(); ;

        bool endsswith = curruntpath.EndsWith(".aspx");
       HttpContext obj = HttpContext.Current;
        if (!endsswith)
        {
            curruntpath = curruntpath + ".aspx";
        }
         if (System.IO.File.Exists(Server.MapPath(curruntpath)))
        {
             obj.RewritePath(curruntpath);
        }
         else
        {
             obj.RewritePath("Error.aspx");
        }
        
       
    }

No comments:

Post a Comment