ASP.NET: using request ["param"] versus using Request.QueryString ["param"] or Request.Form ["param"]

When you access the string or string value of a request from code in ASP.NET, what are the pros and cons of using, say:

// short way
string p = Request["param"];

instead:

// long way
string p = Request.QueryString["param"]; // if it in the query string or
string p = Request.Form["param"];        // for posted form values

I thought about it many times and came up with:

Shortcut:

  • Shorter (more readable, easier for beginners to remember, etc.)

A long way:

  • No problem if there is a form value and a query string value with the same name (although this is usually not a problem)
  • Someone reading the code later knows whether to look in the URLs or form elements to find the data source (perhaps the most important point).

.

. What other advantages / disadvantages exist for each approach?

+3
2

, :

  • ( ) , ( )

  • ( )

ASP.NET( PHP) , " ". , , , , , . , , . , , , .

+4

param (4) :

  • Cookies

, , ,

+9

Source: https://habr.com/ru/post/1790865/


All Articles