Basic URL rewriting without file extension

By Super Man

How you can rewrite the url which can work without entering 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");
        }
         
         
    }

Basic URL rewriting without file extension  (1424 Views)