Url encoding issue; + v. %2B

Discussion in 'ASP .Net' started by MWells, Jan 13, 2005.

  1. MWells

    MWells Guest

    I've encountered an interesting issue regarding Url encoding that I'm
    hopeful someone can shed some light on.

    I have some vanity Url's that have to contain filename content, using the
    file naming rules of the Windows file system. Because spaces are plus (+)
    signs are permitted in Windows filenames, I might have a file called;

    "test+test test.txt"

    And the vanity Url that references it might be something like;

    http://yadda/getfile/test test test.txt

    To avoid Url problems, I encode the filename portion of the vanity Url using
    Server.UrlEncode () and I get...

    http://yadda/getfile/test+test test.txt

    Looking good so far, but in my HttpModule I run into a serious issue; the
    Url value that I get through Request.RawUrl appears with the %2B translated,
    as follows...

    http://yadda/getfile/test test test.txt

    This means that I can't distinguish between plus signs and spaces. When I
    decode, I get;

    http://yadda/getfile/test test test.txt

    Which makes it impossible for me to locate the file the user has requested.

    I've tested this many times, refreshing, viewing the results in trace.axd,
    and the problem is very consistent. I can see the %2B in the Url bar, but
    it's being decoded before the value is stored in Request.RawUrl. None of
    the other header variables (as perused in trace.axd) show the %2B either.

    I haven't isolated the location of the problem yet; it's somewhere between
    the Internet Explorer Url bar and the start of execution of my HttpModule.
    The problem might be IE6, or IIS, or .NET; I'm hopeful that someone already
    knows the answer before I have to put on the hardhat and go spelunking.

    Also while I'd like to understand it, I'm more immediately concerned about a
    solution, so ideas are welcome. Clearly, I'd like to avoid my own
    additional encoding scheme if I can avoid it...

    Many thanks.

    /// M
     
    MWells, Jan 13, 2005
    #1
    1. Advertising

  2. MWells

    MWells Guest

    Update; for anyone interested, the Url decoding problem is definately
    occurring in the HttpModule. I've setup an HttpModule that does nothing
    but;

    Trace.Write (HttpContext.Current.Request.RawUrl);

    When entering a Url into MSIE like;

    http://mysite/test test+test/testing.aspx

    The HttpModule gets;

    http://mysite/test test test/testing.aspx

    I've turned off IIS wildcard mapping for the test, eliminated most all of
    the other elements I can think of. If I do this same test to a normal .aspx
    page without the HttpModule, I get the properly decoded Url;

    http://mysite/test test+test/testing.aspx

    Does anyone have any idea why this is happening, or where to go from here?
    Is there a defect submission procedure for this kind of anomaly?

    Thanks again,

    /// M



    "MWells" <outbound__at_sygnal.com> wrote in message
    news:OHFkzTV#...
    > I've encountered an interesting issue regarding Url encoding that I'm
    > hopeful someone can shed some light on.
    >
    > I have some vanity Url's that have to contain filename content, using the
    > file naming rules of the Windows file system. Because spaces are plus (+)
    > signs are permitted in Windows filenames, I might have a file called;
    >
    > "test+test test.txt"
    >
    > And the vanity Url that references it might be something like;
    >
    > http://yadda/getfile/test test test.txt
    >
    > To avoid Url problems, I encode the filename portion of the vanity Url

    using
    > Server.UrlEncode () and I get...
    >
    > http://yadda/getfile/test+test test.txt
    >
    > Looking good so far, but in my HttpModule I run into a serious issue; the
    > Url value that I get through Request.RawUrl appears with the %2B

    translated,
    > as follows...
    >
    > http://yadda/getfile/test test test.txt
    >
    > This means that I can't distinguish between plus signs and spaces. When I
    > decode, I get;
    >
    > http://yadda/getfile/test test test.txt
    >
    > Which makes it impossible for me to locate the file the user has

    requested.
    >
    > I've tested this many times, refreshing, viewing the results in trace.axd,
    > and the problem is very consistent. I can see the %2B in the Url bar, but
    > it's being decoded before the value is stored in Request.RawUrl. None of
    > the other header variables (as perused in trace.axd) show the %2B either.
    >
    > I haven't isolated the location of the problem yet; it's somewhere between
    > the Internet Explorer Url bar and the start of execution of my HttpModule.
    > The problem might be IE6, or IIS, or .NET; I'm hopeful that someone

    already
    > knows the answer before I have to put on the hardhat and go spelunking.
    >
    > Also while I'd like to understand it, I'm more immediately concerned about

    a
    > solution, so ideas are welcome. Clearly, I'd like to avoid my own
    > additional encoding scheme if I can avoid it...
    >
    > Many thanks.
    >
    > /// M
    >
    >
    >
    >
     
    MWells, Jan 15, 2005
    #2
    1. Advertising

  3. MWells

    MWells Guest

    Further update;

    In my particular application I've been able to solve this problem. In this
    particular case, I manufacture all of the Urls that the user accesses using
    Url rewriting, and as a result I can eliminate the problematic "space to +"
    encoding behavior.

    // original Windows filename I need to embed in the Url
    string szUrl = "test+test test.txt";

    // encode the Url
    szUrl = Server.Encode (szUrl); // creates test%2Btest+test

    // substitute %20 for + as encoded spaces
    szUrl = szUrl.Replace ("+", "%20"); // creates test%2Btest%20test

    // finish Url
    szUrl = "http://mysite.com/getfile/" + szUrl;

    // set link
    hlFile.Hyperlink = szUrl;


    In this case the HttpModule gets the Url as;

    http://mysite.com/getfile/test test test.txt


    HTH anyone who finds themselves facing the same issue.

    /// M



    "MWells" <outbound__at_sygnal.com> wrote in message
    news:OBNH6Ou#...
    > Update; for anyone interested, the Url decoding problem is definately
    > occurring in the HttpModule. I've setup an HttpModule that does nothing
    > but;
    >
    > Trace.Write (HttpContext.Current.Request.RawUrl);
    >
    > When entering a Url into MSIE like;
    >
    > http://mysite/test test+test/testing.aspx
    >
    > The HttpModule gets;
    >
    > http://mysite/test test test/testing.aspx
    >
    > I've turned off IIS wildcard mapping for the test, eliminated most all of
    > the other elements I can think of. If I do this same test to a normal

    ..aspx
    > page without the HttpModule, I get the properly decoded Url;
    >
    > http://mysite/test test+test/testing.aspx
    >
    > Does anyone have any idea why this is happening, or where to go from here?
    > Is there a defect submission procedure for this kind of anomaly?
    >
    > Thanks again,
    >
    > /// M
    >
    >
    >
    > "MWells" <outbound__at_sygnal.com> wrote in message
    > news:OHFkzTV#...
    > > I've encountered an interesting issue regarding Url encoding that I'm
    > > hopeful someone can shed some light on.
    > >
    > > I have some vanity Url's that have to contain filename content, using

    the
    > > file naming rules of the Windows file system. Because spaces are plus

    (+)
    > > signs are permitted in Windows filenames, I might have a file called;
    > >
    > > "test+test test.txt"
    > >
    > > And the vanity Url that references it might be something like;
    > >
    > > http://yadda/getfile/test test test.txt
    > >
    > > To avoid Url problems, I encode the filename portion of the vanity Url

    > using
    > > Server.UrlEncode () and I get...
    > >
    > > http://yadda/getfile/test+test test.txt
    > >
    > > Looking good so far, but in my HttpModule I run into a serious issue;

    the
    > > Url value that I get through Request.RawUrl appears with the %2B

    > translated,
    > > as follows...
    > >
    > > http://yadda/getfile/test test test.txt
    > >
    > > This means that I can't distinguish between plus signs and spaces. When

    I
    > > decode, I get;
    > >
    > > http://yadda/getfile/test test test.txt
    > >
    > > Which makes it impossible for me to locate the file the user has

    > requested.
    > >
    > > I've tested this many times, refreshing, viewing the results in

    trace.axd,
    > > and the problem is very consistent. I can see the %2B in the Url bar,

    but
    > > it's being decoded before the value is stored in Request.RawUrl. None

    of
    > > the other header variables (as perused in trace.axd) show the %2B

    either.
    > >
    > > I haven't isolated the location of the problem yet; it's somewhere

    between
    > > the Internet Explorer Url bar and the start of execution of my

    HttpModule.
    > > The problem might be IE6, or IIS, or .NET; I'm hopeful that someone

    > already
    > > knows the answer before I have to put on the hardhat and go spelunking.
    > >
    > > Also while I'd like to understand it, I'm more immediately concerned

    about
    > a
    > > solution, so ideas are welcome. Clearly, I'd like to avoid my own
    > > additional encoding scheme if I can avoid it...
    > >
    > > Many thanks.
    > >
    > > /// M
    > >
    > >
    > >
    > >

    >
    >
     
    MWells, Jan 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardy Wang

    Encoding.Default and Encoding.UTF8

    Hardy Wang, Jun 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    18,871
    Jon Skeet [C# MVP]
    Jun 9, 2004
  2. Jon paugh
    Replies:
    1
    Views:
    756
  3. Replies:
    1
    Views:
    23,373
    Real Gagnon
    Oct 8, 2004
  4. johkar
    Replies:
    0
    Views:
    698
    johkar
    Feb 25, 2006
  5. Just D.
    Replies:
    0
    Views:
    444
    Just D.
    Aug 11, 2004
Loading...

Share This Page