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


Similar Messages:

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

VS 2010 - Handling File Not Found Exception From HttpHandler

Oct 27, 2011

I'm using a HttpHandler to intercept PDF file download requests and modify the PDF file. I'm stuck on what to do if the requested file doesn't exist on the webserver. If I handle the Exception and return an empty response, it gives the user a 0 byte file to download. If I ignore the Exception, then ASP.NET catches it and the user is redirected to my unfriendly customError page.

View 9 Replies

MVC :: Exception Passing Data Into Partial View?

Feb 11, 2011

I have a page that I created using the Razor engine to allow updates to a database. One of the fields is a date time field, so I thought I'd try to implement a date picker.

So I was looking at a blog article here , and attepted to follow it through, and implement the suggestions within my code, but I get the following error"Value cannot be null or empty. Parameter name: name"

This is my main View

[Code]....

I read something about this being a bug in MVC2, but I'm using MVC3 and I was led to believe it had been fixed. Am I missing something here?

View 7 Replies

DataSource Controls :: Getting Exception / An Exception Occurred While Executing A Transact-SQL Statement Or Batch

Jan 1, 2010

i need to restore Database.mdf; I create a blank new database exactly the same name as the .mdf file. However, I could not restore the database.

The error message prompted was:

TITLE: Microsoft SQL Server Management Studio Express

An exception occurred while executing a Transact-SQL statement or batch.

(Microsoft.SqlServer.Express.ConnectionInfo)

ADDITIONAL INFORMATION:

Cannot open backup device 'C:inetpubwwwrootTCPSystemApp_DataDatabase.mdf'. Operating system error 32(error not found).

RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3201)

click: [URL]

BUTTONS:

OK

View 10 Replies

Architecture :: How To Log Dal Exception And Showing Alert To User / Exception Occurs

Aug 3, 2010

I am working on a 3-tier asp.net application. Currently I'm stuck up in a situation where I need to handle a specific type of exception (User Defined) in DAL and Show alert to the user if that exception occurs in DAL.

I tried following things:

1) I raised that exception from the DAL and catch it in BLL and throw a new BLL exception to for that DAL exception and finally catch it in the UI layer to show the alert to the user. I've successfully implement this in my project. But there are some issues in this approach. First of all I feel this is not right way to do this as it may lead to performance related issues. Secondly, the application contains more than 500 pages and classes. so I need to attach additional catch block in every method to catch the BLL exception. which is the last option i'd like to take.

2) in second approach I logged the the DAL exception into a text file. but problem in this approach is that how could the UI layer know that exception has occurred and show the alert to the user. Is there any event in asp.net where i could handle all this activities?

my question is what is the best approach to handle this type of situation? Will Exception handling block help me in this?

I've tried reading many articles on this but i couldn't get an answer for my question? I might not be using right keywords for my search.

View 4 Replies

C# - How Do I Get Specific Details About An Exception From A General Exception Class Object

Feb 4, 2010

In ASP.NET,How can i know the Specific details about an exception (like What kind of Exception it is (FileNotFound /Arithmentc etc..) )from a General Exception class object.

View 2 Replies

C# - Exception Handling - Implement Custom Exception Classes?

Jul 2, 2010

i have this application structure:

1. Presentation Layer which calls

2. Business Logic Layer which in turn calls

3. Data Access Layer to do the dealing with the database.

Now i have a Contacts page from where i can add a new contact to the database.So to add a New Contact i fill in all the required details and then call a Add Method (residing in the BLL) from the page, which in turn call a Add Method residing in the DAL.this method in the DAL returns the Current Identity of the record which is then return back to the BLL method and finally delivered on the page.this is fine. but what if a get an exception how do i handle it properly because the method in DAL has a return type of int and i dont want to throw another error!! coz other wise i will have to write try catch in almost all the methods.

//something like this
public int AddMethod(ContactClass contactObj)
{
int result = 0;[code]...

rather i want to show the user a user-friendly message which they can easily understand and in the mean while i will send a mail to myself documenting the Error that just occurred.how can i implement my custom exception classes.

View 2 Replies

Ways To Identify A Particular Exception From Exception Class?

May 18, 2010

Is there any way to uniquely identify a particular exception from the general exception class.

i.e any property or method that retrieves a unique identifier that to identify a particular exception.

I have kept some error values and corresponding error texts in an xml file. I want to read that xml file and have to taken the error ids and fix the corresponding texts to a label. in the case of a system exception we have to identify a particular exception.

View 1 Replies

WCF / ASMX :: Difference Between Exception And Fault Exception?

Jul 18, 2010

Difference between Exception and Fault Exception..?

Can i use Fault Exception when i get the Exception.

View 5 Replies

C# - Exception Is Like The Padding Is Invalid And Cannot Be Removed Exception?

Jul 12, 2010

We're getting this InternalSubStringWithChecks exception with our application's healthMonitoring. This exception is like the Padding is invalid and cannot be removed exception where it's being recorded and we're getting a notification email but the end user is unaware that an actual error has happened. Though we don't want our event log filled up with this rubbish! The stack trace is:

Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest
[code]...

View 1 Replies

Console Application Calling Datalayer Throws An Exception "The Type Initializer For Threw An Exception."

Aug 17, 2010

I have simple 3 tier web application and have mostly CRUDE functionalities. Recently I required to add new console application to the existing solution in which I call data layer methods for retrieving data from DB but I get an exception "The type initializer for threw an exception."When I debugged I found that the exception is thrown at datalayer on first line of class where I get connectionstring from

web.config, the code is public static readonly string CONNECT_STRING =

ConfigurationManager.ConnectionStrings["DbConnectString"].ConnectionString;

Now if I hardcode the connection string value like public static readonly string CONNECT_STRING = "Data Source=XYZ;uid=sa;password=XXX;initial catalog=ABC;"

it works fine.I don't understand what is the issue here as web application works fine with this datalayer.

View 2 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







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