ihttphandler

How to catch a specific HttpException (#0x80072746) in an IHttpHandler

旧街凉风 提交于 2019-12-07 13:03:05
问题 It appears that this HttpException (0x80072746 - The remote host closed the connection) can be thrown if, for example, the user closes the window whilst we are transmitting a file. Even if we send the files in smaller blocks and check the client is still connected, the exception can still occur. We want to be able to catch this specific exception, to ignore it. The ErrorCode provided in the HttpException is an Int32 - too small to hold 0x80072746, so where do we find this number? 回答1: Int32

How to catch a specific HttpException (#0x80072746) in an IHttpHandler

北慕城南 提交于 2019-12-06 00:32:26
It appears that this HttpException (0x80072746 - The remote host closed the connection) can be thrown if, for example, the user closes the window whilst we are transmitting a file. Even if we send the files in smaller blocks and check the client is still connected, the exception can still occur. We want to be able to catch this specific exception, to ignore it. The ErrorCode provided in the HttpException is an Int32 - too small to hold 0x80072746, so where do we find this number? Int32 is not really too small to hold 0x80072746; only in “normal” notation, this number is negative: 0x80072746 ==

Should I set IsReusable to True in my HttpHandlers?

谁都会走 提交于 2019-12-04 17:20:46
问题 I've never fully understood this property of the IHttpHandler. It is a property that you have to set when you implement the interface. I've assumed that setting it to true would be better for performance, but I am not sure what the negative side effects might be. Should I return true or false? 回答1: It is used to indicate if a single instance of the IHttpHandler will be used to process multiple concurrent requests. So if you set it to true it will improve performance but you must make sure

Unbuffered output from IHTTPHandler

Deadly 提交于 2019-12-04 13:32:36
I want to stream data from an IHttpHandler class. I'm loading a large number of rows from the DB, serializing, and compressing them, then sending them down the wire. On the other end, I want my client to be able decompress, and deserialize the data before the server is even done serializing all the objects. I'm using context.Response.OutputSteam.Write to write my data, but it still seems like the output data is being put into a buffer before being sent to the client. Is there a way to avoid this buffering? The Response.Flush method should send it down the wire; however, there are some

How to obtain a reference to the default ASP.NET page handler or web-services handler?

时光怂恿深爱的人放手 提交于 2019-12-04 07:27:04
Consider a Web.config file containing the following httpHandlers declaration: <httpHandlers> <add verb="*" path="*" type="MyWebApp.TotalHandlerFactory"/> </httpHandlers> In other words, this handler factory wants to “see” all incoming requests so that it gets a chance to handle them. However, it does not necessarily want to actually handle all of them, only those that fulfill a certain run-time condition: public sealed class TotalHandlerFactory : IHttpHandlerFactory { public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { if (some condition

Sending XML data via HTTP POST to IHttpHandler causes HttpRequestValidationException

前提是你 提交于 2019-12-04 04:51:44
问题 I'm writing an IHttpHandler implementation that will receive XML data sent through a regular HTTP POST from another website. Here's a prototype of the implementation: public class MyHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string s = context.Request.Form["input"]; // <== this throws HttpRequestValidationException XmlDocument doc = new XmlDocument(); doc.LoadXml(s); // ... } public bool IsReusable { get { return false; } } } I'm testing the implementation with

Streaming large video files .net

隐身守侯 提交于 2019-12-04 01:26:23
问题 I am trying to stream a large file in webforms from an HttpHandler. It doesn't seem to work because its not streaming the file. Instead its reading the file into memory then sends it back to the client. I look all over for a solution and the solution are telling me that they stream the file when they are doing the same thing. My solution that stream is this: using (Stream fileStream = File.OpenRead(path)) { context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(360.0)); context.Response

POST json object array to IHttpHandler

江枫思渺然 提交于 2019-12-03 21:52:26
Im constructing an array of objects like this: var postData = []; $.each(selectedFields, function (index, value) { var testTitle = 'testing ' + index; postData.push({title: testTitle, title2 : testTitle}); } I then post it like this(note that i have tried a number of different aproaches): $.post('SaveTitlesHandler.ashx', { form : postData }, function (data) { console.log(data); }); I then try to get the data in a handler... public class SaveTitlesHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string json = context.Request.Form.ToString(); } } I cant seem to get

ASP.NET C# OutofMemoryException On Large File Upload

痞子三分冷 提交于 2019-12-03 16:39:45
I have the following file upload handler: public class FileUploader : IHttpHandler { public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; context.Response.ContentType = "text/html"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); var tempPath = request.PhysicalApplicationPath + "\\Files\\TempFiles\\"; byte[] buffer = new byte[request.ContentLength]; using (BinaryReader br = new BinaryReader(request.InputStream)) { br.Read(buffer, 0, buffer.Length); } var tempName = WriteTempFile

Should I set IsReusable to True in my HttpHandlers?

馋奶兔 提交于 2019-12-03 11:14:23
I've never fully understood this property of the IHttpHandler . It is a property that you have to set when you implement the interface. I've assumed that setting it to true would be better for performance, but I am not sure what the negative side effects might be. Should I return true or false? It is used to indicate if a single instance of the IHttpHandler will be used to process multiple concurrent requests. So if you set it to true it will improve performance but you must make sure that your code is thread safe because the ProcessRequest method might be invoked from multiple threads at the