Why is the request ["url"] set by default?

Even if I do not perform POST or GET with any parameter named url, it still gets into the Request variable, as a result of which it is always set Request["url"]. The default value is the requested aspx file. If I specify the URL as a POST or GET parameter in the request, the default value will be overwritten. Can you explain why this behavior is implemented in .net?

+4
source share
3 answers

This is described in the class information HttpRequest. Look at the Items collection and it says that it will look at objects from QueryString, Form, Cookies or ServerVariables. This goes back to the classic ASP, and other languages ​​implement similar ones, such as PHP, although PHP considers it unsafe, and I believe that it was disabled in version 5.5. Microsoft also recommended against doing so, as it can be used. In case of request ["url"] it will return a server variable. If there is a pointer with the url variable in it, Request ["url"] will return the querystring variable, since it is first checked in the list. It has been included for backward compatibility with classic ASP, as it has been widely used in classic ASP.

HttpRequest MSDN Documentation

+5

? " # X" (. )

- " - ". , , , , , , . , " ", , , pre -.net asp.

+1

HttpRequest Request [ "url" ], . HttpRequest :

public string this[string key]{ get; }

- , / , , .

HttpRequest , , , (Cookies, ServerVariables, QueryString, Form ..). - , Request , .

, , .NET 4.5:

public string this[string key]
{
    get
    {
        string val = this.QueryString[key];

        if (val != null)
            return val;

        val = this.Form[key];

        if (val != null)
            return str;

        var cookie = this.Cookies[key];

        if (cookie != null)
            return cookie.Value;

        val = this.ServerVariables[key];

        if (val != null)
            return val;

        return null;
    }
}

URL POST GET , . , .net?

"url" POST GET, QueryString, , . HttpRequest (Cookies, QueryStrings ..) .

[ "url" ]?

ServerVariables.

POST GET url?

, Request [ "url" ] # , . . Request.Path.

+1

All Articles