Posts

Showing posts with the label BSc CSIT 6th Semester

Explain ASP.NET Web Forms.

 ASP.NET Web Forms • A part of the ASP.NET web application framework and is included with Visual Studio. • You can use to create ASP.NET web applications, the others are ASP.NET MVC, ASP.NET Web Pages, and ASP.NET Single Page Applications.  • Web Forms are pages that your users request using their browser. These pages can be written using a combination of HTML, client script, server controls, and server code. • When users request a page, it is compiled and executed on the server by the framework, and then the framework generates the HTML markup that the browser can render. • An ASP.NET Web Forms page presents information to the user in any browser or client device. • The Visual Studio (IDE) lets you drag and drop server controls to layout your Web Forms page. You can then easily set properties, methods, and events for controls on the page or for the page itself. These properties, methods, and events are used to define the web page's behavior, look and feel, and so on • Based on Mic

Explain Mono of (.NET).

 Mono • Mono is an example of a cross-platform framework available on Windows, macOS, Linux, and more. It was first designed as an open-source implementation of the .NET Framework on Linux. • Mono (like . NET) is tied heavily around the C# programming language, known for its high level of portability. • For example, the Unity game engine uses C# as a cross-platform way of creating video games. This is in part due to the language's design. C# can be turned into CIL (Common Intermediate Language), which can either be compiled to native code (faster, less portable), or run through a virtual machine (slower, more portable). • Mono provides the means to compile, and run C# programs, similar to the.NET Framework.

Explain .NET Core and .NET Core Characteristics

 .NET Core .NET Core is a new version of the .NET Framework general-purpose development platform maintained by Microsoft. It is a cross-platform framework that runs on Windows, macOS, and Linux operating systems used to build different types of applications such as mobile, desktop, web, cloud, loT, machine learning, microservices, game, etc.  .NET Core is written from scratch to make it a modular, lightweight, fast, and cross-platform Framework.  It includes the core features that are required to run a basic .NET Core app.  Other features are provided as NuGet packages, which you can add to your application as needed. In this way, the .NET Core application speed up the performance, reduce the memory footprint, and becomes easy to maintain. .NET Core Characteristics Open-source Framework: .NET Core is an open-source framework maintained by Microsoft and available on GitHub under MIT and Apache 2 licenses. It is a .NET Foundation project. Cross-platform: .NET Core runs on Windows, macOS

How to create Web API in ASP.NET Core.

Image
Create a controller that has 3 things: It should have the [ApiController] attribute on them. This attribute tells that the controller will serve HTTP API Responses. Derive from ControllerBase class instead of Controller class.  It should have attribute routing applied on them like [Route("someUrl/[controller]")]. The controller of a Web API looks like this:-

Explain important interfaces and classes for built-in loc containers.

Image
 The followings are important interfaces and classes for built-in loc containers:   Interfaces 1. IService Provider 2. IServiceCollection Classes 1. Service Provider 2. ServiceCollection. 3. Service Description 4. ServiceCollection Service Extensions 5. ServiceCollection ContainerBuilderExtensions                                           Figure:-  Interfaces and classes for built-in loc containers Interfaces 1. IService Provider 2. IServiceCollection 1.  IServiceCollection •  We can register application services with a built-in loC container in the Configure method of Startup class by using IService Collection. IServiceCollection interface is an empty interface.  It just inherits IList<servicedescriptor>. •  The ServiceCollection class implements the IService Collection interface. • So, the services you add in the IServiceCollection type instance, actually create an instance of Service Descriptor and add it to the list. 2. IService Provider •  IService Provider includes the GetS

Explain BUILT-IN IOC CONTAINER.

 BUILT-IN IOC CONTAINER • The built-in container is represented by IService Provider implementation that supports constructor injection by default. The types (classes) managed by built-in  IOC containers are called services. There are basically two types of services in ASP.NET Core: 1. Framework Services: Services that are a part of ASP.NET Core framework such as Application Builder, I Hosting Environment, ILoggerFactory, etc.  2. Application Services: The services (custom types or classes) which you as a programmer create for your application. • In order to let the  IOC  container automatically inject our application services, we first need to register them with the  IOC  container. • ASP.NET Core framework includes a built-in  IOC  container for automatic dependency injection. The built-in loC container is a simple yet effective container.

Explain DEPENDENCY INJECTION AND IOC CONTAINERS.

 DEPENDENCY INJECTION AND IOC CONTAINERS • ASP.NET Core is designed from scratch to support Dependency Injection. •  ASP.NET Core injects objects of dependency classes through constructor or method by using built-in loC container. •  ASP.NET Core framework contains a simple out-of-the-box loC container which does not have as many features as other third-party loc containers. If you want more features such as auto-registration, scanning, interceptors, or decorators then you may replace the built-in loC container with a third-party container.

Explain JSON and how to add JSON Patch To Your ASP.Net Core Project

 JSON The new built-in JSON support, System.Text.Json, is high-performance, low allocation, and based on Span<byte>. The System.Text.Json namespace provides high-performance, low allocating, and standards-compliant capabilities to process JavaScript Object Notation (JSON), which includes serializing objects to JSON text and deserializing JSON text to objects, with UTF-8 support built-in.  It also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM) for random access of the JSON elements within a structured view of the data.  Adding JSON Patch To Your ASP.Net Core Project Run Package Manager and install JSON Patch Library with the command: Install-package Microsoft.AspNetCore. JsonPatch Write in your controller public class Person [ ( public string FirstName (get; set;)  public string LastName (get;set;)) ] [Route ("api/ [controller]")]  public class PersonController: Controller ( private readonly Person _def

Explain API Controllers.

Image
 API Controllers API Controller is just a normal Controller, that allows data in the model to be retrieved or modified, and then delivered it to the client. It does this without having to use the actions provided by the regular controllers. The data delivery is done by following a pattern known by name as REST. REST Stands for REpresentational State Transfer pattern, which contains 2 things: a) Action Methods which do specific operations and then deliver some data to the client. These methods are decorated with attributes that make them be invoked only by HTTP requests.  b) URLs that define operational tasks. These operations can be sending full or part of data, adding, deleting, or updating records. In fact, it can be anything. MVC and API controllers both derive from the Controller class, which derives from ControllerBase: public class MyMvc20Controller Controller {} [Route("api/ [controller]")] public class MyApi20Controller Controller {} As of Core 2.1 (and 2.2), the temp

What do you mean by ASP.NET Core Web API Architecture also Characteristics of ASP.NET Core Web API Architecture

Image
 ASP.NET Core Web API Architecture •ASP.NET Web API is mainly based on the MVC architecture. The .NET framework and .NET Core also share a number of APIs. New Features in ASP.NET Core Web API Cross-Platform - ASP.NET Web API Core is cross-platform; therefore, it is suitable for running on any platform like Windows, Mac, or Linux. Earlier ASP.NET applications were not able to run on Linux and Mac operating systems. Backward Compatibility - For existing applications, ASP.NET Web API Core supports two frameworks. Faster- ASP.NET Web API Core is much faster than previous versions Static Content - wwwroot folder contain all the static content e.g. js, CSS, images.

Explain Web API Applications.

 Web API Applications Before ASP.NET Web API core, the two-different frameworks MVC and Web API were pretty much similar. Both are used to support Controller and action methods. In the earlier version, the main purpose of Web API was to make REST API calls and there was a view engine like Razor. On the other hand, MVC was designed for HTML front ends to communicate to the backend in a standard web application.  However, when ASP.NET Web API core was released, the main target was to support JSON-based REST API. It combines the key feature of both MVC and the old Web API framework.

Explain URL Patterns.

Image
 URL Patterns • Each route must contain a URL pattern. This Pattern is compared to an incoming URL. If the pattern matches the URL, then it is used by the routing system to process that URL. • The URL Pattern {controller=Home}/{action=Index}/{id?} Registers route where the first part of the URL is Controller, the second part is the action method to invoke on the controller. The third parameter is additional data in the name of id. • Each segment in the incoming URL is matched to the corresponding segment in the URL Pattern. • {controller=Home}/{action=Index}/{id?} has three segments. The last one is optional.

Explain Route , Route colllection, MVCRouteHandler , Route Handler

 What is a Route •  The Route is similar to a roadmap. We use a roadmap to go to our destination. Similarly, the ASP.NET Core Apps use the Route to go to the controller action. • Each Route contains a Name, URL Pattern (Template), Defaults, and Constraints. The URL Pattern is compared to the incoming URLs for a match. An example of URL Pattern is {controller=Home}/{action=Index}/{id?} • The Route is defined in Microsoft.AspNetCore.routing namespace. Route Collection The Route Collection is the collection of all the Routes in the Application. An app maintains a single in-memory collection of Routes. The Routes are added to this collection when the application starts. The Routing Module looks for a Route that matches the incoming request URL on each available Route in the Route collection. The Route Collection Microsoft.AspNetcore.routing. is defined in the namespace What is a Route Handler The Route Handler is the Component that decides what to do with the route. When the routing Engine

Explain the types of Model Validation DataAnnotations

 Types of Model Validation DataAnnotations 1. [Required] - Specifies that a value needs to be provided for this property 2. [StringLength] - Allows you to specify at least a maximum amount of characters. We can also add Minumum Length as well.  [StringLength (50, MinimumLength = 3)] 3. [Range] - specify a minimum and a maximum value for a numeric property (int, float, double etc.) [Range(1, 100)] 4. [Compare] - allows you to set up a comparison between the property [Compare ("MailAddressRepeated")] public string MailAddress { get; set; } public string MailAddressRepeated { get; set; }

Explain Model Validation.

 Model Validation They will allow you to enforce various kinds of rules for your properties, which will be used in your views and in your Controllers, where you will be able to check whether a certain Model is valid in its current state or not (e.g. after a FORM submission). Let's add just a couple of basic validation to the WebUser public class WebUser { [Required] [StringLength (25)] public string FirstName { get; set; } [Required] [StringLength(50, MinLength (3)] public string LastName (get; set; } } [Required] [EmailAddress] public string MailAddress { get; set; } } Notice how the three properties have all been decorated with DataAnnotations. First of all, all properties have been marked with the [Required] attribute, meaning that a value is required it can't be NULL.  [StringLength] attribute makes requirements about the maximum, and in one case minimum, length of the strings. These are of course particularly relevant if your Model corresponds to a database table, where st

Explain Data Annotations.

 Data Annotations Data Annotations (sometimes referred to as Model Attributes), which basically allow you to add metadata to a property. The cool thing about DataAnnotations is that they don't disturb the use of your Models outside of the MVC framework. When generating the label, the name of the property is used, but property names are generally not nice to look at for humans. As an example of that, we might want to change the display version of the FirstName property to "First Name". public class WebUser { [Display (Name="First Name")] public string FirstName { get; set; } }

Explain Model Binding in ASP.NET Core with exqample.

 Model Binding in ASP.NET Core The Model Binding extracts the data from an HTTP request and provides them to the controller action method parameters. The action method parameters may be simple types like integers, strings, etc. or complex types such as Student, Order, Product, etc. The controller action method handle the incoming HTTP Request. Our application default route template ({controller-Home}/{action=Index}/{ld?})  When you load this url - http://localhost:52191/home/details/101, shows the Details action method. public ViewResult Details(int Id) var student Details= listStudents. FirstOrDefault(std => std. StudentId == Id); return View(studentDetails); Example In Model Folder, create a class WebUser.cs public class WebUser { public string FirstName { get; set; } public string LastName { get; set; } } In Controller Folder, create a new Controller as UserController.cs and add action method as follows: [HttpGet] public IActionResult SimpleBinding() { return View(new WebUser() {

Explain View model and its uses.

 ViewModels There are, however, a lot of situations where you may want to create a specific View Model for a specific View. This can be to extend or simplify an existing Model, or because you want to represent something in a View that's not already covered by one of your models. ViewModels are often placed in their own directory in your project, called "View Models". Some people also prefer to postfix the name of the class with the word viewModel, e.g. "AddressViewModel" or "EditUserViewModel". When to use ViewModel? To represent something in a View that's not already contained by an existing Model: When you pass a Model to a View, you are free to pass e.g. a String or another simple type, but if you want to pass multiple values, it might make more sense to create a simple ViewModel to hold the data, like this one: public class Address ViewModel { public string StreetName { get; set; } public string ZipCode { get; set; } } To access the data of mul

Explain Model in an MVC.

 Model The Model in an MVC application should represent the current state of the application, as well as business logic and/or operations. A very important aspect of the MVC pattern is the Separation of Concerns (SOC). SOC is achieved by encapsulating information inside a section of code, making each section modular, and then having strict control over how each module communicates.  For the MVC pattern, this means that both the View and the Controller can depend on the Model, but the model doesn't depend on neither the View nor the Controller. As mentioned, the Model can be a class already defined in your project, or it can be a new class you add specifically to act as a Model. Therefore, Models in the ASP.NET MVC framework usually exists in a folder called "Models".

How to setup Routes in URL Routing?

Image
 How to setup Routes There are two different ways by which we can set up routes. 1. Convention-based routing 2. Attribute routing Convention-based routing The Convention-based Routing creates routes based on a series of conventions, defined in the ASP.NET Core Startup. cs file. Attribute routing Creates routes based on attributes placed on controller actions. The two routing systems can co-exist in the same system. The Convention-based Routes are configured in the Configure method of the Startup class. The Routing is handled by the Router Middleware. ASP.NET MVC adds the routing Middleware to the Middleware pipeline when using the app.UseMVC or app. UseMvcWith DefaultRoute.