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);
try
{
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


Similar Messages:

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)
Try
myResponse.End()
Catch ex As Exception
Console.WriteLine(ex.ToString)
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

Create Object Of HttpResponse Class?

Feb 11, 2010

how to create object of HttpResponse class

HttpResponse response=new
HttpResponse (TextWriter
tx);

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

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

How To Handle Errors On Server Logs

Dec 30, 2010

I am seeing a lot of these errors on the server logs.

Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1309
Date: 12/29/2010
Time: 9:16:28 AM
User: N/A
computer: LFIWEB1
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 12/29/2010 9:16:28 AM
Event time (UTC): 12/29/2010 3:16:28 PM
Event ID: 7843d62e326c41f1a7c819ec2b362418
Event sequence: 549
Event occurrence: 7
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1733199574/Root/ComfortlinkNET-1-129381012604990336
Trust level: Full
Application Virtual Path: /ComfortlinkNET
Application Path: D:WebappsComfortlinkNet
Machine name: LFIWEB1
Process information:
Process ID: 3896
Process name: w3wp.exe
Account name: NT AUTHORITYNETWORK SERVICE
Exception information:
Exception type: InvalidCastException
Exception message: Conversion from string "cindye" to type 'Integer' is not valid.
Request information:
Request URL: xxxxxxxxxxxxxxxx
Request path: xxxxxxxxxxxxxxxxxx
User host address:xxxxxxxxxxxxxx
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITYNETWORK SERVICE
Thread information:
Thread ID: 1
Thread account name: NT AUTHORITYNETWORK SERVICE
Is impersonating: False
Stack trace: at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)

View 3 Replies

How To Handle Errors During Async Postbacks

Jan 5, 2010

We have an ASP.NET page which uses an update panel for partial page postbacks. On the server side, the postback performs some database work and updates several UI elements. The database code is all contained in several transactions, so the state will still be consistent if an exception is thrown. We're working on some error handling code now, and my first thought was to log the exception thrown, reload the last consistent UI state, and show some sort of modal popup or other ui element with a brief error message for the user (this is an intranet page, so we're automatically notified of the bug, and the users know where to find us.

View 1 Replies

C# - Handle Errors On Certain Pages Differently?

Mar 28, 2011

I have an Application_Error handler in my Global.asax file. However, I load many pages using an XHR request and would rather these "sub pages" return javascript or a real 500 code for my main app to process, rather than an error page.

Is it possible to handle errors on certain pages in a different way? Can a master page handle its own errors in a page extending it without bubbling it up to Global.asax?

View 4 Replies

Web Forms :: How To Handle 404 Errors When Using URL Routing

May 7, 2015

I have been using using System.Web.Routing for url routing in global.asax file  code is as below.

public static void RegisterRoutes(RouteCollection routes) {
routes.MapPageRoute("Home", "", "~/Home.aspx");
routes.MapPageRoute("Posts", "Posts/{blog_url}", "~/blog-description.aspx");
}
protected void Application_Start(object sender, EventArgs e) {
RegisterRoutes( RouteTable.Routes);
}

Now this works fine on local  but when i move the same to live it shows error 404 .I want to create a log actually what url is called.

View 1 Replies

How To Handle 403.9 HTTP Errors In The Web.config File

Nov 23, 2010

Do anyone of you know how to handle XXX.X IIS HTTP errors in a web.config file? I tried doing the following:

<customErrors mode="On" defaultRedirect="error.aspx">
<error statusCode="403" redirect="error403.aspx" />
<!--NOTE: The following does not work-->
<error statusCode="403.9" redirect="error403.9.aspx" />
<!--ENDNOTE-->
<error statusCode="404" redirect="error404.aspx" />
</customErrors>

But obviously that didn't worked, because the web.config file expects an integer as the statusCode value.
CONTEXT: WinServer 2003 - ASP.NET 3.5

View 1 Replies

ADO.NET :: Closing Sql Connection Properly And Handle Errors?

Mar 31, 2011

This morning I found myself dealing with A SQL POOLING ERROR Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. I did fix this with resetting my pooling and setting a pooling max =100 Anyway now Im starting to rethink how I open connections, dealing with errors and proper closing of connections Would you say this code below is a good way of opening, closing connections (even when errors occurred)

Dim Connection As SqlConnection
Dim myConn As String = (ConfigurationManager.ConnectionStrings("MyConnString").ConnectionString)
Connection = New SqlConnection(myConn)
Try
Dim DBCommand As SqlCommand
Dim dt As New DataTable()
Dim myDataSet As New DataSet
Connection.Open()
DBCommand = New SqlCommand("GetAllCategories_", Connection)
DBCommand.CommandType = CommandType.StoredProcedure
DBCommand.Parameters.Add("@HomePageID", SqlDbType.Int).Value = HiddenChosenVirtualMainID.Value
Dim mySqlAdapter As New SqlDataAdapter(DBCommand)
mySqlAdapter.Fill(dt)
SecondLevelChildDatalist.DataSource = dt
SecondLevelChildDatalist.DataBind()
Catch ex As Exception
'Error goes here
SqlConnection.ClearAllPools()
Finally
'close the connction
Connection.Close()
Connection.Dispose()
End Try

View 5 Replies

AJAX :: How To Handle Errors / Exceptions During Postback

Mar 27, 2010

I really want to switch over to ajax, but i can't seem to get my error handlling perfect. If i can't handle errors correctly, I just can't use it. What I really want to happen is to do a full refresh of the Top Frame. How I normally do this is by a similar call to Response.Write(<script>top.location.href = ""</script>). I was currently doing this in Global.asax. This becomes a problem when I error out in an AJAX postback. I've also noticed that There is an AsycPostbackErrorHandler you can attach to the ScriptManager. This is all find an dandy, but it will still hit my Global.asax Application_Error Event.

I am honestly just not sure how to handle this.

As I said, the result I want is....To Reload the Top Frame with some Error Message...whether I have to do some weird redirection or whatever. My problem lies specifically with the Global.asax file.

View 2 Replies

Handle Errors At Application Or Server Level?

Sep 28, 2010

When setting up asp.net error handlers for things like 404 errors, it is more 'efficient' to do this in IIS, or handle it in the Global.asax Application_Error event? I know the latter will be called, and I want to log this information in a database, but should I then just return without any redirect and let IIS do the redirect, or would it be better to do a response.redirect inside application_error once we've logged it?

View 1 Replies

C# - Handle All Errors/messages In One Place On Page?

May 7, 2010

On my site I put things in Web user controls. For example, I will have a NewsItem Control, an Article Control, a ContactForm control.These will appear in various places on my site.

What I'm looking for is a way for these controls to pass messages up to the Page that they exist on.

I don't want to tightly couple them, so I think I will have to do this with Events/Delegates. I'm a little unclear as to how I would implement this, though.

A couple of examples:

1: A contact form is submitted. After it's submitted, instead of replacing itself with a "Your mail has been sent" which limits the placement of that message, I'd like to just notify the page that the control is on with a Status message and perhaps a suggested behaviour. So, a message would include the text to render as well as an enum like DisplayAs.Popup or DisplayAs.Success

2: An Article Control queries the database for an Article object. Database returns an Exception. Custom Exception is passed to the page along with the DisplayAs.Error enum. The page handles this error and displays it wherever the errors go.

I'm trying to accomplish something similar to the ValidationSummary Control, except that I want the page to be able to display the messages as the enum feels fit.

Again, I don't want to tightly bind or rely a control existing on the Page. I want the controls to raise these events, but the page can ignore them if it wants.I'd love a code sample just to get me started.

I know this is a more involved question, so I'll wait longer before voting/choosing the answers.

View 3 Replies

Web Forms :: How To Handle Not Found Errors When Using URL Routing

May 7, 2015

I have a small problem:

Example:

RouteCollection routes
routes.MapPageRoute("Product","{ProductName}","~/Product.aspx")
Address on browser:
localhost:port/Software/VisualStudio

Error: HTTP Error 403.14 - Forbidden (because that Route is not exists).

How can i catch errors when routes are incorrect or not exist?

View 1 Replies

ADO.NET :: Handle Errors In Data Access Layer Code?

Feb 28, 2011

I am learning on how to create data access layer code for a web site. I want to ensure I am actually connecting to the datasource, so, I am wanting to use a try/catch block within my data access layer class methods. What I am not sure how to handle is a case where the connectionstate is not open. The method should ideally return a datatable. If an error is thrown would I just return an empty datatable? That is my first thought. My other thought is to return an object and pass a datatable if the connection succeeds or the exception if the connection fails.

View 10 Replies

AJAX :: Download The Control Toolkit From Codeplex / Getting An Errors

Apr 21, 2010

i downloaded the ajax control toolkit from codeplex, and followed the instructions to install it on my visual studio toolbox panel. then i just tried to use a calenderextender on a textbox.i get errors. i use visual studio 2008, windows xp sp2, .net
3.5.

this is my code:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> [code]....

when i run the page , i get the following error on the browser <html


Webpage error details,User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)
Timestamp: Wed, 21 Apr 2010 09:26:51 UTC


Message: AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll.
Line: 2
Char: 412
Code: 0
URI:
http://localhost:1975/LearnAjaxControlKit/ScriptResource.axd?d=7EpUrBYKJUxUvlaCKyczmnwIfd03hNqM0Z73JZEjtiK7woy5vZ9bqIneG9KNiH6H0&t=634064303120000000


Message: Object doesn't support this property or method
Line: 2
Char: 9702
Code: 0
URI:
http://localhost:1975/LearnAjaxControlKit/ScriptResource.axd?d=7EpUrBYKJUxUvlaCKyczmng9Qst_KL8215GZBigOiAwJKrFNmxZ21M_Z9YzWn1I3_LI-o-OYcARQmvjaTAEzyg2&t=634064303120000000


Message: Object doesn't support this property or method
Line: 2
Char: 27077
Code: 0
URI:
http://localhost:1975/LearnAjaxControlKit/ScriptResource.axd?d=7EpUrBYKJUxUvlaCKyczmm52CX_RWQFeSM7yLR_r3VD9wTjX79oGHdgUNySBlr8bM4Zb-RdVZFB4R31momZv7g2&t=634064303120000000


Message: 'Sys.Extended.UI.TextBoxWrapper' is null or not an object
Line: 2
Char: 456
Code: 0
URI:
http://localhost:1975/LearnAjaxControlKit/ScriptResource.axd?d=7EpUrBYKJUxUvlaCKyczmm52CX_RWQFeSM7yLR_r3VD9wTjX79oGHdgUNySBlr8bM4Zb-RdVZFB4R31momZv7g2&t=634064303120000000

View 4 Replies

Web Forms :: Handle Custom Errors Using Custom Error Page?

May 7, 2015

I want put custom error page in my website so I wrote below code in web.config

<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="error-404.aspx" responseMode="ExecuteURL" />
</httpErrors>

is it correct?

or I should put other code?

View 1 Replies

IE Errors On File Download Through .ashx File With Caching Turned Off?

Feb 1, 2011

I have a simple 'file download' generic handler which sets the response contenttype and headers before sending the file through the same response.

I also have Response.Cache.SetCacheability(HttpCacheability.server) set in the global.asax.

As I have noticed from various sources, Internet Explorer doesn't like this no-cache setting and gives an error when trying to download the file (requested site unavailable or cannot be found).

I thought maybe I could override this setting in the .ashx page, so I alter the response's cacheability setting to public. This did not solve the issue. removing the line from global.asax does solve the problem but obviously affects the whole site.

Is there a way of setting the cachability just for my generic handler?

View 1 Replies

.net - Lucene.net Create + Lock Errors In .NET?

May 26, 2010

-Edit- Important: I updated the code to not use obsoluete functions. Now only the NoSuchDirectoryException issue remains

Edit: NOTE i can bypass the NoSuchDirectoryException by creating the folder in a winform app and copy it. However i still have a LockObtainFailedException issue if i dont shut down properly.I have an issue with (Lucene.net 2.9.2

[https://svn.apache.org/repos/asf/lucene/lucene.net/tags/]. It throws a lock exception. After poking around i notice these things.

My code below works in an app bit when calling in Application_Start i get a NoSuchDirectoryException.Not closing the writer (as my code doesnt do below) i WILL get a LockObtainFailedException with the message

Lock obtain timed out: SimpleFSLock@<FULL_PATH> from either app or asp.net

These thread hinted when spawning threads they get less permissions then i do (but! my main thread has problems as well...) and one solution is to impersonate IIS. I am using visual studios 2010. I am not sure how full blown it is but my attempt to impersonate it failed.

So my question is how do i have lucene create the directory and not throw an exception if dont close the writer for some reason (such as power going out)?

http://stackoverflow.com/questions/2341163/why-is-my-lucene-index-getting-locked/2499285#2499285

http://stackoverflow.com/questions/1123517/lucene-net-and-i-o-threading-issue/1123981#1123981

static IndexWriter writer = null;
static void lucene_init()
{
[code].....

View 1 Replies

Application Hosted On IIS7 That Is Ignoring Custom Errors And Falls Back To IIS Errors?

Jul 2, 2010

I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ignored and it will fall back the IIS errors.

This gets entirely ignored

[code]....

This would be a minor inconvenience except that by the fact it falls back to IIS native instead of my application it completely circumvents Elmah logging my 404 exceptions correctly.

View 3 Replies

C# - Prevent Or Handle Time Out With XmlReader.Create(uri)?

Aug 23, 2010

Sometimes I am getting a time out exception when reading an XML via a URL. Is there something I can do to prevent this, or is this a problem with the remote server? Below is my simple code:

XmlDocument doc = new XmlDocument();
doc.Load(XmlReader.Create(this.RssUrl));

I do not know how to pass that setting into the code above (or if that is even the correct solution): [URL]

Exception Details: System.Net.WebException: The operation has timed out

Stack Trace:

[WebException: The operation has timed out]
System.Net.HttpWebRequest.GetResponse() +5375213
System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) +69
System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +3929371
System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54
System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext) +144
System.Xml.XmlReader.Create(String inputUri) +8

View 1 Replies

Web Forms :: Create One Subroutine To Handle All Deletes For Page?

Mar 5, 2011

I am trying to create one subroutine that can handle all deletes for a web app. I have one delete popup panel in my master page, and I call it each time from my content pages. When an instance of delete is called from a content page, I store the name of a delete subroutine specific to the delete instance in a session variable and popup the delete panel in the master page. If a user types YES into a delete textbox in delete popup panel, a confirmDelete Subroutine in codebehind of the Masterpage is called. When the confirmDelete subroutine in the Masterpage is callled, I want to call a subroutine in the content page that has the name stored in the session variable. What is the simplest way to do that?

View 1 Replies

C# - Create Method To Handle Multiple Types Of Controls

Mar 30, 2010

I am trying to create a method that accepts multiple types of controls - in this case Labels and Panels. The conversion does not work because IConvertible doesn't convert these Types.

public void LocationsLink<C>(C control)
{
if (control != null)
{
WebControl ctl = (WebControl)Convert.ChangeType(control, typeof(WebControl));
Literal txt = new Literal();
HyperLink lnk = new HyperLink();
txt.Text = "If you prefer a map to the nearest facility please ";
lnk.Text = "click here";
lnk.NavigateUrl = "/content/Locations.aspx";
ctl.Controls.Add(txt);
ctl.Controls.Add(lnk);
}
}

View 1 Replies

DataSource Controls :: Create And Handle Wide Tables Programmatically?

Apr 15, 2010

I have a set of keywords (about 1000 keywords), and I want to build a wide table, up to 1000 columns:

+each column corresponding to a keyword

+each row will represent an article document, which each cell will be the frequency of the keyword in the document

How to do that in a programmatically way? (e.g., using Linq and C#)

View 4 Replies

Web Forms :: Create Download Pop Up Box?

Apr 26, 2010

I need to create a button, which when clicked shows the download pop up box, but I don't know how, and would be grateful if someone could show me how? The box needs to work with any file type, the file name will be based upon a value from a database.

View 3 Replies







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