Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Monday, 28 January 2013

Sending and Logging Custom Errors in ASP.Net MVC

When you set the custom errors as remote only , you basically want to use the errors for debugging and fixing the problems.

There are various ways how you can use the very useful information from custom errors and notify these errors to the website administrators within no time.

Notifications can happen in many different ways out of which following are the most used:
a. Use Event Log on the server system.
b. Use log tables in SQL Server to log errors.
c. Write error log on to a text file and save them in folders.
d. Send Email to admin(s) with relevant information.
e. Send pager/sms with relevant information to the admin/maintenance team.

Notification of the error can be sent to the administrator in one of the following two ways:
1) Error can be registered as a log entry in the Windows Event Log on the administrator's machine
 2) An Email can be sent to the administrator with a suitable error message
Writing to the Event Log

In ASP.NET, error can be handled programmatically by writing appropriate code in the page-level error event, for errors on an individual page or in the application-level error event for handling errors that may occur in any page of the application.
Therefore, code for writing in the Event Log should be written in either of the events, depending on the requirement of the application. To illustrate this example, I have written the code in the application-level event with the error mode set to "RemoteOnly" and the defaultRedirect attribute to error.htm. The application-level error event should be included in the global file global.asax within the same application folder.

Event Log support is provided in .NET through the namespace System.Diagnostics.

SMTP mail service support is provided in .NET through the namespace System.Web.Mail.

To Log the errors into SQL, create a log table and use ADO.Net classes to write the errors.

To Log error on to text file use System. IO

To send message use System.Net

Send a mail across to me in case you want to implement any of these methods but are confused/need help to implement this.


Thursday, 6 September 2012

FAQs -I-Design Patterns

Design patterns MVC and MVVM uses Widely

MVC , MVVM aren't these two patterns design patterns.
Yes , both MVC and MVVM are UI design.

The other design patterns prominently used in MVC and MVVM are:
a. Observer pattern
b. Command pattern
c. Strategy pattern
d. Inversion of Control

The design principle used here are
S - Separation of Concern
O - Open- Closed Principle
D - Dependency Inversion

If we use Entity Framework and RIA Services will be using the Repository Pattern as well.

What does a View Model Contain?

It is important to note that the ViewModel does not describe how the view looks. It describes how the view functions, and what information it provides to the user.
 

Difference between View and User Control

while a View is a UserControl, a UserControl is not necessarily a View. 
 

Do you think developer in MVVM shouldn't contain any code

Developers should refrain from writing any code in the View's code behind file that doesn't pertain purely to the GUI.
 

View and View Model Relationship

A view should only have one viewmodel but  a single viewmodel might be used by multiple views

What are the two things necessary for MVVM?

  •  A class that is either a DependencyObject or implements INotifyPropertyChanged to fully support data-binding, and
  • Some sort of commanding support.

When will you use design patterns ...Always?

A pattern is useful when it accelerates development, improves stability and performance, reduces risk, and so forth. When it slows development, introduces problems, and has your developers cringing whenever they hear the phrase "design pattern", might want to rethink on the approach.