Blankman
Blankman

Reputation: 267290

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?

Upvotes: 8

Views: 3362

Answers (2)

John Farrell
John Farrell

Reputation: 24754

ViewPage inherits from System.Web.UI.Page and I'm pretty positive all of the HttpRequest members are inherited from that:

http://msdn.microsoft.com/en-us/library/dd504962.aspx

Upvotes: 2

womp
womp

Reputation: 116987

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.

Upvotes: 5

Related Questions