Sunday, September 8, 2019

ONE ASP.NET STEP BY STEP

One Asp.net lets you build an application and use all asp.net technology in one project which was not possible before this.
It means we can create Webforms project and in the same project, we can also use MVC and Web API too.
In now day's developer do not work on any one technology especially if we want some rapid development and small project people use web forms and if large project then MVC and meanwhile some want to develop API for mobile then would be use WEB API with launch of One ASP.NET it's possible to work with different flavors in one project.
Fig 1. One ASP.NET overview
Fig 2. One ASP.NET
Before we understand what's new in One Asp.net we are going create an application in the older version and have a look at it and then compare with what's new in One ASP.NET.
Creating Project in Visual studio 2012
If we take visual studio 2012 for development of new web project
From visual studio IDE on the start page selects "New project" link then a new dialog with Name "New project" will pop up.
From that dialog we are going to select web templates from left pane after selecting web template, we find much other option for selecting templates such as Empty, WebForms, MVC 3, and MVC 4 but in this part, we can select only one project template at a time right.
Fig 3. Creating project using Visual studio 2012
Here we are going to select "ASP.NET MVC 4 Web Application" Template and click on the OK button a new dialog will pop up for selecting Project Template.
Fig 4. Choosing project Template in Visual studio 2012
Here we can select only one project template at a time.
In the same way, if we are going to have a look on new One ASP.NET Project template it's something different for showing that I am going to use Visual studio 2015.
Next step we are going to have a look on how to create a project in Visual Studio 2015 and what is One ASP.NET.
Creating Project in Visual studio 2015
It's the start page of new Visual studio IDE.
Fig 5. Creating project using Visual studio 2015
From visual studio IDE on start page select "New project" link then a new dialog of the new project will pop up.
In that we are going to select web templates from left pane after selecting web template, we find only one project template in it "ASP.NET Web Application".

It's the New One ASP.NET

Fig 6. Choosing project Template in Visual studio 2015
After selecting this project template next we are going to name the project as "MVC5DEMO" and clicking on the OK button a new dialog will pop up with Name "New ASP.NET Project" for selecting project Templates.
Fig 7. Choosing project Template in Visual studio 2015
Here we are going to choose Web Forms as base Template but meanwhile, we can also add reference of additional frameworks to project such as MVC and Web API which can be added to the project by choosing appropriate checkboxes. This was not possible earlier.
Note:- If we choose below checkboxes option then it Adds Folder structure and Core reference frameworks to project.
e.g :- If we choose MVC then it's going to create MVC folder structure and add all reference .DLL of MVC framework to project.
If we choose WEB API then it's going to create MVC folder structure will add all reference DLL of WEB API framework to project.
Let's check MVC Checkbox for this application.
Next step is to choose Authentication which is new in One ASP.NET.
Change Authentication
In New project template dialog you will button with Name Change Authentication just click on that button to Change Authentication of the project.
There are 4 types of authentication
  1. No Authentication
  2. Individual User Accounts
  3. Work And School Accounts
  4. Windows Authentication
No Authentication
If you do not want any Authentication for the application then you can choose this option.
Fig 8. Choosing No Authentication
Individual User Accounts
If you choose this option for Authentication of application then your application will be configured to use ASP.NET identity [ASP.NET Membership] where User register in the application and then sign in using credentials and also User sign in via social accounts such as Facebook, Twitter, Google, Microsoft and other providers. All user data will be stored in SQL server database.
Fig 9. Choosing Individual User Accounts Authentication
Work and School Accounts
If you choose this option for Authentication of application then your application will be configured to Authenticate user with Active Directory, Microsoft Azure Active Directory or Office 365.
Fig 10. Choosing Work and School Accounts Authentication
Windows Authentication
If you choose this option for Authentication of application then your application will be configured to Authenticate user in an intranet environment, where any user from a local user group or Active Directory can access this application.
Fig 11. Choosing Windows Authentication
Here we are going to choose No Authentication for this project.
Fig 12. Choose Host in cloud option for hosting application in Azure cloud
If you have Azure account and want to Host application on azure then you can choose this option after choosing this option it will pop up a dialog with name "Configure Microsoft Azure Web App" where it will ask credentials of Azure account and other details.
Fig 13. Provided Account details to host application on Azure
Here we are not going to choose Host in the Cloud option for this project.
Finally, we have chosen all option which we required for developing the project.
Fig 14. Choosing project Template
Here are combinations which we can choose for creating a solution.
Choosing Project Combination
Fig 15. Combination of project where you can play around
Empty Project Template
If we choose Empty Project Template then we get three options for creating a project we can select any one or all combination or all three option.
MVC Project Template
If we choose MVC Project Template then by default MVC checkbox is checked and we can choose other options with it.
WEB API Template
If we choose WEB API Project Template then by default MVC and Web API checkboxes is checked and we can choose other options with it.
WEB Forms Template
If we choose Web forms Project Template then by default web forms checkbox is checked and we can choose other options with it.
Single Page Application Template
If we choose Single Page Application Project Template then by default MVC and Web API checkboxes is checked and we can choose other options with it.
Option we chose
We have chosen web forms with MVC let's have a look at project structure it's mixed merged it contains both flavors it has the flavor of MVC and flavor of web forms both in it.
Project structure
If we see project structure closely then you can see we have MVC project structure along with that we also have Web Forms in it that seems something new right.
It's the flavour of ONE ASP.NET its Tasty.
Fig 16. Project structure view
After creating Project next step now if you think you want to add WEB API in this project it is possible in simple steps.
Adding API Controller
To add API controller in existing project just right click on Controller folder then select Add and inside that select "New Scaffolded Item".
Fig 17. Steps to add API Controller
After selecting New Scaffolded Item a new dialog with name "Add Scaffold" will pop up.
Fig 18. Adding API Controller
In this dialog just select "Web API 2 Controller- Empty" and click on Add button will pop up a small dialog with name "Add Controller" Just Name controller which you want I am going to name it as "PurchaseController" and finally click on Add button.
Fig 19. Naming API Controller
Note: -
The "New Scaffolded Item" is also a new feature which is not available in the earlier version.
If you select "New Scaffolded Item" the new dialog with name "Add Scaffold" will pop up and in similar way if you select [Add ➜ Controller] option then same dialog of "Add Scaffold" will pop up but this time it will contain only controllers [MVC 5 Controller , Web API Controller] No Views and Area in it.
After clicking on Add button the Purchase API Controller will get added in Controller folder and meanwhile a readme.txt file will open in Visual studio IDE.
This text file contains information which you need to make changes in a project such that it works in a proper way.
  1. The first step it is saying to add namespace for using WEB API
  2. using System.Web.Http;
    using System.Web.Routing;
     
  3. The second step it is saying to add Application_Start() in global.asax file if it is not there
  4. protected void Application_Start()
    {
    }
     
  5. The third step it is saying to add the following line in Application_Start()
  6. GlobalConfiguration.Configure(WebApiConfig.Register);
After making changes as it was told in a readme.txt file in global.asax below is a snapshot of global.asax class.
Snapshot of Global.asax
After creating Project and making all changes next step now we are going to run this project.
Final Output

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...