C# - Application_Error Exceptions Handling, Redirection Infinite Loop And CSS Loading?

Oct 9, 2010

I have error handling in Application_Error event of globals.asax file. Inside this event, I'm using Response.Redirect(~errorview.aspx) method, for redirection to site which is able to handle errors in user friendly way.

Everything works fine, unless exception is rising in Application_Start event. When error occurs there, my application gets trapped in infinite loop with the Application_Error method hit repeatedly. What is more, the page I'm redirecting to never gets hit. Changing Response.Redirect(~errorview.aspx) method to Response.Redirect(~errorview.aspx, false) changes nothing.

The good news is, when Response.Redirect(~errorview.aspx) has been replaced with Server.Transfer(~errorview.aspx), errorview.aspx page succesfully gets hit.

The side effect now is not loading CSS, and errorview.aspx page looks ugly. What is more, the CSS is not loaded only when exception occurs in Application_Start event. Exceptions thrown from any other place don't make the CSS mess.

How I can handle this problem in correct way, and why the CSS is missing in the one particular situation ? What is the appropriate way of handling errors in my case ?

UPDATE

For CSS loading, I'm using this:

<link href="~/Css/Layout/style.css" type="text/css" rel="stylesheet"
runat="server" ID="_uid" />

error page I'm transfering from: http://localhost/APP/Pages/Module/Pages/ErrorView.aspx

css folder path: http://localhost/APP/Pages/Module/CSS/Layout/style.css

View 2 Replies


Similar Messages:

State Management :: Using Application_Error For Redirection / Application_Error To Redirect The User To A Custom Error Page?

Oct 11, 2010

I am trying to use the Application_Error to redirect the user to a custom error page. I know I could use the web.config to do this, but let's assume for now that this is not a desirable path to take.

Initially, I tried to do a Response.Redirect to perform this, however, there seem to be occasions where the current http context does not define the response object. So, I attempted to perform a check to make sure that the response object is not null prior to attempting the redirection, and if it is not defined, perform a Server.Transfer instead.

What happens is that in most cases, the Redirect causes the browser to some generic "friendlyish" error page rather than the requested error page.

So then I tried using Server.Transfer exclusively, and this worked well for most cases, however, sometimes the transfer didn't seem to take in the browser. Changing it back to a redirect in these cases solved that problem, but reintroduced the issue where the errors previously being captured and transferred now were being redirected.

What I surmised from this is that in certain contexts where the Application_Error method is trapped, it is necessary to use Server.Transfer in redirection, whereas in others, it is necessary to use Response.Redirect. The question then became twofold: (a) When is one necessary and when is the other? and (b) What available information can I poll to tell me when a given condition exists.

After much searching, I cannot find a reasonable answer to this question. So I began to trap errors and examine the HttpContext object for some indicator. One thing that I was looking for is the reason why if even with a defined Response in the current context does a redirect fail. The only thing that stood out is that even though a Response object may exist, the Session data could be absent. I added the case to check whether the Session data was null and perform a Transfer in this case and it
seems to be handling it properly.

I emphasize "seems to be handling it properly" because no documentation I've been able to find confirms either the problem I am having or whether this is an appropriate strategy for solving it.

I guess the question is, am I on the right track here or is the null Session object just a red herring, indicative of nothing relevant. Here's the check I have set up for reference.

[Code]....

View 2 Replies

Web Forms :: Exceptions From Business Logic Layer Not Caught In Application_Error?

Nov 11, 2010

I know there are a few posts on this issue already, however I haven't found the answers I was really looking for.

My situation is like this: I have a DLL project containing my business logic. Then I have a web application that refers to this DLL, and calls a function from it. And I have a global.asax which handles errors on Application_Error

Sample:

// MyWebsite.aspx.cs
using MyBusinessLogic;
protected void Page_Load(object sender, EventArgs e)
{
MyBusinessLogicClass.DoSomething();
}
// global.asax.cs
protected void Application_Error(object sender, EventArgs e)

[Code].....

View 6 Replies

Exceptions - Catch In Page Or Handle In Global.asax (Application_Error)

Jan 27, 2011

Looking for best practice focused answers here with explanations.

Should the presentation layer of an ASP.Net app catch and handle exceptions thrown from the business layer, or should these be allowed to bubble out, where they can all be logged and handled uniformly in the Global.ascx's Application_Error handler?

[code]....

View 2 Replies

Infinite Loop With HTTP 401 Status?

Jul 7, 2010

I wrote an ASP.NET page that requires HTTP Basic authorization, which I put in the Page_Load function:

void Page_Load(object sender, EventArgs e)
{
string auth = Request.Headers["Authorization"];
if (string.IsNullOrEmpty(auth))
{
Response.StatusCode = 401;
}
else
{
string[] usernameAndPassword = Encoding.UTF8.GetString(Convert.FromBase64String(auth)).Split(':');
string username = usernameAndPassword[0];
string password = usernameAndPassword[1];
Login(username, password);
}
}

When I try to view the page in a browser (either Firefox or IE), it asks me for the username and password, and then...asks me for the username and password again.

Why does this happen, and how can I fix it?

View 1 Replies

C# - Forms Authentication Infinite Loop?

Sep 19, 2010

I have an application that works great on localhost with forms authentication.I deployed it to the deployment machine and it to the build machine and received and endless set of 302 redirects.I try logging onto the deployment machine and access the page via the deployment machines ip and it works again.So it is not working when I try and access the site from my computer to the build computer.

View 4 Replies

Web Forms :: Infinite Loop From Random Class?

Feb 17, 2010

Infinite loop from random class?

[Code]....

View 4 Replies

SQL Reporting :: Web Report Causing An Infinite Loop?

Aug 3, 2010

I am having problems moving my reports from VS2008 to VS2010. I have made several WEB reports in VS2008 that use the code below on the load event of the WEB page to provide a data for the report and they all work correctly. I have to use this method of providing data because I am using several complicated queries that brake the VS2008 and VS2010 wizard.

When I try to convert over to VS2010, the report loading message flashes on the screen and the report never loads. I have run this code in debug and found that it is causing an infinite loop. After the code runs, the load event fires again. I tried adding an exit sub at the end of the code for a test but it has no effect.Below is a sample of the code that I am using with a simplified query and names.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Declare connection string.
Dim cnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString.ToString [code]...

View 2 Replies

Web Forms :: __doPostBack Infinite Loop Using Onfocus?

Feb 15, 2011

I am calling a method with __doPostBack using the OnFocus event for the controls. However I need to update the values multiple controls when the server method executes. This actually causes on focus to keep firing. Looking for help. I tried using TextBox1.Attributes.Remove("onfocus") and then adding it the javascript after processing but it still keep looping. Here is a sample using to textbox's for simplicity:

HTML

[Code]....

Code Behind:

[Code]....

View 3 Replies

MVC :: RC2 Client-Side Validation Infinite Loop Bug?

Mar 3, 2010

I've found a bug with RC2's client-side validation that causes an infinite loop (at least in IE7).Basically, if you create a standard ASP.NET MVC 2 RC2 web application template and then modify the LogOn.aspx view to this:

[Code]....

Note the new table that has been placed around it.Now, when you fire it up in IE7 and hit "Log On", the whole browser freezes and goes into an infinite loop.I have narrowed this down to the use of OnPropertyChange and the setting of the CSS classes for the elements themselves. It seems whenever an element is in a table, and you change its CSS class, the OnPropertyChange event fires with the property of "value" (which fires the entire process off again hence the endless loop).This is reproducable for me in IE7 (I haven't tested FireFox, IE6 or IE8).

View 1 Replies

AJAX :: CascadingDropDown Infinite Reload Loop In Webkit?

Jan 4, 2010

Using VS2005, VB code behind, I have a page with two DropDownLists and corresponding CascadingDropDown's. I want to automatically postback when the second DropDownList index changes, therefore I have set its AutoPostBack="true". I have wired up the web services and the lists are getting populated as expected in IE7+, FireFox and Opera, but when I view the page in a WebKit based browsers (Chrome, Safari) the CascadingDropDown appear to load in an infinite loop. I included theWebkit compatibility fix but the issue persists. I've attached a working example below.Anyone know why Webkit browsers are infinitely reloading the cascading dropdownlists? Is there a fix?Source code below:Markup:

[Code]....

Webkit.js

[Code]....

Code Behind:

[Code]....

Web Services Markup:

[Code]....

View 3 Replies

AJAX :: Numeric UP/Down Extender Causes Infinite Page Load Loop?

Aug 14, 2010

I have fought a bizarre situation for days. Anytime a certain listview loaded the page went into an infinite loop of reloading. I was finally put the listview on a page with nothing else to see if I could isolate the issue.Even with only the folowing code, it continually looped on load even though it brought in the correct data every time.

[Code]....

[Code]....

View 1 Replies

Configuration :: Handling Errors In Global.asax - Application_Error Fires Twice

May 25, 2010

I am handling errors in Global.asax. When I encounter an error in certain pages, the Application_Error event fires twice. On the second trip, Server.GetLastError() returns null. I have a simple page where I throw an error in page load. When that page throws an error the code below works fine. I also have a more complex page with an update panel and many controls. When that page throws an error Application_Error fires twice. I suspect the update panel but update panels are always suspect, right?

There are no try/catch blocks on any of my pages I'm testing with. Custom errors in web.config is commented out. Note that logging and busywork in the Application_Error event are commented out. I'm pretty much just doing a respone.redirect. The problem with the the event firing twice is that the response.redirect fails with an error msg stating that headers have already been sent (adding Context.ClearError and Response.Clear does nothing to fix that).

View 20 Replies

C# - Handling Asp.net Datasource Exceptions

Apr 4, 2011

I have a datasource that uses a business logic object for the select event. How can I catch an exception that occurs in the business logic layer and pass it to my presentation layer to display to the user in a label?

View 1 Replies

Handling Exceptions That Happen In A MVC Controller Constructor?

Apr 22, 2010

What's the best way to handle exceptions that happen from within a controller's constructor?

All I can think of to do is use Application_OnError() or put a try/catch in my ControllerFactory.

Neither of these solutions seem ideal. Application_OnError is to broad - I have some non-mvc content in the site that has its own error handling. Using a try/catch block seems kinda hacky.

If I'm serving different content type -html/text/json/rss.... I would like to be able to handle the exception from within the action method instead of having to write all kinds of conditions to determine what kind of error message to serve.

View 1 Replies

Globally Handling Exceptions In Static Aspx [WebMethods]

Mar 16, 2011

The default behavior of a [WebMethod] attributed static method on an aspx page is to return the error to the caller. We are accessing these methods using json, and the only way we have found of capturing exceptions is either a try/catch in every webmethod on the site or using a javascript callback with the error (which has the unacceptable downside of exposing the error to the client).

Is there any way to globally handle these exceptions using the HealthMonitoring setup in ASP.NET?

View 1 Replies

Web Forms :: Handling Exceptions / Sending Error Message

Nov 24, 2010

I have what is probably a basic question, but I am rather new to writing exception handling code. I thought I understood the concept, but apparently I don't, heres the code:

[Code]....

If I enter in any non-integer values, the textbox is set to nothing and the label displays the error message. However, now that I have verified the textbox contains an integer, I want to continue on and use that value. The remaining code works fine unless there was an exception, in which case the conversion to an int value for x throws an error.

All the examples I have looked at demos the structure of try-catch-finally, but in this instance I am not performing any clean up, I want to execute code when a valid value is entered into the textbox.

View 5 Replies

Configuration :: Error Handling Strategy For Exceptions Causing Page Request Fail?

Nov 1, 2010

I have been tasked with implementing a strategy to catch all errors in an ASP.net application which cause a user request or interaction to crash and then e-mailk this exception to a support team in advance of a user calling about the error.Some errors however are not causing the page to crash or be redirected to the custom error page but these are being emailed to the support team instead of simply being loggedMy requirement is to seperate what exception types will cause a page fail and which will not.Example I am currently receiving a System.Web.HttpUnHandledException which is not causing any page to fall over and therefore is not of relevance to the support team. this can be logged but does not require emailing.

View 1 Replies

Redirect - Custom Errors With Mode=remoteOnly And Global.asax Handling Exceptions?

Jul 19, 2010

I have custom errors set in the web config file as follows:

<customErrors mode="RemoteOnly" defaultRedirect="GenericError.aspx" />

Fine and dandy... I like that mode="RemoteOnly" facilitates development...

For unhandled exceptions, I have in global.asax:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("GenericError.aspx")
End Sub

However, unhandled exceptions are going to the generic error page instead of the informative yellow screen of death preferred by developers. I can comment out the redirect in global.asax, but then I need to remember to change it for the production environment. Is there a way I can check in Application_Error whether I am remote or not to determine whether to redirect?

View 2 Replies

Web Forms :: Handling Field Validations With Loading Progress

Mar 22, 2013

How to validate jquery which has been written in code in following link

[URL] ....

View 1 Replies

How To Handle Exceptions In A 3-tier Web Application - Specifically Sql Database Exceptions

Jan 26, 2010

I'm building the standard 3-tier ASP.NET web application but I'm struggling as to where to do certain things - specifically handling exceptions.

I've tried to have a look around on the web for some examples but can't find any which go as far as a whole project showing how everything links together.

In my data-tier I'm connecting to SQL Server and doing some stuff. I know I need to catch exceptions that could be raised as a result but I'm not sure where to do it.

From what I've read I should be doing it in the UI tier but in that case I'm not sure how to ensure that the connection to the database is closed. Is anyone able to clarify how to do this? Also if anyone knows as to where I could find an example 3-tier web application that follows best practices that would be great too.

View 4 Replies

Distinguish Between Internal Exceptions And Real Exceptions?

Dec 9, 2010

We have a asp.net application and want to implement logging. The first idea was to use the Application_Error method in the global.asax file.

The problem is that ASP.NET very often seem to throw exceptions internally that are not caused by the application and which seem not to interfer with the users normal workflow. For example we often get HTTPExceptions, UnauthorizedAccessExceptions and others caught in this method, although there is no real error in the application.

View 2 Replies

AJAX :: Infinite Width Of ValidatorCalloutExtender

Mar 7, 2011

I have create a textbox to be validated and a rangevalidator along with validatorcalloutextender to display the error message. All seems to work perfectly, until I realise that my validatorcalloutextender's pop-up has a width like infinite. I have tried diverse css style which I found in google, but still, the width of that validatorcalloutextender is like infinite (though I have set its width to width="20px")

View 6 Replies

Configuration :: Application_Error Is Not Executing?

Feb 21, 2011

I have writen error handling code in my Application_Error event in global.aspx page, but that event is not executed any time when error is occurring.So do I need to take care any other settings on my application to run this.

View 2 Replies

JQuery :: Infinite Scroll / Load External Content Into Element?

Jan 25, 2011

[Code]....

With the above syntax we can load content into a
[Code]....

when the user scrolls. But before inserting into the div I want to make sure that div is in the viewport area when the user scrolls down.

If yes then I would like to load external content into that
[Code]....

so tell me how could i detect which element is in viewport area by jquery when user scroll down then i can load external content into that element.

View 3 Replies







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