locked
How to handle the query string during url rewirting RRS feed

  • Question

  • User-1331347409 posted

    Hi all,

    This is the code that I used to URLREWRITE. But I don't know how to handle the query string. Can any body explain how to have a friendly url with query string.


    private void Application_BeginRequest(Object source, EventArgs e)
        {
            
            System.Web.HttpContext httpContext = HttpContext.Current;
            String currentURL = httpContext.Request.Path.ToLower();
            string processPath =
              currentURL.Substring(httpContext.Request.ApplicationPath.Length).
                                                       TrimStart('/').ToLower();

            //Creates the physical path on the server
            string physicalPath = httpContext.Server.MapPath(
                          currentURL.Substring(currentURL.LastIndexOf("/") + 1));

            if (physicalPath.EndsWith(".aspx"))
            {
                httpContext.Response.Redirect(currentURL.Replace(".aspx", string.Empty));
            }

             //get the relative URL of the requested page
            string strRelativeUrl = HttpContext.Current.Request.Url.AbsolutePath;
            if (!strRelativeUrl.StartsWith("/"))
            {
                strRelativeUrl = "/" + strRelativeUrl;
            }

            strRelativeUrl =  strRelativeUrl.ToLower().Replace( ("/App_And_Page_LifeCycle/").ToLower(), "");


            string queryString = httpContext.Request.ServerVariables["QUERY_STRING"];

            if (strRelativeUrl.Equals("Content", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Content.aspx");
            }
            else if (strRelativeUrl.Equals("Page1", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Page1.aspx");
            }
            else if (strRelativeUrl.Equals("Page2", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Page2.aspx");
            }
            else if (strRelativeUrl.Equals("Page3", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Page3.aspx");
            }
            else if (strRelativeUrl.Equals("Page4", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Page4.aspx");
            }
            else if (strRelativeUrl.Equals("Page5", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Page5.aspx");
            }
            else if (strRelativeUrl.Equals("Page6", StringComparison.OrdinalIgnoreCase))
            {
                HttpContext.Current.RewritePath("/App_And_Page_LifeCycle/en-ca/Page6.aspx");
            }

    }


    Thanks.

    Saturday, July 18, 2009 1:05 AM

Answers