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
Similar Messages:
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
Mar 2, 2011
How can we prevent page crash in asp.net? Is there any generic function or place like global.asax where we specify a file to redirect to when an unhanded exception occurs? (like we redirect to a specified page when 404 page not found exception occurs?
View 3 Replies
Jul 18, 2010
"I DONOT WANT TO use the default error page tachnique, because i donot want the webpage to redirect!"
yes there is the try and catch
yes there are way to add exception handling mathods overwrite for controls
but what i need is,
it may just be a simple sql command,it may be a control such as formview, it may be a control such as datagrid, whatever it may be, when an illegal entry is done into the table of the database,
"THE BIG ERROR PAGE SHOULD NOT COME!!"
instead
a label at the top of the same page (where the illegal operation is performed) should display the error like
"error caused by "this control" and the error message is "null is not allowed in this field blah blah"
View 2 Replies
May 7, 2010
I am making MSSQL stored procedure CLR calls from ASP pages. When an exception occurs, it is logged and then rethrown. In this scenario I need to be able to handle the exception (if possible) in the ASP page. Note that I cannot move away from classic ASP in this instance; I am stuck within a legacy system for this project. let me know if you know of a way to handle the exceptions in classic ASP.
View 1 Replies
Feb 28, 2011
I have a simple method that is secured
[PrincipalPermission(SecurityAction.Demand, Role = "Administrator")]
protected void lnkClearCache_Click(object sender, EventArgs e)
{
}
If this is clicked without the role, it generates a System.Security.SecurityException: Request for principal permission failed. as expected.
I use ELMAH to handle logging for my errors, and I have a custom ELMAH event in my global.asax to transfer to the error pages in ways that preserve status codes which works correctly.
[Code]....
This works all well and fine and redirects to my error page which works properly, however instead of displaying the content as expected. I immediately get a second request for the error page but this time using the value of customErrorsSection.DefaultRedirect that does not come from my code in any way that I can see.
As far as I can tell it's almost as if when .NET raises an exception for PrincipalPermission and then lets the entire request complete, then after the request is complete it throws away the application response and instead responds with the default custom error.
When I'm debugging I do break on 2 separate exceptions for PrincipalPermission, whether this is a just a rethrow by .NET I'm not sure but my .NET code never sees the 2nd throw, nor does ELMAH. I always end up with a single response, single error logged, but that the url that finally renders to the browser is the default url and not 403 url that I specifically server.transferred to. If I browse to a /location that is secure I properly get the 403 error page.
View 1 Replies
Feb 1, 2010
Is there a way to globally handle exceptions in regular ASP.NET Web Service (asmx) using ELMAH like we do it in ASP.NET web site ?
View 2 Replies
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
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
Feb 17, 2010
In sqlserver2005 how to handle exceptions in stored procedures and
1)redirect to other page
2)write in to log file
View 1 Replies
Jun 21, 2010
We're using an Out-of-Process Session Provider (ScaleOut) for an ASP.NET application and we've noticed that when an object that's not correctly setup for de-serialization inadvertently makes its way into session it will eventually cause the entire process to terminate.
Reproducing and handling this scenario is where it gets even more interesting.
The exception that terminates the process is raised in AnyStaObjectsInSessionState whose implementation is pretty straightforward:
[code]....
View 2 Replies
Dec 19, 2011
I have some code that is throwing unhandled DivideByZero exceptions in a WebMethod. These exceptions are not being caught by the global logging in Application_Error in global.asax. why exceptions thrown from a WebMethod are not handled by Application_Error?
View 3 Replies
Jul 2, 2010
I' am trying to write a aplication using a 3 Tier Model
Data Access Layer <--> Business Logic Layer <--> Presentation Layer
But now i am facing a problem, i need to Handle Transactions i already found a interesting article
[URL] but i have some doubts.
For example when i need to iterate to a Grid in the presentation Layer how will i Use the Transactions??
[Code]....
View 2 Replies
Sep 29, 2010
I have an ASP.NET project which is pretty n-tier, by namespace, but I need to separate into three projects: Data Layer, Middle Tier and Front End.I am doing this because...
A) It seems the right thing to do, and
B) I am having all sorts of problems running unit tests for ASP.NET hosted assemblies.
Anyway, my question is, where do you keep your config info?Right now, for example, my middle tier classes (which uses Linq to SQL) automatically pull their connection string information from the web.config when instantiating a new data context.If my data layer is in another project can/should it be using the web.config for configuration info?If so, how will a unit test, (typically in a separate assembly) provide soch configuration info?
View 3 Replies
Jan 21, 2010
How should I log exceptions? I never tried logging in .NET before. Nor try to dump exceptions to a txt (or binary) file. I dont require a text file, just a way to view the logs with the file and line #.
-edit- using asp.net
View 13 Replies
Aug 5, 2010
I have the following code
[code]....
and while that presents a friendlier error message to a user, I've forgotten how to show me the "real" error.
View 2 Replies
Apr 1, 2011
I have a set of WCF services which I have been using with an ASP.NET MVC application so far. These service operations return a FaultException when the server has identified problem with what the client has submitted. For example:
[code]...
However with Silverlight this all fails. The server returns a 500 status code with the faultexception (as expected) but to Silverlight this just looks like a duff response.
The following MS article indicates a (ugly) work around for this: [URL] This workaround makes the service transmit 200 status codes, even if there is a FaultException, so that the Silverlight client can get them. But this will mess up 'normal' clients of my service (my ASP.NET application, other users in the wild).
However, the point of services is to have seperation from your clients. I still want my services to return 500 status codes so that my ASP.NET application can detect the FaultExceptions and handle them. But I also want Silverlight to be able to handle them too.
View 1 Replies
Mar 11, 2010
string lNewHTML = Regex.Replace(lOldHTML, "(word1|word2|word3)", "<a href="page.aspx#$1">$1</a>", RegexOptions.IgnoreCase);
The code works, but I need to include some exceptions to the replace - e.g. I will not replace anything i an img-, li- and a-tag (including link-text and attributes like href and title) but still allow replacements in p-, td- and div-tags.
View 2 Replies
Feb 11, 2011
I need to handle 404 exceptions differently than all other types of them. What is the best way to identify those 404 exceptions (distinguish them from other exceptions)?
The problem is that there is no a special exception class for 404 errors, I get regular System.Web.HttpException with Message = "File does not exist."
Should I just use exception's message for it or is there a better way?
View 4 Replies
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
Aug 3, 2010
There used to be an article at ELMAHs docs site that contained this information, but it seems to have been removed. I think it's as simple as setting a configuration setting in the section, but I haven't a clue what it isCan anyone take a few seconds and drop the configuration setting here?
View 1 Replies
Feb 23, 2010
RemoteOnly" defaultRedirect="~/Errors.aspx">
<error statusCode="404" redirect="~/Error.aspx?code=404"/>
</customErrors>
hrow new HttpException(404, "404 Not Found");
View 2 Replies
Sep 30, 2010
I put some global error handling in place, but am having problems testing it by causing unhandled exceptions.
Here's all I can think of at the moment. feel free to add to this list with more ways to trip unhanndled exceptions.
1) Dangerous form data - Entering characters such as < and > in a text box and trying to submit
2) Put invalid values in a URL parameter - eg if you page is www.test.com/home?testid=XXX where XXX is the form number/identity # you are trying to pull up, put a number that doesn't exist in the URL and hit enter.
I'm sure I could change some stored procedures or otherwise mess with my data access components but I'd rather not have to change any code anywhere...I want to be able to generate these exceptions on the front end, like a user would.
View 3 Replies
Jan 21, 2010
I spawn a thread on Application_Start and would like to log exceptions. There is not Context/HttpContext/HttpContext.Current, so how might i get it to log?ATM it does not catch any exception in my threads and if i write ErrorSignal.FromCurrentContext().Raise(ex); i get an error about context cannot be null.Maybe i can create a dummy HttpContext but somehow i dont think that will work well.-edit- i tried ErrorSignal.Get(new HttpApplication()).Raise(ex); and it doesnt seem to pick up that exception.
View 2 Replies
Apr 8, 2010
If you wrap a call to HttpResponse.End within a try catch block, the ThreadAbortException would automatically be re-raised. I assume this is the case even if you wrap the try catch block in a try catch block.How can I accomplish the same thing? I do not have a real-world application for this.
namespace Program
{
class ReJoice
[code]...
View 3 Replies