MVC :: Passing Around HttpContext From HttpHandler.ProcessRequest?

Dec 24, 2010

I am working on an existing application which works using a custom built MVC framework.

The gateway into the front end is an implementation of IHttpHandler to handle the requests and determine which Action to call - its called FrontControllerHandler.

Currently FrontControllerHandler.ProcessRequest(HttpContext context) method takes a HttpContext object and then continues to pass it around to various other methods that it calls.

What we're hoping to refactor is to stop passing around the 'context' object and simply refer to:

HttpContext.Current Allowing asp.net to do the work for us...its there...why not use it, right?

Thing that i'm not sure about is, would there ever be a scenarion in which the HttpContext object passed to ProcessRequest would not actually refer to the same memory location (same object) that is referenced by:

HttpContext.CurrentI'm assuming that this would never happen unless something has gone wrong, in which case i can test for it and throw an exception. EG

[Code]....

So i would like to get peoples thoughts on this...

View 6 Replies


Similar Messages:

HttpHandler ProcessRequest() Firing Twice?

Jun 18, 2010

I have a strange issue where i have a a HttpHandler having its ProcessRequest() event firing twice.i have nothing else in the class except a pointer to a static method so i'm lost.I have done some googling to no avail even thought it appears a few people are having similar issues:

Code:

public bool IsReusable
{
get { return true; }

[code]...

View 2 Replies

C# - Passing An Exception To An HttpHandler?

Dec 10, 2010

I am trying to pass an exception to an HttpHandler by doing the following:

catch (Exception e)
{
byte[] exceptionData;
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Persistence));
formatter.Serialize(stream, e);
exceptionData = stream.ToArray();
WebClient client = new WebClient();
Uri handler = new Uri(ApplicationUri, "TransferException.axd");
#if DEBUG
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(BypassAllCertificateStuff);
#endif
try
{
client.UploadData(handler, exceptionData);
}
catch (WebException) { }
}

EDIT

I am getting the following exception on the client.UploadData() line.
"Content-Length or Chunked Encoding cannot be set for an operation that does not write data."

EDIT

Even if I change my call to be client.UploadString(location, "THIS IS A TEST!"); it still fails with the same exception.

View 2 Replies

C# - Workaround For HttpContext.HideRequestResponse Being Internal? Detect If HttpContext.Request Is Really Available?

Apr 9, 2010

We're migrating an application to use IIS7 integrated mode. In library code that is designed to work either within the context of an HTTP request or not, we commonly have code like this:

if (HttpContext.Current != null &&
HttpContext.Current.Request != null) {
// do something with HttpContext.Current.Request
} else {
// do equivalent thing without HttpContext..
}

But in IIS7 integrated mode the check for HttpContext.Current.Request throws an exception whenever this code is called from Application_Start.

protected void Application_Start(object sender, EventArgs e)
{
SomeLibrary.DoSomethingWithHttpContextCurrentDetection();
}

Results in:

System.Web.HttpException: Request is not available in this context

How can I detect whether the request is really available without wrapping these calls in an exception handler and taking action based on whether an exception is generated or not.

Looking at HttpContext in Reflector I see it has an internal bool HideRequestResponse field but it's internal so I can only get to it with reflection and that's fragile. Is there a more official/approved way to determine if it's ok to call HttpContext.Request?

This blog post about the subject says not to use HttpContext, but how, in generic library code, can you determine if it's ok to use HttpContext?

http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

I'm using the work-around mentioned there which is to use Application_BeginRequest and an initialized field to only initialize once as part of BeginRequest, but that has to be done in every calling application whereas I'd prefer to make the library code more robust and handle this situation regardless of where it's called from.

View 4 Replies

Web Forms :: System.Web.UI.Page.ProcessRequest - Elapsed Exclusive Time

Jan 28, 2010

We have an ASP.NET web app talking to WCF for data. After resolving a number of service and db level performance issues, we turned to look at the web app itself.

After running a profile while hitting a few common pages, ProcessRequest is at the top of the list as far as elapsed exclusive time (which means time just in that method and any kernel code if I'm not mistaken)

Function Name
Elapsed Inclusive Time
Elapsed Exclusive Time
System.Web.UI.Page.ProcessRequest(class System.Web.HttpContext)
31,573.64
17,915.56

Viewstate sizes are not severe, prob 60k at most for fattest page.

View 1 Replies

Relationship Between HttpContext.Request.Cookies And HttpContext.Response.Cookies

Nov 23, 2010

I have been experimenting with code that will clear all of the cookies in an HttpContext.Response.Initially, I used this:

DateTime cookieExpires = DateTime.Now.AddDays(-1);
for (int i = 0; i < HttpContext.Request.Cookies.Count; i++)
{
HttpContext.Response.Cookies.Add(
new HttpCookie(HttpContext.Request.Cookies[i].Name, null) { Expires = cookieExpires });
}

this will error with an OutOfMemoryException because the for loop never exits - each time you add a cookie to the Response, it also gets added to the `Request.

View 1 Replies

Difference Between ControllerContext.HttpContext.Session And HttpContext.Current.Session

Nov 23, 2010

i'm using an example in which i can fake the session.It's for use in a unittest of a mvc controller.In the test i create a controller and then i do this:

FakeHttpContext httpctx = new FakeHttpContext(null,null,null,null,mSessionItems );
ControllerContext ctx2 = new ControllerContext(httpctx,new RouteData(), target);

here mSessionItems is my session and target is my instance of a controller,and indeed, when i'm in a controller reading this.ControllerContext.HttpContext.Session, i have a session, great!but.... i also read the session outside the controller, and there i use HttpContext.Current.Session, and that is null (or actualy, the HttpContext.Current is null).

View 1 Replies

Why My HttpHandler Is Ignored

Jun 28, 2010

In an ASP.NET application, I need to do some changes on every CSS file sent.So I created an HttpHandler (inside the app itself), added:

<add verb="*" path="*.css" type="MyWebsite.CssTestHandler,MyWebsite"/>
to Web.config in system.web/httpHandlers and modified the handler like this:
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
text.Response.Write("Hello World");
context.Response.End();
}

View 3 Replies

Using HttpHandler & HttpModules?

Apr 9, 2010

i know how to implement this thing..

but i have few question like..

wot is the major purpose of using HttpHandler & HttpModules..

and how they work with page life cycle..?did they get executed b4 page life cycle..?where i got more control and more power

in order to utilize HttpHandler & HttpModules..

View 5 Replies

What ASHX HttpHandler Uses For

May 25, 2010

Can u explain me what ASHX HttpHandler uses for?

View 7 Replies

ViewState In A HttpHandler?

Apr 9, 2010

I have an aspx page that I want to convert to an HttpHandler, but I'm struggling withewState that's been used in the code behind of the aspx page

View 2 Replies

Authentication In .NET HttpHandler?

Sep 1, 2010

I have created a HttpHandler to be used with SWFUpload to upload images to the server. This upload is done in an administration backend so users need to be authenticated to upload images.Initially I made the whole administration area deny annonymous users but because of the way SWFUpload appears to work it wouldn't work correctly with Forms authentication and would return a 302 status code.I had thought it would be possible to make the location of my handler public in Web.config and use context.User.Identity.IsAuthenticated in my handler to determine if the user is logged in.

View 3 Replies

How To Tell Who Called An HttpHandler

Sep 10, 2010

How can I tell from within an ASP.NET HttpHandler if it is executing because of a call to Server.Execute("myHandler.ashx")or because of the user linking directly to myHandler.ashx? (Besides using a querystring parameter).

View 2 Replies

Httphandler And Httpmodule In .net?

Jan 7, 2011

As i know that asp.net fulfill all the requirements for any web application but what are the ground rules for creating custom httphandler and httpmodule in asp.net.Edit:For example I want to fetch image from database then what i should i use httphandler or normally read image from database.If httphandler then why?

View 4 Replies

How To Test .net Httphandler

Jan 28, 2011

Im trying to write a small web application for forwarding requests to my page to the new pages on my web site. First off im implementing a IHttpHandler and in the ProcessRequest method i simple want to print out the requesting page, my conde looks like this:

public class RedirectHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
[code]...

View 1 Replies

C# - Httphandler In .net Return A Value?

Nov 26, 2010

Can a httphandler in .net return a value? If yes how?

View 2 Replies

MVC :: Communication Between HTTPHandler & Controller

Jan 15, 2011

So I am working on a project in ASP.NET MVC 2 with C#.I have a View with a file upload but this is a flash component (.swf).The result of the file upload (the storing of the file and processing of data in the database) is done in a HTTPHandler.I would like the HTTPHandler to send information to my active controller.

Is there a way to get the controller that was used to load the view? I'm having problems finding information about it online.

View 1 Replies

Encrypt Querystring Using HttpHandler

Feb 24, 2011

How to encrypt querystring using HttpHandler?

View 1 Replies

Configuration :: HttpHandler Two Web.config

Apr 1, 2010

I have an website in IIS 6.0 (windows 2003). Inside that I had configured another application (As IIS Application).

Now, When I uncommend a "add verb" tag in main web.config file, the webservice inside the application throws "404 file not found exception" Is there anything which I need to update in child web.config?

View 1 Replies

Caching The Xml Response From A HttpHandler

Mar 15, 2010

My HttpHandler looks like:

[Code]....

How can I cache the entire xml document that I am generating?

Or do I only have the option of caching the DataTable object?

View 1 Replies

HttpHandler And Session State?

Sep 3, 2010

I'm trying to fashion a solution which will simulate App_Offline.htm for remote access but still allow local users to test the website out. I found some various options that I am trying out but the best one doesn't seem to work for our ASP.NET(2.0) site which relies on session state being enabled on all of the pages.

The HttpHandler is added into web.config

<add verb="*" path="*.aspx" type="AppOffline.AppOfflineHandler, AppOffline" />

and when the class is called, it boils down to this:

public void ProcessRequest( HttpContext context )
{
this.context = context;

[code]...

View 1 Replies

Will .NET HttpHandler Trigger Page_Load

Jun 21, 2010

<asp:Image ID="imgVerify" Width="60" Height="18" runat="server" align="absmiddle" Style="border: 1px solid #999999" ImageUrl="/Common/GetCaptcha.aspx" />

It'll also trigger Page_Load() of abc.aspx. Is this that true? And if it is, can I avoid it?

View 1 Replies

HttpHandlers / Modules :: What Is Httphandler In .net

Mar 3, 2010

what is httphandler?what is the use ?

View 7 Replies

.net Httphandler Recursion Method?

Mar 25, 2011

I'm using the RssToolkit for .net. I'm using an Httphandler to return rss feeds. The feedID is passed in as a querystring parameter. If no parameter is passed in, I would like to have the the handler return a feed that is an aggreate of some of the feeds that the handler can handle. What I'm wondering is, can the handler recurse?

View 1 Replies

Httphandler - Embed ASP Web Application Into Another?

Apr 4, 2011

Providing web features through a custom HttpHandler such as in Elmah is extremely handy for ASP.NET Web Applications, because the handler can be embedded into any ASP.NET web app. It perfectly fits as a simple way to extend an existing web app. Now, developing any significant set of features through a custom handler is a very tedious process. I am wondering if it is possible to directly embed an ASP.NET Application into another one through a custom handler (as opposed to cut and pasting the whole app in a sub directory). Here is a small list of embedded web app that would be fit for such a purpose:

Health monitoring console. Provisioning console (for cloud web app with auto-scaling). App settings management console (considering a scheme IoC-settings-stored-in-DB). Each one of those web parts could be provided as an HttpHandler; but again implementation is really tedious. Does anyone know how to do that or how to achieve an equivalent behavior?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved