I am back after long interval with some new and exciting stuffs.
Today i will explain how can we write our custom code in ASP.NET MVC for user account management like Login, User Registration, Password Change, Password Reset etc. Will we see each one of them in a series of post.
Step 1: Create a new project from visual studio and select MVC template as project type.
Step 2: In the solution explorer you will see a Models folder. Right click and add a new class named “UserAccountModel.cs”
Step 3: Create a new public class named “Login” in UserAccountModel.cs with below definition.
You might have heard arguing some of developers about Advantage and Disadvantages of Web Forms over MVC or vice versa. I tried to compile some of the major difference between ASP.NET WEb Form and MVC design pattern which are listed below.
|Asp.Net Web forms
|Asp.Net Web Form follows traditional event driven development model for creating web applications.
||Asp.Net MVC is a light-weight framework that separate an application into three main components i.e. Model, View, Controller (MVC) so it follows MVC pattern based development model for web application development.
|ASPX page (.aspx) is tightly coupled with code behind files (aspx.cs/aspx.vb file) .So In Asp.Net web Forms there is no separation of concerns (SOC). So it’s not possible that multiple developers can work on one section i.e. aspx and another on code behind file at same time. So less support for parallel development.
|| Asp.Net MVC pattern is loosely coupled and provides very clean separation of concerns (SOC). View and Controller are independent of each other. So one developer can work on Controller, at the same time other on View and third developer can work on Model. This is called parallel development.
|Because of this tightly coupled behavior unit testing in Asp.Net Web Forms becomes really difficult.
||Each component in Asp.Net MVC can be easily tested because MVC is loosely coupled. So it provides better support for test-driven development (TDD) and Enhances testability.
|Asp.Net Web forms allow rapid application development (RAD) of web applications because of the availability of robust toolbox having lots of web controls and many control libraries.
||Asp.Net MVC might be bit slower to develop a project than Web Forms (due to its SOC nature)
|In Asp.Net web forms there are ViewState and Postback events. Large viewstate means increase in page size since viewstate is stored in the page itself thus bit slower loading time and performance degrades.
||MVC is stateless, so no ViewState and PostBack events so light weight, quick loading time and gain in performance.
|URLs are not much SEO friendly (though this is now possible in ASP.NET 4 as well), so affect SEO.
||Use of RESTful URLs makes MVC is more suitable to Search Engine Optimization as we can control the URL and the HTML to a greater extent.
|ASP.NET Web Forms model follows a Page Life cycle.
||Asp.Net MVC doesn’t follow Page Life cycle like Web Forms instead request cycle is simple in ASP.NET MVC model.
||Because ASP.NET MVC doesn’t support server controls, ViewState and event driven programming mode so it is very difficult framework for new developers to learn and work on MVC pattern.
|Asp.Net Web Form has Master Pages that provides for consistent look and feels across all the pages of web application.
||Asp.Net Web Form has Layouts for consistent look and feels. Default name of the layout is _Layout.cshtml and stored in /Views/Shared folder.
|Many server controls provided by visual studio toolbox like GridView and DataList, Repeater etc has easy data binding capabilities so reduces lots of efforts and codes being written.
||ASP.NET MVC doesn’t have server controls instead it has html input controls.
|Asp.Net allows code re-usability through User Controls.
||Asp.Net MVC has Partial Views for the concept code re-usability.
|Asp.Net Web forms will be good for small scale applications with limited team size.
||Asp.Net MVC will be best suitable and recommended for large-scale applications where different teams are working together.
So I guess above are some of the points you should remember if you have to make a choice between Web Form and MVC design pattern in ASP.NET Development life cycle.