Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does the controllers action have HttpRequestBase, and the viewpage has HttpRequest?

My methods take HttpRequestBase as arguements, and I am finding it strange as to why the Actions in Controllers have access to HttpRequestBase but the view page's have HttpRequest.

Is there a reason for this or just something that was not thought through?

like image 850
Blankman Avatar asked Feb 01 '10 21:02

Blankman


People also ask

What is HttpRequestBase?

The HttpRequestBase class is an abstract class that contains the same members as the HttpRequest class. The HttpRequestBase class enables you to create derived classes that are like the HttpRequest class, but that you can customize and that work outside the ASP.NET pipeline.

Can there be the same action method name with the same Httpverb in a controller?

The methods must have different parameters. This is dictated by the programming language and is basically method overloading. Even if two methods have different parameters, they must also have different http verb attributes (httpget, httppost).

What is HttpPost and HttpGet in MVC?

HttpGet and HttpPost both are the attributes used in asp.net mvc application. We use both attributes on action represents the http requests like whether it is get request or post request.

What is a controller action?

An action (or action method) is a method on a controller which handles requests. Controllers logically group similar actions together. This aggregation of actions allows common sets of rules, such as routing, caching, and authorization, to be applied collectively. Requests are mapped to actions through routing.


1 Answers

View pages have access to the MVC HttpContext through ViewContext.HttpContext, which is an HttpContextBase.

The seemingly dual access is just due to the way ASP.Net works. When you look at Request.HttpContext, this is the ASP.Net pipeline's injection of the original HttpContext. This is accessible in any HttpHandler, whether it's an MVC controller or view, or a WebForms page or ashx.

like image 64
womp Avatar answered Sep 19 '22 20:09

womp