Urlrewritting problem

Last post 07-03-2009 9:40 AM by SSA. 1 replies.

Sort Posts:

  • Urlrewritting problem

    07-03-2009, 6:08 AM

    Hi everyone I have problem regarding dynamic url rewritting in asp.net. I am working on some site where i am passing querystring and on behalf of querystring i have to get name  etc now i have return code on global.aspx page on application_beginrequest and code is below:

     

    if i type www.peopleforever.org/profile.aspx?uid=9 it should be written like www.peopleforever.org/profile.aspx/Prakash

    if (HttpContext.Current.Request.Path.ToLower().Contains("/profiles.aspx"))
            {
                string userid = Request.QueryString["uid"];
                string name = utility.GetName(userid);
                name = name.Replace(" ", "_");
                Context.RewritePath("~/Profiles.aspx/" + name);
                Context.Response.Status = "301 Moved Permanently";
                Context.Response.AddHeader("Location", Context.Request.Url.AbsolutePath);
            }

    Now first time it get correct querystring and give correct url but after that it goes to infinite loop and after coming of this loop querystring doesn't

    have value and and i need to querystring value on my above url bcoz on the basis of querystring i need to get some records also but querystring is null.

     

    How to solve my problem plz plz help me to come out of this problem.

     

    my url is (http://www.peopleforever.org/profiles.aspx?uid=9) should be http://www.peopleforever.org/profiles.aspx/PrakashShrestha and i have to check querysting value also in profiles.aspx page.

    how is it possible to keep querystring value after urlrewritting.

     

     

     

     

    Filed under:
  • Re: Urlrewritting problem

    07-03-2009, 9:40 AM
    Answer
    • Contributor
      2,508 point Contributor
    • SSA
    • Member since 05-07-2009, 3:16 PM
    • Amsterdam, The Nederlands
    • Posts 418

    You are doing it allright, as per the requirement mentioned but

    Check this line:

    you are using contains function 

    if (HttpContext.Current.Request.Path.ToLower().Contains("/profiles.aspx"))

    and your both URL contains this text. So it will cause rewriting on all request made to sever to load Profile.aspx.

    Next, Before assigning querystring value, add a check if its not null.


    and you said: 

    @ my url is (http://www.peopleforever.org/profiles.aspx?uid=9) should be http://www.peopleforever.org/profiles.aspx/PrakashShrestha and i have to check querysting value also in profiles.aspx page.@


    But in your rewriting you are removing querystring and adding path info, so new page you can not use it as Querystring but you have to do something like this:

    If (Request.PathInfo.Length == 0)

    {

    string strName = Request.PathInfo.Substring(1); // This will give PrakashShrestha

    }
              


Page 1 of 1 (2 items)