C# ASP.NET SQL SERVER

Request.Params == QueryString + Form + ServerVariables + Cookies

I'm doing some work with the ASP.NET Request object and have just discovered that I can get all of the "params" from one property on the Request object.

If I'm not already in a context where the Request object is a member of that context (such as an MVC Controller or a codebehind page) then I will usually access the Request object through the HttpContext.Current object. I always wrap this access in a double are-you-null before trying to access it:

if (HttpContext.Current != null && HttpContext.Current.Request != null)
{
}

These four objects:

HttpContext.Current.Request.QueryString
HttpContext.Current.Request.Form
HttpContext.Current.Request.ServerVariables
HttpContext.Current.Request.Cookies

Can be accessed through a single collection if you reference the:

HttpContext.Current.Request.Params

which gets a combined collection of the other four.

 

» Similar Posts

  1. Combine, compress, and update your CSS file in ASP.NET MVC
  2. ASP.NET MVC DropDownList from Enum
  3. Professional ASP.NET MVC 1.0

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=255

» Comments

    There are no comments. Kick things off by filling out the form below.

» Leave a Comment