IIS treats double-encoded forward slashes in URLs differently on the first request than it does on subsequent requests

后端 未结 2 780
花落未央
花落未央 2021-01-05 17:33

Recently my team was asked to implement an HttpModule for an ASP.NET MVC application that handled double-encoded URLs on IIS 7 and .NET 3.5. Here\'s the crux of the problem

相关标签:
2条回答
  • 2021-01-05 18:07

    Request.Url can be decoded already - I wouldn't trust it for what you are doing.

    See the internal details at: Querystring with url-encoded ampersand prematurely decoded within Request.Url

    The solution is to access the values directly via Request.RawUrl.

    I realize your prob is with the path, but it seems the same thing is going on. Try the RawUrl - see if it works for you instead.

    0 讨论(0)
  • 2021-01-05 18:11

    This really isn't an answer, but possibly a step in the right direction. I haven't had time to create a test harness to prove anything.

    I followed this.PrivateAbsolutePath through Reflector and it goes on and on. There is a lot of string manipulation when it's accessed.

    public string AbsolutePath
    {
        get
        {
            if (this.IsNotAbsoluteUri)
            {
                throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
            }
            string privateAbsolutePath = this.PrivateAbsolutePath; //HERE
            if (this.IsDosPath && (privateAbsolutePath[0] == '/'))
            {
                privateAbsolutePath = privateAbsolutePath.Substring(1); 
            }
            return privateAbsolutePath;
        }
    }
    
    0 讨论(0)
提交回复
热议问题