ASP.NET MVC web application exception handling - asp.net-mvc

ASP.NET MVC web application exception handling using application blocks.
How can i configure Microsoft Application blocks for exception handling in .NET MVC2 web application logging the error to the sql database?

You can write own Library bur this is not easy so i prefer u Use Elmah
I think elmah is good because now 588,786 is downloaded so we safely to use.
You can simply install
PM> Install-Package elmah
ELMAH with initial configuration for getting started quickly. ELMAH
(Error Logging Modules and Handlers) is an application-wide error
logging facility that is completely pluggable. It can be dynamically
added to a running ASP.NET web application, or even all ASP.NET web
applications on a machine, without any need for re-compilation or
re-deployment.

You might want to think about ELMAH. It is much lighter than Application Blocks and you can use it as a filter for handling errors.

Related

ASP.NET MVC with Plesk

I have an ASP.NET MVC web application that I'm trying to publish to Plesk, but I get a 500.21 Internal Error each time about a bad module.
In general, I'm not sure how to work with Plesk and ASP.NET MVC, this is my first time deploying to a hosting service and I haven't found much documentation on it. Could anyone point me to some helpful resources?? Or copy/paste some good instructions on how to do this? It seems anything that I do find is outdated..
Turns out that Plesk Onyx doesn't support .Net core (or at least GoDaddy won't enable the drivers to support it). I had to transfer it all over to .Net 5 and that solved the problem!

Using ELMAH inside my asp.net mvc 4 & MVC5 web application

I have two asp.net mvc web applications; asp.net mvc4 and asp.net mvc5 , they are both deployed under iis7 on two separate VMs.
now i am currently facing problems when un-handled exceptions are raised,,, because users will be re-directed to the Error view inside the shared folder under the view section. and i am unable to know exactly the exception details..
so i have read about using the ELMAH tool which will automatically logs all the UN-handled exceptions. but my question is that what are the steps that i need to follow to configure the tool inside myC application ?
second question; will ELMAH works on asp.net vmc4 and asp.net mvc5 in the same way?
Third question. now i have custom error set to <customErrors mode="RemoteOnly" /> inside my live asp.net mvc web application, since i do not want end users to be exposed to the technical details about any exception, so when using elmah should i set the custom error to be no ?
Thanks
1) Just install Elmah from Nuget. That will enable it with the default configuration to save exceptions to an XML file
2) Yes, it should work both in MVC4 and 5
3) No, you can leave it as it is. The Elmah page is available locally only by default. Users will be still redirected to your Error page, and you can use the elmah URL locally to access the actual error information.

Elmah.MVC vs. Elmah.contrib.Mvc

I'm new to ASP.NET MVC and I'm looking for the least painful way to get global error handling, logging, and reporting (via email) set up. FYI, my ASP.NET MVC app is being hosted as a web role in Azure, but I'm trying to avoid using any Azure-specific hooks.
It looks like getting ELMAH installed and configured is a good first step.
When I look in NuGet, I see:
ELMAH ("ELMAH with initial configuration for getting started quickly...")
Elmah.Contrib.Mvc ("...designed to add ease-of-use inside MVC projects...")
Elmah.MVC ("...painless integration into MVC...")
Which of these packages do I want to install?
EDIT: After some experimentation, I'm more confused. I compared the project files after installing each of the three options on top of a default MVC 4 app. It appears that neither Elmah.Contrib.Mvc nor Elmah.MVC add the elmah.1.2.2 package (which I get when I install basic ELMAH). Also, neither package adds the <elmah> section to Web.config.
So... do I need to install ELMAH first, and then install one of the "...MVC" packages to get whatever nifty improvements they presumably get me?
ELMAH - This is the default ELMAH package with no mvc specific code in it, if you dont do what is described here I don't believe ELMAH will log any errors that occur in you're controllers, and you may not be able to access the ELMAH log page
Elmah.Contrib.Mvc - This is an enhancement on ELMAH specifically for MVC based upon one of the creators of ELMAHS answer to a stack overflow question.
Elmah.MVC - This is simliar to the above package however I believe it provides much better support for mvc features like routes etc, It is also quite easy to install and configure, it removes a lot of the messing around you would have to do with ELMAH to take out various parts that arent required when running in a mvc project
You can read the authors posts to get a better idea of how it works:
Integrating ELMAH to ASP.NET MVC in right way
ELMAH MVC controller released on NuGet
ELMAH.MVC v.2.0.0 - Release Candidate
Personally I believe the last package would be the best one ot use, it seems to be the more up to date and maintained of the two mvc ones.
You might consider using Elfar instead of Elmah. Elfar is "inspired" by Elmah but is designed to be MVC specific and is very simple to configure.
Just open NuGet, and search for Elfar. You will find a number of different packages, but in general you want the one that conforms to the technology you are intested in using. I'm not familiar with Azure web roles, but if you have access to a standard Sql Server then you can simply use Elfar.SqlClient.
More info here:
https://github.com/stevenbey/elfar/wiki

Can't Access elmah.axd When Running ASP.net MVC on Apache

I'm using MVC2, mono 2.10.5, mod-mono-server4.
ELMAH is configured as per here, but I am using the XML file logger.
When trying to access /elmah.axd locally I get the following message in error log (indicating that the logging capabilities for ELMAH are working):
The controller for path '/elmah.axd' was not found or does not implement IController.
The following is still present in Global.asax's RegisterRoutes method as well:
routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");
It seems like adding the handlers for ELMAH is not working with apache - it is working on a windows 7 desktop with cassini, haven't tried with IIS.
I can post more details if needed.
This may not be the best answer, but I've followed the directions here to display ELMAH information in a more MVC-friendly way (this makes it easier to allow remote access as well). I'm running into another mono-specific error now, but I will post that as a new question.

log in asp.net mvc

In my mvc application i need to check a condition in action and throw it to the log.
How can i add a info to log info.
To use the event log:
System.Diagnostics.EventLog.WriteEntry()
Or look at a library like log4net or ELMAH.
Kindness,
Dan
Have you tried using EMAB or Log4Net libraries?
Yes...there are built-in classes but instead of building it ground-up the best method is to use established frameworks.
Check this out >>> MS Logging Application Block
And if your needs are at a very basic level the System.IO.Log should suffice.
For unhandled errors ELMAH is the easiest to use.

Resources