Why Does Custom HttpResponse Throw Exception On HttpResponse.End()

Jul 27, 2010

I'm writing some code in which I need to use my own HttpResponse object to capture the output from a method on another object that takes an HttpResponse as a parameter. The problem is, this other object (which I cannot modify) calls HttpResponse.End(), which causes an "Object reference not set to an instance of an object" exception to be thrown. What can I do about this?

Dim myStringbuilder As New StringBuilder
Dim myStringWriter As New IO.StringWriter(myStringbuilder)
Dim myResponse As New Web.HttpResponse(myStringWriter)

someObject.doStuffWithHttpResponse(myResponse) ' calls myResponse.End() and crashes

Here's some more complete information about the error, thrown from the following code in a console application:

Dim myStringbuilder As New StringBuilder
Dim myStringWriter As New IO.StringWriter(myStringbuilder)
Dim myResponse As New Web.HttpResponse(myStringWriter)
Catch ex As Exception
End Try

Here's the text of the exception:

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.HttpResponse.End()
at ConsoleApplication1.Module1.Main() in C:Documents and Settingsjoe.userLocal SettingsApplication DataTemporary ProjectsConsoleApplication1Module1.vb:line 10

View 2 Replies

Similar Messages:

C# - Read Specific Div From HttpResponse?

Feb 22, 2011

I am sending 1 httpWebRequest and reading the response. I am getting full page in the response. I want to get 1 div which is names ad Rate from the response. So how can I match that pattern?

My code is like:

HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://www.domain.com/");
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream response = WebResp.GetResponseStream();
StreamReader data = new StreamReader(response);
string result = data.ReadToEnd();

I am getting response like:

<HTML><BODY><div id="rate">Todays rate 55 Rs.</div></BODY></HTML>

I want to read data of div rate. i.e. I should get Content "Todays rate 55 Rs." So how can I make regex for this???

View 3 Replies

Use HttpResponse.End() For A Fast Webapp?

May 30, 2010

HttpResponse.End() seems to throw an exception according to msdn.Right now i have the choice of returning a value to say end thread(it only goes 2 functions deep) or i can call end().

I know that throwing exceptions is significantly slower (read the comment for a C#/.NET test) so if i want a fast webapp should i consider not calling it when it is trivially easy to not call it?

-edit- I do have a function call in certain functions and in the constructor in classes to ensure the user is logged in.So i call HttpResponse.End() in enough places although hopefully in regular site usage it doesn't occur too often.

View 2 Replies

Web Forms :: Can Use HttpResponse From An Ascx File

Feb 19, 2011

I am looking to render excel from an web control. I have code that works from a web page, but when I run it in an ascx.cs file it doesn't do anything.

Is there something about being in an ascx that makes a difference?

Here is my code:

Response.AddHeader("content-disposition", "attachment; filename=file.xls");
Response.ContentType = "application/vnd.ms-excel";

View 6 Replies

Intercept What's Being Written To HttpResponse.OutputStream

Feb 17, 2010

I am working on a tool which audits access to existing web application. Existing app does not have any hooks in place, but my plan is to inject an IHttpModule by modifying web.config and log whatever I need to log during EndRequest event.

What I'm struggling with right now is: I cannot intercept what is application writing to an output stream. I need to know what output does the application send to the client. Originally, I hoped I could run a code in BeginRequest to replace HttpContext.Response.OutputStream with a stream of my own, which would be flushed to original stream during EndRequest, but the stream only has a get accessor, so I cannot replace it.

I could of course use reflection to assign to private member of HttpContext.

View 2 Replies

C# - How To Read The HTML From An HttpResponse Object

Aug 1, 2010

I'm creating a custom module and I need to be able to read the html output that's written to the HttpResponse object. Can anyone provide direction on this?

View 2 Replies

Create Object Of HttpResponse Class?

Feb 11, 2010

how to create object of HttpResponse class

HttpResponse response=new
HttpResponse (TextWriter

how to inplement this wrong code to right one & how to implement TextWriter.

View 2 Replies

Saving HttpResponse / Request To File System

Mar 15, 2010

User fills out this large page which is dynamically created based off DB values. Those values can change. When the user fills out the page and hits submit we want to save a copy of the page as html on the server, this way if the text or wording changes, when they go back to view their posted information, it is historically accurate.

So I basically need to do this

protected void buttonSave_Click(object sender, EventArgs e)
//collect information into an object to save it in the db
bool result = BusinessLogic.Save(myBusinessObject);
if (result)
//!!! Here is where I need to save this page as an html file on my servers IFS!!!!

Also I CANNOT just request the data from the url because query string parameters are a big no no in this case. The key to pull the database info up (at its highest level) is all in session so I cant just request a url and save it.

View 2 Replies

Httpresponse - Why Are .docx Files Being Corrupted When Downloading From A Webpage

Mar 19, 2010

I have this following code for bringing page attachments to the user:


The problem is that all supported files works properly (jpg, gif, png, pdf, doc, etc), but .docx files, when downloaded, are corrupted and they need to be fixed by Office in order to be opened.

At first I didn't know if the problem was at uncompressing the zip file that contained the .docx, so instead of putting the output file only in the response, I saved it first, and the file opened successfully, so I know the problem should be at response writing.

View 3 Replies

Httpresponse - How To Handle Errors When Using C# To Create A Zipfile For Download

Oct 29, 2010

I'm working on a functionality in my asp.net web site that enables the user to download some files as a zip file. I'm using the DotNetZip library to generate the zip file.

My code looks like this:

protected void OkbtnZipExport_OnClickEvent(object sender, EventArgs e)
var selectedDocumentIds = GetSelectedDocIds();
string archiveName = String.Format("archive-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
AddResponseDataForZipFile(Response, archiveName);
string errorMessage = Utils.ExportToZip(selectedDocumentIds, arkivdelSearchControl.GetbraArkivConnection(), Response.OutputStream);
if (!string.IsNullOrEmpty(errorMessage)).......

Now, if anything goes wrong, say the Utils.ExportToZip method fails, I want to present an error message to the user and not the download dialog. Do I have to remove some data from the Response object in order to cancel the download operation?

View 2 Replies

C# - Will HttpResponse - Filter Buffer The Whole Data Before Start The Sending?

Apr 6, 2010

An user posts this article about how to use HttpResponse.Filter to compress large amounts of data. But what will happen if I try to transfer a 4G file? will it load the whole file in memory in order to compress it? or otherwise it will compress it chunk by chunk?

I mean, I'm doing this right now:

public void GetFile(HttpResponse response)
String fileName = "example.iso";
response.ContentType = "application/octet-stream";


So at the same time I'm reading, I'm compressing and sending it. Then I wanna know if HttpResponse.Filter do the same thing, or otherwise it will load the whole file in memory in order to compress it. Also, I'm a little bit insecure about this... maybe is needed to load the whole file in memory to compress it... is it?

View 1 Replies

Web Forms :: Accessing HttpResponse Page.Response From A Class Instead Of Cs File?

Oct 18, 2010

I have an issue with trying to create a Pdf file from my webpage. Basically, everythig involving creating the Pdf (using iTextSharp) is done, and I'm doing this as a File Stream (i.e, I'm saving the Pdf on local machine). Now what I'm trying to do is create it as a Memory Stream (i.e, open the Pdf from the browser). I was able to do this earlier when I wa still at the 1st version of the application, and all of the code behind was incluced in my .aspx.cs file. But now, I've kept the code in the .aspx.cs at a minimum and put the cude in classes and I'm creating onjects of thoses classes from the .aspx.cs

The problem is that the code from creating the Memory Stream is in a class as follows:


As you can imagine, the compiler cannot recognise "Response" as it's in a seperate class instead of in .aspx.cs

View 5 Replies

C# - No Trailing Slash In Hostname, HttpResponse.RemoveOutputCacheItem Doesn't Work?

Feb 19, 2011

I have an action for which the output is fairly static, until another action is used to update the datasource for the first action. I use HttpResponse.RemoveOutputCacheItem to remove that action's cached output so that it is refreshed next time the user loads it.Basically I have an action like this:

[OutputCache(Duration=86400, Location=OutputCacheLocation.Server)]
public ActionResult Index()
return ...


View 3 Replies

Web Forms :: Trying To Create An Instance Of System.Web.HttpResponse To Send The Uers To Another Website?

Jul 11, 2010

I am trying to create an instance of System.Web.HttpResponse to send the uers to another website.I am doing some other stuff in my vb.net that does not let me use the regular Response.Redirect.when I do Dim myRsp As System.Web.HttpResponse = New System.Web.HttpResponseit complains about a textwriter.

View 4 Replies

Unable To Throw Custom Error Handler From Within An Exception / "UnableToOpenDatabaseException Was Unhandled"

Jul 25, 2010

Why can't I throw a custom exception from within an Exception? In code below, I get error msg "UnableToOpenDatabaseException was unhandled" even though I have catch statement for it. What am I doing wrong? and how to fix it?


View 3 Replies

WCF / ASMX :: How To Execute WebService Asmx Link From Default.aspx Page Link Using HTTPRequest And HTTPResponse

Nov 3, 2010

I have spent a couple of days on this one. I have an ASP.NET website that has Linkbuttons on

the Default.aspx page.. I added a WebService to the Website because later on the WebService will

subscribe to a Provider(Feed) of News, Sports and Weather and things like that. So when a Linkbutton

on the Default.aspx page is clicked it will connect to the link in the WebService which will load the News,

Sports or Weather onto the Default.aspx web page.

The problem is I can't get the LinkButton to execute the Link in the WebService. The link will call the page up

to where you see all of the Web References. But then if you want to execute one of those references you

have to click its link and the Invoke button that will follow. My questioh is how can the link on my Default.aspx

page execute the link in the WebService. Now I changed the LinkButton into an <a href> but I still can't execute

the link in the WebServices. I always use www.Microsoft.com as the link when testing and I wasn't sure about the return type

so I put "void" for an HTTPRequest, so below is the link from the Default.aspx web page and below that is he asmx file:


View 2 Replies

How To Throw And Catch Exception Handling

Oct 12, 2010

iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
if (updaterec > 0)
running = true;
DataSet BillContainerDetails = BillingDetails();
byte[] ContainerDetails = GenerateBill(DBmgr, sContainerIds, rcno,isGeneralRCNo, FetchContainerDetails, ModifyId,ref BillContainerDetails);
//string otherchargesId = obj.retriveSingleRecord("select top(1) ModifyId from ASOtherCharges");
DBmgr.AddParameters(0, "@InvoiceNo", "1","IN");
DBmgr.AddParameters(1, "@BillDate", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"), "IN");
DBmgr.AddParameters(2, "@CustomerId", "1", "IN");
DBmgr.AddParameters(3, "@TotalAmount", "10000", "IN");
DBmgr.AddParameters(4, "@OtherChargesId", ModifyId, "IN");
DBmgr.AddParameters(5, "@ContainerDetails", ContainerDetails, "IN");
String BillNo = DBmgr.ExecuteScalar (CommandType.Text, "Insert into BillMaster(InvoiveNo,BillDate,CustomerId,TotalAmount,OtherChargesId,ContainerDetails) values (@InvoiceNo,@BillDate,@CustomerId,@TotalAmount,@OtherChargesId,@ContainerDetails)
Select @@Identity ").ToString();
if (!String.IsNullOrEmpty(BillNo))
running = true;
for (int i = 0; i < BillContainerDetails.Tables[0].Rows.Count; i++)
BillContainerDetails.Tables[0].Rows[i]["BillNo"] = BillNo;
DBmgr.AddParameters(0, "@Billno", BillContainerDetails.Tables[0].Rows[i].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@rcno", BillContainerDetails.Tables[0].Rows[i].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@acontinerid", BillContainerDetails.Tables[0].Rows[i].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@bflag", BillContainerDetails.Tables[0].Rows[i].ItemArray[4].ToString(), "IN");
//string value = BillContainerDetails.Tables[0].Rows[i].ItemArray[0].ToString(); ;
// string strsql = "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)Select @@Identity").ToString();
if (count > 1)
running = true;
//running = true ;
for (int j = 0; j < BillContainerDetails.Tables[1].Rows.Count; j++)
DBmgr.AddParameters(0, "@billcontkey", BillContainerDetails.Tables[1].Rows[j].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@ratetypcode", BillContainerDetails.Tables[1].Rows[j].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@days", BillContainerDetails.Tables[1].Rows[j].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@amount", BillContainerDetails.Tables[1].Rows[j].ItemArray[4].ToString(), "IN");
DBmgr.AddParameters(4, "@level", BillContainerDetails.Tables[1].Rows[j].ItemArray[5].ToString(), "IN");
DBmgr.AddParameters(5, "@sflag", BillContainerDetails.Tables[1].Rows[j].ItemArray[6].ToString(), "IN");
// string strsql = "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)Select @@identity ").ToString()

View 2 Replies

Set Dynamic Controls So It Doesn't Throw Exception

Jun 28, 2010

I have problem with Dynamic Controls in my Wizard Steps. In one of my Steps, I create a set of text boxes and checkboxes based on values from an XML document. Now, I initialise my dynamic controls using the OnInit method of the page, but at this stage there is no xml document until that step is reached, and of course I get null exception. How do I set my dynamic controls so it doesn't throw an null exception and be able to load any xml document when that step is reached?

View 1 Replies

Global.Asax - When Click On Datagrid Throw Exception

Nov 4, 2010

I m having a datagrid and for client side events I m using Javascript. I have few other buttons in the same page.

when I click on datagrid and select, it is working fine. After that, if I click on any other button in the Page, It is directly going to global.asax and throwing exception.

If I click directly on other buttons, they are working fine. Once I click on Datagrid and try to click on other buttons, it is throwing that exception.

View 2 Replies

How To Throw Exception If Session Is Written To In ReadOnly Mode

Sep 3, 2010

I would like to find a way to raise an exception if the Session is written to when in readonly mode. When EnableSessionState is set to "ReadOnly", values can still be put in Session, but the next request they will not be there. This seems somewhat dangerous.

One option is to create a helper class which we alway use to access session. However, this still leaves room for a developer to inadvertently use session directly, and fall into the "readonly" trap. Is there a way to create a CustomSessionStateDataStore that sits on top of the existing session code? I could not see an obvious way, and you can't inherit from System.Web.SessionState.SessionStateStoreData directly.

View 2 Replies

DataSource Controls :: EntityDataSource Throw Exception When Update With Self-Reference?

Nov 3, 2010

For a Table A defined in the DB like this:

A :{ id, selfId, name,} where selfId is a foreign key refered to Table A itself.

I generated the Entity automatically like this:

A :{ string id; A self; string name,} when i update the entity in gridview Edit/Update CommandField

i got the exception:

Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:


Stack Trace:


I guess maybe this is caused by:

A is to be updated, and when the EntityDataSource construct the new A, the reference "self" is invalid at that moment. I do not want to modify my DB structure and do not want to lose the self reference, The event EntityDataSource_Updating is not triggered while the exception hit. so i can not access my entity at any time. Maybe the worst idea is deal the whole Update Procedure myself. However, is there any better workaround?

View 3 Replies

Web Forms :: DataSet.Fill Takes Along Time To Throw Exception When Connectionstring Wrong

Jan 18, 2010

when my website allow user many connectionstring by text to connect database anh retrieve data. But when user define very may wrong connectionstring. So Method in DAL dataset.Fill() takes a longtime to throw exception.So mywebsite will be die.

I want to method dataset.Fill() throws exception immediately when a connectionstring wrong. How can i do that?

View 2 Replies

Forms Data Controls :: Throw The Exception Back To Page_Load Error: ArgumentNullException Was Unhandled By User Code

Nov 19, 2010

I'm trying to throw the exception back to Page_Load but the throw statement causes error: ArgumentNullException was unhandled by user code. How can that be fixed? Also, I can't see Label1.Text displayed on the page after the ArgumentNullException occurs because the page is not re-load. If there is no exception, it's fine to not reload the page. How can I see the Label1.Text displayed?

protected void Page_Load(object sender, EventArgs e)
...do something here...
catch (ArgumentNullException ae)
Label1.Text = ae.Message;
Label1.Style.Add("visibility", "visible");
catch (Exception ex)
...do something here...
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)............................

View 3 Replies

IIS Throw Away URL Fragment On Custom Error Pages?

Nov 5, 2010

I'm using the old 404-rewrite method on a certain site that is tied to IIS6 *. So if I enter [URL] it calls my error page like so [URL]
Except if I call the page with a fragment, like [URL] I get the same result as above. I can't find the fragment anywhere:

headers, server variables, etc

This has come up because I want to resolve paths created by AJAX to their server-side versions. Is there any way for me to retrieve the original path from my handler?

View 1 Replies

WCF / ASMX :: Throw A Custom Message From A Web Service

Jun 24, 2010

I have a schema which contains the ErrorCode and ErrorDescription.

When error is captured i need to create a new xml and throw it to the client with the error code and description captured from the client

View 1 Replies

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