ASP.NET: Using Request["param"] versus using Request.QueryString["param"] or Request.Form["param"] -
when accessing form or query string value code-behind in asp.net, pros , cons of using, say:
// short way string p = request["param"];
instead of:
// long way string p = request.querystring["param"]; // if it's in query string or string p = request.form["param"]; // posted form values
i've thought many times, , come with:
short way:
- shorter (more readable, easier newbies remember, etc)
long way:
- no problems if there form value , query string value same name (though that's not issue)
- someone reading code later knows whether in urls or form elements find source of data (probably important point)
.
so other advantages/disadvantages there each approach?
the long way better because:
it makes easier (when reading code later) find where value coming from (improving readability)
it's marginally faster (though isn't significant, , applies first access)
in asp.net (as equivalent concept in php), use calling "long form." out of principle want know input values coming, ensuring application way expect. so, it's input validation , security prefer longer way. plus, suggest, think maintainability worth few keystrokes.
Comments
Post a Comment