MVC :: Display Friendly Error Message On Page Without Redirecting To Error.aspx
Mar 8, 2011
All the examples and websites i have looked at redirect a user to the error.aspx page when an error occurs. How do you just display a friendly error message on the page the user is viewing saying something like "Sorry unable to do whatever" I've tried using a try catch block on my class that executes a stored procedure and put another try catch on the controller, but this does not work and i still get the default error message (System.InvalidOperationException was unhandled by user code) My code is below:
So how can i just return ViewData["SqlError"] message in page.
I have an asp.net web application that queries a database with a SELECT query in a stored procedure. If the server returns an error, I want to display a friendly "sorry, there was a problem with your search" type message.
Should I handle this with a custom error page, and a redirect to that page in web.config? Or can put some text in a Label Control and set its property to visible if there are errors? I've seen the latter done with a Try/Catch arrangement in the code behind, but not sure if I can do that here. What would you recommend?
My code behind is below for the page that displays the search results:
I am trying to handle the unhandled exceptions in my project.I tried with this following code in my web.config filebut it is not at all redirecting to an error page which i have created instead of that it is throwing an exception in my code itselef. How to print the error description over therein my custom error page.
I've tried to implement two different solutions that use either and HttpModule or and HttpHandler to do URLRewriting for me. These work great on IIS 7 within my local development environment in Integrated and Classic modes. Currently the production server is running IIS 6.0 on a shared hosting environment. It appears that the request at least hits both the Module and Handler as the URL above redirect to the particular friendly url, but it doesn't redirect and hit hte Module or Handler again. Instead I get a 404 error for the friendly URL.
I have a serious problem with "Error on Page". The error message points to line number 939, char 13. In my code behind (C#) in line number 939 is only an obsolete method found which is no longer called. The aspx file has only 339 lines. What the heck is line number 939?The Webapplication allows a special user group to change some group memberships for members of another user group in Active Directory. The App handles 3internal DataViews derived from corresponding DataTables as DataSource for 3 GridViews and some other internal lists with objects (List<obj>).
It uses windows authentication to get current users credentials and his membership in the "Operators" group. This credentials will be passed-through to allow the process managing group memberships in active directory.After starting the App in browser it seems to work fine. But after an indeterminated time it doesn't longer respond. After each click on buttons (or link buttons) you only can see the message "Error on Page" in the browsers status bar below.I played with session timeout, storing the DataTables in session variables, without success.
Last week I found this article here: [URL]" and I addedEnableEventValidation="false" ViewStateEncryptionMode="Never" to Page declaration. However, at some point the the server does not respond. Each time the worker process on webserver recycles it seems the application turn to wrong state. Might be important: All controls including GridViews are embedded in an AJAX UpdatePanel. How to get a better error message? Debugging is enabled and Custom Error handling On, Off or Remote Only brings the same result as described.
This means that when this kind of Errors occur it should redirect to that page. All these pages are contents of the Master page including the Error page. But this Error Persist it does not show me the Error page. Even if i try to see if it goes to "Application_Error" in the Global.asa nothing goes there.
So i have also tried the second option. so i turned the web config part "off" and i trapped this in the global.asa like this
Code: Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Server.Transfer("~/Content/ErrorPages/SupportError.aspx") 'Response.Redirect("~/Content/ErrorPages/SupportError.aspx", False) End Sub
Can I configure ASP.NET custom errors so that it would redirect to other site when error has occurred. Even more, I would like to redirect to different web page every time. Here is my simplified actual case: User opens my pages with query? urlpage=[URL] and I would like to redirect to this page when error occurs. How should I act in this scenario?
I am new to .net. i amworking on the supproting project. At first i want to execute the project. It uses microsoft visual studio 2010 and sql server 2008, i attached the data base to sql server 2008,when am trying to execute the project , it opens the login page , it is taking the user name and password ,after entering the user name and password, when it redirects to index page it shows the xml parsing error. i am not getting what to do for this error. when i try to execute all other pages, it opens that pages . please help me to open the index page.
I use Custom errors in my web.config. It works for urls like www.x.com/x.aspx , but when I write something like :www.x.com/name (I have Application_BeginRequest dealing with it on global.asax) on the live server, IIS bypasses my application and shows its own error page.How can I disable IIS error handling and redirect where I want to?
I have recently moved my project to VS2005 and I have trouble running all pages that have code behind. I set up a DEV sub domain so I could start with one page and work out what is going on.
I have got the page working locally but it won't work when I upload the page, dll and associated files to the web server (hosted for me).
The error seems simple enough, it's a parser error saying it can't find the code behind file (aspx.vb), but I can't for the life of me work out why, especially when it works locally.
Problem Page = [URL]
Parser Error Description: An error occurred during the parsing of a resource required to service this request. review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The file '/rss/rss_darts_players_cx.aspx.vb' does not exist.
I have this admin page where i want to throw an error if they select more than 5 items from the list. I was trying to do this on the server side. When the selected items is more than 5, I get an error screen.
I have a customvalidator to validate the sum of 2 drop downs.. the validation code is working, because if the sum doesnt match my logic the page is not submitted, but if i select values that match my logic, the page is submitted.. so i know the logic is working, but the error message is not working.. and not sure why..
Some background, last week i had this working based on additional controls, but the business decided they wanted less questions on the form, so all i did was remove the controls from the validation and updated the logic to make sure it was only calculating against the existing controls. reminder that the validation is working( meaning that the page is not being submitted because it failed ) but the error message doesnt display on the page, so no one knows what is happening..
i ahve one custvalidator control in that i have used OnServerValidate="ValidateDateRange" ValidateDateRange is function i have written in serverside now i want raise error message without postback operation like (clientside validation) if that ValidateDateRange function returns false .
I have a regular expression validation control initialized to validate a textbox control. I want users to be able to enter U.S. Currency values ($12,115.85 or 1500.22 etc.). I found a regular expression off of regexlib website that does the trick. The validation control seems to be working except for one crucial thing. If invalid data is entered, the validation text dispalys (a red "*" next to the textbox), but the page will still submit and the error message won't pop up... I thought that the error message is supposed to display and the page won't submit if the validation control detects invalid data. Isn't this automatic with ASP .NET? I have searched extensively on how to create validation controls, but haven't found anything different than what I am already doing. Can anyone tell me what I am doing wrong here?