Friday, 25 August 2023

Differences Between ASP.NET and ASP.NET Core - ASP.NET vs ASP.NET Core

 


What is ASP.NET?

ASP.NET is a fundamental web development platform used to create websites, applications, and web services. It is the integration of HTML, CSS, and JavaScript. Originally ASP.net was released in 2002. The first version of Asp.Net deployed was 1.0. The Recent Version of Asp.Net is 4.6.

Asp.Net works on HTTP (Hypertext Transfer Protocol) and uses the HTTP commands and policies to set a browser-to-server bilateral communication.

ASP.NET is a part of the Microsoft .NET Framework. The following image shows the component stack.

 

 
Asp.Net Introduction

ASP.NET provides three development styles for creating web applications:

  • Web Forms
  • ASP.NET MVC
  • ASP.NET Web Pages

1. Web Forms: ASP.NET web forms extend the event-driven model of interaction to web applications. It is used to develop an application with data access and also provides server-side and event to create an application.

2. Asp.Net MVC: The ASP.NET MVC web development framework employs the MVC design pattern. Unlike ASP.NET, where the view is predetermined, .NET MVC separates app functionality, view data, and model data. It enables you to use critical features like URL authorization, Windows and form authentication, data caching, output management, state management, configuration system, and many more.

3. Asp.Net Web Pages: It is used to create dynamic web pages. It combines server code with HTML in a fast way.

The following table illustrates each development model.

ModelSkillsDevelopment styleExperience
Web FormsWin Forms, WPF, .NETRapid development using a rich library of controls that encapsulate HTML markupMid-Level, Advanced RAD
MVCRuby on Rails, .NETFull control over HTML markup, code and markup separated, and easy-to-write tests. The best choice for mobile and single-page applications (SPA).Mid-Level, Advanced
Web PagesClassic ASP, PHPHTML markup and your code together in the same fileNew, Mid-Level
Sources: https://www.javatpoint.com/asp-net-introduction

The ASP.NET application code can be written in any of the following languages:

  • 1. C#
  • 2. VB.Net
  • 3. J#

Looking to hire .NET developer for your next project?

ASP.NET Architecture and its Components


ASP.NET basic architecture is shown below.

Asp.Net Architecture

This .NET framework has the following key components.

  • 1. Language - A .NET Framework is a variety of programming languages including VB.NET and C#.

  • 2. Library - The .NET Framework is a set of a standard class library of reusable classes, interfaces, and value types for ASP .NET development process and system functionality

  • 3. Common Language Runtime (CLR) - The CLR is used to perform code activities. Activities include exception handling and garbage collection mostly.

What Is ASP.NET Core?


Asp.net Core is a new version of Asp.net released by Microsoft. It is an open-source platform used to develop a web framework and can be executed with different browsers like Windows, Mac, or Linux. ASP.Net Core is a new version of asp.net. It is a free open source that can run on different OS like Mac, Windows, and Linux. It was originally launched as ASP.NET 5 but later it was renamed to ASP.NET Core and still with the same name.

Asp.Net Core Introduction

ASP.NET Core is a cloud-based cross-platform framework to build web apps on Windows, Mac, and Linux including the MVC framework. It is a combination of MVC and WEB API in a single web programming framework Core is a cloud-based cross-platform framework to build web apps on Windows, Mac, and Linux including the MVC framework. It is a combination of MVC and WEB API in a single web programming framework.

Turn your vision into reality with the best ASP.NET Web Development Company.

Major Benefits of ASP.NET Core:

  • 1. Asp.Net core is a much leaner and modular framework because of multiple architectures

  • 2. Asp.Net Core is an open-source framework.

  • 3. Easy to build cross-platform Asp.net apps on Windows, Mac, and Linux.

  • 4. The configuration is a cloud-ready environment.

  • 5. Ability to host on:
      a) Kestral
      b) IIS
      c) HTTP.sys
      d) Nginx
      e) Apache
      f) Docker

ASP.NET Core Version History:


VersionRelease Date
ASP.NET Core 2.1May 2018
ASP.NET Core 2.0August 2017
ASP.NET Core 1.1November 2016
ASP.NET Core 1.0June 2016

net-core-release-roadmap-ifour

Difference Between Asp.Net VS Asp.Net Core


ASP.NETASP.NET CORE
Asp.Net Build for WindowsAsp.Net Core Build for Windows, Mac, and Linux
Asp.Net has a Good PerformanceASP.Net core has higher performances than ASP.Net 4x.
It runs on .Net Framework or commonly called full .Net FrameworkIt runs on .Net Core and Full .Net Framework.
Asp.Net Supports WebForm, Asp.Net MVC and Asp.Net WebAPI.Asp.Net Core does not support WebForm. It supports MVC, Web API, and Asp.Net Web pages originally added in .Net Core 2.0.
Asp.Net used only IIS with dependent on System.web.dll.Asp.Net Core has not dependent on System.web.dll and so the IIS.
Support C#, VB, and many other languages and also support WCF, WPF, and WFSupport only C#, and F# language. VB support to added for a short time and no support for WCF, WPF, and WF but support for WCF client libraries are available.
Asp.Net MVC application added Web. config, Global.asax, Application Start.Core did not support Web.config and Global.asax files. It is supporting appsettings.json.
Container support is not than better the ASP.Net Core application.Container support is best suited for deployments like Docker.
All major versions supportedSupport Core from Visual Studio 2015 update 3 and current version VS 2017.
We Need to re-compile after the code change.Core Browser refresh will compile and execute the code with no need for re-compile.

Now that you are perfectly aware of the key distinctions between ASP.NET Core vs ASP.NET, there are certain questions that many experts still get confused about. Let’s go through them.

Is .NET Core and ASP.NET Core the same?


Many individuals get puzzled when they discover about .Net Core vs Asp.Net Core. Even though they seem similar but there is a small yet critical difference between them.

ASP.NET Core is a web-specific framework used for API and web app development. It is simply implemented on top of .NET CORE.

While .NET Core is a general-purpose programming framework for app development.

Difference between .NET vs .NET Core


Another difference where individuals get confused is .NET vs .NET Core.

.NET framework is an open-source and leading modern web and app development platform with impeccable support for cross-platform compatibility while .NET CORE is an upgraded version of ASP NET framework.

Another difference where individuals get confused is .NET vs .NET Core.

Understanding the differences between ASP.NET vs .NET Core and ASP.NET Core vs .NET Core is essential especially when you try to pick .NET as your career.

ASP.NET development has established itself as a standard in the world of cutting-edge technologies, convincing clients to embrace it for commercial efforts. ASP NET framework has gained new levels of flexibility and increased performance with its newest foundation, .NET Core while remaining a tried-and-true framework and a cornerstone for top-notch web app development.

Let's delve into the key disparities between these two frameworks: .NET vs ASP.NET Core.

Key Features of ASP.NET Framework:


ASP.NET is a rich ecosystem for custom software development offering WebForm features and MVC architecture support. Although this framework provides you with such amazing features, it also has the limitation of being supported by just the Windows platform.

However, the newest version of the ASP.NET framework, .NET Core, has cross-platform compatibility, making .NET even more secure. This is the most important difference between asp.net and asp.net core that everyone should be aware of.

 
net-vs-netcore-differences-ifour

Advantages of ASP.NET Core Over ASP.NET:


Enhanced modularity: ASP.NET Core helps you with enhanced modularity that makes developers easily use the components they require.

Cross-platform support: ASP NET CORE is open-source in nature and offers you amazing features. What makes it even more interesting is its cross-platform compatibility support. This allows developers to build projects of various requirements scenarios.

Lightweight and high performance: The platform is lightweight and known for delivering high performance. This platform helps you with seamless speed and scalability for your business application.

Remarkable security: ASP.NET Core offers both built-in and third-party identity providers to manage authentication. You may enhance project security using CORS management, HTTPS enforcement, app secrets, and so on.

Performance Comparison: ASP.NET Core vs. ASP.NET:


Web applications developed using ASP.NET Core are quicker than those built with Microsoft's ASP.NET framework. This is because the .NET Core platform’s superior execution and usage of the Kestrel web server make it so. Moreover, the excellent support for dependency injection enhances ASP.NET Core with reduced resource overhead and quicker code processes.

Is ASP.NET and ASP.NET MVC the same?


One of the several questions where developers get baffled is MVC vs ASP.NET: Are they the same? These two concepts must be understood clearly before beginning .NET programming.

The ASP.NET framework is completely based on view first architecture, where the view was already decided. While in ASP.NET MVC, the action is executed first, and it can choose any type of View, either from “only View” or “View + data”.

Understanding MVC in ASP.NET and ASP.NET Core:


Both of these frameworks follow the MVC development pattern (Model-View-Controller) for structuring projects and applications. ASP.NET Core, on the other hand, is more versatile and adaptable than the DOT NET framework, which merely follows a convention-based approach. DOT NET developers may use this to modify the architecture of their individual project requirements. .

Dependency Injection in ASP.NET Core and ASP.NET:


The dot net framework apps are cross-platform and easily scalable. Dependency Injection (DI) is one such feature that has been common to both the ASP.NET and .NET Core frameworks. This feature makes bespoke application development more modular with code being maintainable.

ASP.NET Core, however, integrates DI natively into its architecture, making it easier to manage and test dependencies across the application.

Cross-Platform Development with ASP.NET Core:


What makes ASP.NET Core stand out in the crowd is its support for cross-platform compatibility. Because of this, clients tend to hire .NET Core developers to build business apps that run seamlessly on Windows, Linux, and macOS. This flexibility opens new opportunities for reaching a wider audience and reduces deployment constraints.

 
aspnet-core-architecture-ifour

Deployment and Hosting Differences: ASP.NET vs. ASP.NET Core:


When it comes to net core vs net framework, deployment and hosting options are distinct.

ASP.NET Core provides containerization support using a platform known as Docker. It seamlessly simplifies deployment across different hosting environments.

ASP DOT NET applications, on the other hand, relies completely on Windows server and has limited deployment opportunities.

ASP.NET vs .NET CORE: Choosing the Right Framework


Deciding between ASP.NET Core and ASP.NET platforms for custom .NET software development depends on several factors. This includes meticulous consideration of project requirements, platform inclinations, the level of performance expectations, and many more.

As you navigate this decision-making process, a thorough analysis of your business app demands becomes essential. By delving into the specifics of your business requirements and aligning them with the capabilities and strengths of each platform, you can ensure that your choice is grounded in a well-informed decision. This eventually resonates with the unique goals and characteristics of your project.

ASP.Net vs ASP.NET CORE: Key Points to Consider


ASP.NET, with its established history and wide adoption, remains a reliable choice for legacy applications and projects that require integration with the full .NET Framework.

Organizations that look for stability and Windows compatibility can use this framework. This framework has impressive features, mature tooling, and a rich set of libraries that make custom web development a breeze.

On the other hand, ASP.NET Core emerges as a modern and cross-platform solution that addresses the limitations of its predecessor i.e., ASP.NET.

It blows your mind with impeccable performance, modular architecture, and improved scalability. ASP.NET Core is a great fit for enterprise projects, cloud-based applications, and scenarios where lightweight, high-performance web development is paramount.

Its support for microservices architecture, flexibility, and seamless integration with modern development practices, such as DevOps and containerization, keeps it the preferred choice for many forward-looking developers and organizations.

Migration Strategies: Upgrading from ASP.NET to ASP.NET Core:


Migrating from ASP.NET to ASP.NET Core requires careful planning. While the transition can yield benefits in terms of performance and flexibility, it's essential to assess the existing codebase and determine the best approach.

 
migrate-aspnet-to-aspnetcore-ifour

ASP.NET Application use cases.


E-commerce Platforms: ASP.NET is an excellent choice for e-commerce website development entailed with complex features, seamless user experience, and secure payment gateways. Whether it is managing inventory, processing orders, or offering a personalized shopping experience, ASP.NET can effortlessly handle the complexities of online retail.

Enterprise Application Development: Large-scale enterprise applications demand reliability, scalability, and comprehensive security features. ASP.NET is well-suited for crafting intricate internal portals, customer relationship management systems, and data-driven dashboards that facilitate efficient collaboration and decision-making within organizations.

Content Management Systems (CMS): Content-heavy websites and CMSs benefit from ASP.NET's capability to manage and display diverse content types. With features like role-based authentication, user management, and flexible content rendering, ASP.NET empowers businesses to create dynamic and engaging digital experiences.

ASP.NET Core Application use cases.


Cross-Platform Web Applications: ASP.NET Core's cross-platform compatibility is a game-changer for businesses seeking to reach a wider audience. Whether users access your application on Windows, macOS, or Linux, ASP.NET Core ensures a consistent and optimal experience.

Microservices Architecture: In a world of microservices, ASP.NET Core's lightweight and modular nature excels. It's well-suited for building individual microservices that can be easily integrated into a larger system, offering flexibility and scalability as applications evolve.

IoT (Internet of Things) Applications: As the IoT ecosystem expands, ASP.NET Core proves valuable in creating applications that connect and manage devices, sensors, and data streams. Its efficiency in handling real-time data and asynchronous processing makes it an excellent choice for IoT projects.

Outpace your competitors with innovative Angular development services.

Future Trends and Updates: ASP.NET and ASP.NET Core Roadmap


Both frameworks are actively maintained by Microsoft, ensuring continued updates and improvements. ASP.NET Core, with its modular architecture and cross-platform capabilities, is likely to play a pivotal role in the future of web development.

By understanding the nuances of ASP.NET and ASP.NET Core, you can make informed decisions when selecting the right framework for your projects. Whether you prioritize platform independence, performance optimization, or specific development needs, each framework offers unique advantages that cater to different scenarios.

Conclusion

In conclusion, learning the key differences between ASP.NET and ASP.NET Core is essential to make effective decisions during .NET web development. Of course, these two frameworks belong to the so-called ASP.NET ecosystem and have similar goals of creating robust and dynamic web applications, they exhibit distinct features catering to different development scenarios.

Ultimately, the choice between .NET and .NET Core hinges on project requirements, technical constraints, and long-term goals. Evaluating factors such as platform compatibility, performance demands, development team expertise, and deployment environment will guide the decision-making process.

As the technology landscape continues to evolve, both frameworks will play distinct roles, ensuring that developers have the tools they need to build powerful and responsive web applications.

----- Content source: Read here 



Wednesday, 21 June 2023

What is Exception Filter and explain custom Exception Filter in ASP.NET MVC?

 

What is Exception Filter and explain custom Exception Filter in ASP.NET MVC?

What is an Exception Filter?


Exception Filter provides an ability to handle the exception for all the method, and controller classes in one place. Exception filters execute when some of the exceptions are thrown from an action. The exception can be anything. This is by creating a class that inherits from IExceptionFilter and FileAttribute interface.

Custom Exception Filter


Exception Filter provides a built-in HandleError attribute to handle exception filter with the built-in attribute we can’t do the following things.

  1. Cannot log the Exception using the HandleError attribute
  2. It is not possible to handle exception occurs outside the controllers.
  3. Exception handling is not possible, depending on the scenario. For Example, one error page when the request comes through AJAX and a different one is a normal request.

Let's look at how to work around these problems by creating a custom exception filter.

Creating Custom Exception Filter


Here I am creating an Employee class for the model inside the model folder.


Employee. class
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace LIBData
{
public class Employee
{
public int Id {
get;
set;
}
[Required(ErrorMessage = "Name Required")]
public string Name {
get;
set;
}
[Required(ErrorMessage = " Designation Required ")]
public string Designation{
get;
set;
}
[Required(ErrorMessage = "Salary Required ")]
public int Salary {
get;
set;
}
}
}

Now we need to add controller class inside the controller folder add.


EmployeeController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LIBUser.CustomFilter;
using LIBUser.Models;
namespace LIBUser.Controllers
{
public class EmployeeController: Controller
{
public EmployeeContext db = new EmployeeContext();
public ActionResult Index()
{
var employee = db .Employees.ToList();
return View(employee);
}
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Employee employee = db.Employees.Find(id);
if (employee == null)
{
return HttpNotFound();
}
return View(employee);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
[CustomExceptionHandlerFilter]
public ActionResult Create(Employee employee)
{
if (ModelState.IsValid)
{
if (employee.Designation== "JuniorForntEndDeveloper" && (employee.Salary < 1000 || employee.Salary > 4000))
{
throw new Exception("Salary is not matching with JuniorForntEndDeveloper.");
}
else if (employee.Designation== "WebDeveloper" && (employee.Salary < 30000 || employee.Salary > 40000))
{
throw new Exception("Salary is not matching with WebDeveloper.");
}
else if (employee.Designation== "Marketing Manager")
{
throw new Exception("Salary is not matching with Marketing Manager");
}
else
{
db .Employees.Add(employee);
db .SaveChanges();
}
}
return RedirectToAction("Index");
}
}
}

Add the following line of code inside the Employee controller.

In this example, I will just demonstrate how to use a Custom Exception filter you can change your controller as per the requirements.

Now, we need to add the view for Create action method and Index action method. Right-click on create method and add view.


Create View
@model LIBData.Employee
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/LibStudent.cshtml";
}<div class="container"><div class="card"><div class="card-header bg-dark">
<strong class="card-title" style="color : white;"> Add Employee Details</strong></div>
<div class="card-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()<div class="form-horizontal"><h4>Employee</h4>
<hr>
@Html.ValidationSummary(true, "", new { @class = "text-danger" })<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })</div>
<div class="form-group">
@Html.LabelFor(model => model.Designation, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Designation, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Designation, "", new { @class = "text-danger" })</div>
<div class="form-group">
@Html.LabelFor(model => model.Salary, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Salary, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Salary, "", new { @class = "text-danger" })</div>
<div class="form-group"><div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Create"></div></div></div>
}</div></div></div>
<div>
@Html.ActionLink("Back to List", "Index")</div>

Add the CustomExceptionHandlerFilter class for creating a custom exception handler.

Implements FilterAttribute and IExceptionFilter and overrides the OnException method.

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace LIBUser.Controllers
{
public class CustomExceptionHandlerFilter: FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
ExceptionLogger logger = new ExceptionLogger()
{
ExceptionMessage = filterContext.Exception.Message,
ExceptionStackTrack = filterContext.Exception.StackTrace,
ControllerName = filterContext.RouteData.Values["controller"].ToString(),
ActionName = filterContext.RouteData.Values["action"].ToString(),
ExceptionLogTime = DateTime.Now
};
EmployeeContext dbContext = new EmployeeContext();
dbContext.ExceptionLoggers.Add(logger);
dbContext.SaveChanges();
filterContext.ExceptionHandled = true;
filterContext.Result = new ViewResult()
{
ViewName = "Error"
};
}
}
}

Open App_Start folder inside the App_start folder contains FilterConfig class. Inside this class, we add our new CustomExceptionHandlerFilter in the following way.

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.ApplicationInsights.DataContracts;
using MvcCustomExceptionFilter.CustomFilter;
namespace LIBUser.App_Start
{
public class FilterConfig
{
public static void RegisterGlobalFilter(GlobalFilterCollection filters)
{
filters.Add(new CustomExceptionHandlerFilter());
}
}
}

When you create a project, if you have selected the Empty MVC Template then the FilterConfig class will not be available to you, but if you have selected any ready-mate MVC template then the FilterConfig class will be available within your application. If this file is not available, then just simply create a class file with the name FilterConfig inside the App_Start folder. This FilterConfig class is the place where we used to add the Filters globally for our application. It file will be instantiated when our Web application starts.

Looking for a Trusted ASP.Net Development Company For Your Business?

Now Register our CustomExceptionHandlerFilter in the Global. asax


Global.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using MvcCustomExceptionFilter.App_Start;
namespace MvcCustomExceptionFilter
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
FilterConfig.RegisterGlobalFilter(GlobalFilters.Filters);
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
}

Inside the shared folder of view, it contains the Error. cshtml page modifies the Error. cshtml as per your requirement. If the shared folder does not contain an Error. cshtml you can add a view inside the shared folder and place this code inside the error page.

 
@{
ViewBag.Title = "Error";
}<h1>Error Occured</h1>
<h1 class="alert alert-danger">An unknown error occurred while processing your request.</h1>

Open the web. config file and add the custom error mode inside the system. web

 
<system.web>
<customerrors mode="On"></customerrors>
</system.web>

Now run the application and add the details inside the create view.

AddEmployeeDetails
[Fig:- Add Employee Details]

If we can add the salary that is not range to a specific position it will give an error and we will redirect to the Error page instead of yellow screen or exception. Here I insert salary for JuniorForntEndDeveloper 10000 it will get me an error because in code set salary for JuniorForntEndDeveloper between 1000 to 4000.

Exception
[Fig:-Exception]

After clicking on create button, it gives an Error and redirects to the error page.

Conclusion


Exception filter provides the built-in HandleError attribute but we cannot handle the log error and exceptions that occur inside the controller class, however, with the help of the custom exception we can handle the errors that occur inside the controller class.

Content source: https://www.ifourtechnolab.com/blog/what-is-exception-filter-and-explain-custom-exception-filter-in-asp-net-mvc




PowerApps Consulting Services - Driving Innovation in Enterprise Solutions

Driving innovation while keeping costs in check is something that every executive looks for. Microsoft Power Apps is a leading low-code app ...