C# - Best Practices When Reporting Exception Messages To The User

Mar 4, 2011

In my ASP.NET MVC application, I do not want to report all exception messages to the user. But there are certain types of exceptions that I'd like to report to the user, so I created an action filter to decide if it's this particular type of exception, and if so then display the exception's message, otherwise display a generic message. So I created a custom exception called ClientException.

My filter looks something like this:

if (filterContext.Exception is ClientException)
message = filterContext.Exception.Message.Replace("
", " ").Replace("
", " ");
else
message = "An error occured while attemting to perform the last action. Sorry for the inconvenience.";

filterContext.HttpContext.Response.Status = "500 " + message;


I read this http://blogs.msdn.com/b/kcwalina/archive/2007/01/30/exceptionhierarchies.aspx where the author recommends using existing .NET exception types to report usage errors. However, by introducing my custom exception, I just have to do a single check in my filter.

View 5 Replies


Similar Messages:

Architecture :: How To Manage User Messages To Avoid Hardcoding Messages

Aug 10, 2010

How to manage user messages to avoid hardcoding messages accross the web application.

View 17 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# - Success Messages As Opposed To Model State Error Messages?

Jan 26, 2010

For error messages, validation faults etc you have

ModelState.AddErrorMessage("Fool!");

But, where do you put success responses like "You successfully transfered alot of money to your ex." + "Your balance is now zero". I still want to set it at the controller level and preferably in key-value way, the same way as errormessages but without invalidating the modelstate.

View 3 Replies

To Send Messages To The User Of Web Application?

Feb 25, 2010

i have a problem there that i had an application that is running now i have problem that i have to send messages to all my user that are in my list.

View 5 Replies

Passing Messages To The User In MVC2?

Jun 29, 2010

I am using ASP.NET MVC2 for my project. I want to send the user confirmation messages after actions.

Ideally: User clicks on a link with a query string (i.e. a link to delete an entry) The controller does what the link says, creates the success message, and uses RedirectToAction to get rid of the query string from the URL. The new action displays the success message.

View 3 Replies

How To Show Error Messages To The User

Jun 9, 2010

Since we cannot display a messag box, how to show an error message [for something that happens on the server side] to the user in ASP.NET [4.0]?

View 5 Replies

SQL Reporting :: In Reporting Services Got This Error "The Permissions Granted To User SysnameASPNET Are Insuffic?

Nov 2, 2010

i'm using sql server 2008 with advance services the below error is of reporting services.."The permissions granted to user 'sysnameASPNET' are insufficient for performing this operation. (rsAccessDenied)"when i'm trying to host appliction.. the above error is occured..it works fine when i try to execute locally.. but when i try to execute through the IIS i.e host applicationthe above error is displayed.

View 2 Replies

SQL Reporting :: Showing User Promt When Opening Reporting Manager URL?

Dec 27, 2010

I am getting user name and password promt while trying to access reporting manager URL at a simple test server. and i have tried so many user name and password even of administrator for that machine . but nothing worked for me.also googled it but no success.. and the same thing working on my PC without doing anything EXTRA..Any one master of SSRS ?

View 5 Replies

To Send Messages To Facebook User Accounts?

Sep 27, 2010

actullay my requirement is i need send messages to facebook user accounts using my web application(Asp.net,C#.Net).i have Users's facebook id and there there facebook Keys.

View 2 Replies

SQL Reporting :: Unhandled Exception Populating Byte Array

Dec 6, 2010

This is actually a problem with a local report (RDLC) as opposed to an SQL report but this seemed to be the closest forum. I'm simply trying to have my page programatically open my report in PDF format. Ideally the preview wouldn't have to load at all but the way of doing it in pure code without loading a page with a ReportViewer control seems complicated to me, especially as the report has several subforms, all with different datasources (from an SQL server database).

So I'll settle for a page with a ReportViewer control which automatically opens the report in PDF when the page loads. I can't believe how much code is required for this! There are lots of tutorials on the Internet for this and I've tried several but without success. It seems to always fail at the same line, when adding values to the byte array.

[Code]....

View 3 Replies

SQL Reporting :: Firefox Exception When Running Sql Server Report Manager?

Feb 24, 2011

when trying to run sql server report manager on Internet explorer its ok ,but when i try to run it in firefox i get thie exception?Server Error in '/Reports' Application.Access is denied. Description:An error occurred while accessing the resources required to serve this request. You might not have permission to view the requested resources.Error message 401.3: You do not have permission to view this directory or page using the credentials you supplied (access denied due to Access Control Lists). Ask the Web server's administrator to give you access to 'C:Program FilesMicrosoft SQL ServerMSRS10.MSSQLSERVERReporting ServicesReportManagerhome.aspx'.Version Information: Microsoft .NET Framework Version:; ASP.NET Version:2.0.50727.4955

View 1 Replies

SQL Reporting :: Exception Of Type 'Microsoft.ReportingServices.RsProxy.AccessDeniedException' Was Thrown?

Apr 2, 2010

I have created a Data Source, Data Source Views and a Report Model. I then tried to deploy it and got the above error.I have seen a lot of possible answers via Google but none as yet have worked for me.I have Windows 7 and Microsoft SQL2008 full package.

View 2 Replies

Valid User Session Variable Not Found - Two Identical Error Messages

Apr 8, 2016

I am getting two identical errors message when I view my Web page in my browser:

Valid User Session Variable Not Found: System.NullReferenceException for this line:

Code:
Response.Write(Session("ValidUser").ToString & "<br />") <----------

and the same error for this line:

Code:
Response.Write(Session("strEmail").ToString) <-----------

This is the code in that page:

Code:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
Response.Write(Session("ValidUser").ToString & "<br />")
Catch ex As System.Exception
Response.Write("Valid User Session Variable Not Found: " & ex.ToString & "<br />")
End Try

[Code] .....

This the page that users are redirected to after logging on and, after verifying their credentials at the log-on stage, should show 'Hello DonaldDuck@Disney.com, Welcome to my website'.

Do these errors mean that the user cannot be validated in the database?

View 9 Replies

SQL Reporting :: Error While Deploying The Report " ErrorKeyset Does Not Exist (Exception From HRESULT: 0x80090016)"

Oct 4, 2010

I have a problem in Deploying my reports in the system. when i try to deploy i get the following

" errorKeyset does not exist (Exception from HRESULT: 0x80090016)".

View 7 Replies

Web Forms :: How To Show Exception To The User

Jun 11, 2010

I have an ASPX page where I want to show an error id when an unhandled error occurs. So I throw an Exception with an error id. However all the user sees is an "Internal Server Error 500" from IIS/ASP-NET Dev. How can I control this? I want the user to either see my Exception.

View 5 Replies

Exception Logging Approach For Concurrent User?

May 12, 2010

I am involved in designing a asp.net webforms application using .NET 3.5. I have a requirement where we need to log exceptions.

What is the best approach for exception handling, given that there would be concurrent users for this application?

Is there a need or possibility to log in exceptions at a user level? My support team in-charge wants to have a feature where the support team can get user specific log files.

To give you a background, this application is currently on VB 6.0 and we are migrating it along with some enhancements. So, today the support personnel have a provision to get user specific log files.

View 2 Replies

Get Exception Error If Logged In User Is Inactive?

Oct 6, 2010

If a logged in user is inactive on the page for more than 20 minutes and thenclicks a button to cause post back they get the error below.Server Error in '/' Application.Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster

View 5 Replies

Exception Handling From Private Class In User Control?

Apr 2, 2010

I am part of a team that is developing a SharePoint web part. My task is to create a user control which will ultimately be wrapped in another class for presentation in a web part. Because of these requirements, I must fit all of my code in a single user control.To organize my code in the code-behind, I created a few private classes for the different objects which are represented in the database. I want to add some exception handling whereby if some sort of DB exception is thrown I can update a message on the page informing the user of the problem.

My problem is that the page-level controls are inaccessible from the private class where I'm issuing the query, so even if I catch the exception I have no way of directly accessing a Label control to populate the error. I tried to create a baseclass with an EventHandler defined, but when I throw events from the private class I'm not able to catch them for whatever reason. I'm far from an OOP expert Here is a snippet:
ASP Code:
using System;
using System.Collections;
[code]....

View 3 Replies

Web Forms :: NullReference Exception Unhandled By User Code?

Mar 18, 2011

I'm working on having two forms that communicate together. In order to do this, I am passing public value from the source page. Here's how I did it:

In the source page I have:

Public ReadOnly Property CurrentCity() As String
Get
Return txtboxfake.Text
End Get
End Property
Then under page_load of the page I have:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtteam.Text = PreviousPage.CurrentCity
txtboxdate.Text = Calendar1.SelectedDate
End Sub

For some reason I keep getting an error that says "NullReference exception unhandled by user code" that points to txtteam.text = PreviousPage.CurrentCity.

View 13 Replies

Web Forms :: User Control Causing Null Reference Exception?

Oct 19, 2010

I am stuck into a problem, i have a user control ProductListing.ascx that contains ListView binded to an object datasource, SelectMethod and SelectCountmethod are provided as well. Everything works fine but the problem started when i add another user control declarativlly Filter.ascx in the productListing.ascx. I want to assign value to a public property MaxPrice in Filter.ascx. I am trying to set this property in the SelectMethod of ObjectDataSource. Usercontrol "Filter.ascx" throws null reference exception when i try to set its MaxPrice Property.

I tried to acced the usercontrol in Databind method of ListView , it is accessible here but viewstate is empty at this point, i saved the value in viewstate in SelectMethod of objectDatasource but i cant access viewstate in ListView Databind. Its empty. Its a simple code and no rewriting to viewstate elsewhere.

Important: My Codebehind files are in a seperate project and .ascx files in seperate project

View 1 Replies

Web Custom User Control Threw A Null Reference Exception?

Mar 8, 2010

I' m using a web custom control to upload images and mark them as primary. all the flow is working fine but it fails to mark images as primary in a diffrent category(there are four categories in which we can load a image-,catalog,primary,misc).It works in - category but not in others when I debug it is failing at a condition in grey . If it is not an element of the Datalist item it would not even enter the loop. I' m lost and unable to find the reason.

View 2 Replies

System.data.sql Exception Login Failed For User 'DomainMechine Name'?

Jul 12, 2010

I developed a asp.net application in vs2008. It is working fine Locally. When I deployed it to the IIS am getting the System.data.sql exception Login Failed for user 'DomainMechine Name'rror.hen I add <identity impersonate ="true" /> then It is working on the server (locally) but not workingWhen I try to acces the page thru link.I already added NT AUTHORITYNETWORK SERVICE permission to the database. understand why am I getting this issue and How can I resolve this Issue? Note: I have authorization enabled in my web.config. I am allowing only certain people to access this site. I have full rights.

View 2 Replies

Way To Capture Unique Constraint Exception And Provide User-friendly Message

May 4, 2010

Using vb.net/asp.net 2005 and SQL Server 2005:I have a unique constraint setup to prevent users from entering duplicate email addresses in my online system.When a user tries to edit an existing email to one that already exists (add a duplicate) it shows the following<ERROR>Cannot insert duplicate key row in ojbect "dbo.someTableName" with unique index.....The statement has been terminated This prevents the user from adding duplicates which is good but I would like to provide a more user friendly exception message and I do not want to show the table and field names to the user.

View 4 Replies

Forms Data Controls :: Null Reference Exception Was Not Handled By User?

Sep 2, 2010

Null Reference Exception was not handled by user Object Reference not set to instance of an object

View 2 Replies







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