The main purpose of "Dot Net Labs" provide the dot net program. You can learn dot net, .Net Core, C#, SQL, Linq step-by-step.

Sunday, 21 May 2023

How to implement Identity, Connection String, IdentityDbContext in .Net 6 Part - 2


 In this article, we are going to create Web API using .Net 6 and Asp.Net Core and also implement JWT Authentication.

Right click on "TimeManager.DAL" add create a folder and put name "Models"

Create "User" class inside "Models" folder see below code.

Friday, 19 May 2023

What is C# and its features



C# is an Object Oriented  Programming Language (OOP). The common traits are encapsulation, inheritance and polymorphic.

All the C# files are saved with file extension .CS

C# includes the following five types of tokens.

  • Keywords
  • Identifies
  • Literals
  • Identifies
  • Operators
  • Punctuates

Programming Language is a process of creating computer programs or in the other word software to solve a particular problem.

C# is developed by Microsoft Corporation in year 2000.

C# can be used to build variety of applications. There are following example of applications developed by c#.

Window Application using WinForm Or WPF

Mobile Application for Phones such as Nokia Lumia (Native support) But you can use a 3rd party library called "Xamarin" to create mobile application for Android and IOS as well.

Web Application using Asp.net web forms or asp.net MVC.


As per the interview perspective this is question is very important so please try to learn in-depth for good impression.


What is C# and latest version of C#?


What is C#?

C# stands out as a powerful and versatile language. It is a modern, object-oriented programming language that was introduced by Microsoft in the early 2000s, C# provides a flexible and efficient platform for building a wide range of applications, from desktop software to web applications and even mobile apps. C# is specifically designed to run on the .NET Framework, which provides a comprehensive set of libraries and tools for developing applications on the Windows platform.


Key Features of C#:

Object-Oriented Approach: C# follows the principles of object-oriented programming (OOP), enabling developers to create reusable and modular code through the use of classes, objects, inheritance, and polymorphism.


Type Safety: C# is a statically-typed language, which means that all variables and expressions must have a specific data type defined at compile-time. This ensures type safety and helps catch errors early in the development process.


Memory Management: C# utilizes automatic memory management through a process known as garbage collection. This feature helps simplify memory management tasks by automatically clearing memory that is no longer in use, reducing the risk of memory leaks and improving application performance.


Language Interoperability: C# is designed to be language interoperable, allowing developers to integrate code written in different languages such as Visual Basic .NET and C++ into the same application. This interoperability enhances code reusability and promotes collaboration among developers.


Exception Handling: C# provides robust support for handling exceptions, allowing developers to catch and handle errors gracefully during the execution of their programs. This helps improve the reliability and stability of applications, making them more resilient to unexpected issues.


Latest Version of C#:

The latest stable version of C# is C# 10, which was released along with .NET 6.0 in November 2022. You can use its feature with the .Net 7 SDK.


Note: C# 12 features have been introduced in previews.



Thursday, 18 May 2023

Create .Net 6 Web API project with Three Tier Architecture - Part 1


Introduction

We will see three tier architecture and how to create the Business Access Layer and Data Access Layer in our project, as well as how to add references between the project.

Project Structure

Here we are going to use three-tier architecture, with a business access layer, a data access layer, and an application presentation layer, see the below diagram how to interact layers.

Let's discuss these layers

Presentation Layer:

In short, called PL. This layer is the top layer of the three-tier architecture. The main responsible for the user interface and user interaction. It handles user input and display information to the user.

Business Access Layer:

In short, called BAL, Contains the core business logic and set rules of the application, handles the processing, manipulation of data, and validates and enforces business rules and constraints. Typically includes classes and methods that represent business entities, services, and workflows.

Data Access Layer:

In short, called DAL, Encapsulates database queries and CRUD (Create, Read, Update, Delete) operations. It is responsible for accessing and manipulating data from various data sources like database, web services. DAL utilizes technologies such as ADO.NET, Entity Framework, or an Object-Relational Mapping(ORM) framework.

Configuring Layers

Right click on the project and go to the new project window and then add .net core class liabray project.

Add the class Liabrary project for Data Access Layer and Business Access Layer.


Add References

In the Presentation Layer,  add the references to the Data Access Layer and the Business Access Layer.

Right click on the presentation layer and then click on Add then go to Project Reference


Add the references by check to all checkboxes


Now we will add the Data Access Layer project references to the Business Layer.

Same right click on the business access layer and then click Add button > Project References


Remember

  • Data Access Layer's main goal is to interface with the database and the business layer.
  • DAL can have the following folders as per your requirement.
    • Contacts
      • We define the interface that has the function that performs the desired functionalities with the database.
    • Data
      • We have Db Context class which is very important for accessing the data from the database.
    • Migrations
      • The migration folder contains information on all the migrations we performed during the construction of the project. 
    • Models
      • This folder contains domain-specific data, and business logic models, which represent the structure of the data as public attributes, business logic, and methods.
    • Repositories
      • We add repository classes against each model and write the CRUD function that communicates with the database using the entity framework.
  • Business layer can have extensions methods and services folder that make the logical decision and evaluations the main function is to process the data between surrounding layers.
  • Presentation layer present the data that we get from the business access layer and give the results to the front-end user.
Advantages of 3-Tier Architecture

The three-tier architecure offers several advantages that easy to the development and maintenance of robust and scalable applications. Below are some key benefits of using a three-tier architecture.

Separation of Concerns: The architecture separates the application into distinct layers, with each layer having its own set of responsibilities. It enhances code reusability, maintainability, and makes it easier to update or modify individual layers without affecting the others.

Scalability: Three-tier architecture enables horizontal scalability by allowing each layer to be scaled independently. For example, if the application experiences increased traffic or data load, you can add more servers to the presentation or business logic layer without affecting the data access layer. This scalability is crucial for handling growing user demands and ensuring optimal performance.

Flexibility and Adaptability: The clear separation of layers in the architecture facilitates flexibility and adaptability. Each layer can be developed using different technologies, frameworks, or platforms as long as they can communicate with each other through well-defined interfaces. This enables the use of specialized tools or technologies for specific layers, making it easier to incorporate new technologies or update existing ones without impacting the entire application.

Improved Security: By separating the layers, the architecture can enhance security. The data access layer can implement security measures like encryption, parameterized queries, and access control to protect against malicious attacks. The business logic layer can enforce security rules and validation to ensure the integrity of data and prevent unauthorized access. Separating the layers also minimizes the exposure of sensitive information in the presentation layer.

Testability and Maintainability: The three-tier architecture promotes testability and maintainability. Each layer can be independently tested, allowing for more focused and comprehensive testing. It simplifies unit testing, integration testing, and regression testing, as changes in one layer are less likely to affect other layers. Additionally, the separation of concerns makes it easier to identify and fix issues or make updates without impacting the entire application.

Team Collaboration: The architecture supports team collaboration by providing clear boundaries between different layers. Different teams or developers can work concurrently on different layers, making it easier to divide the workload and foster collaboration. It also promotes modular development practices, allowing teams to work on specific layers without disrupting others.

Thanks

Tuesday, 16 May 2023

What is the difference between ref and out keywords in C#?


The ref and out keywords in C# are used to pass arguments to methods by reference instead of by value. Both ref and out parameters are treated the same at compile-time but different at run-time. However, there is a several differences between the ref and out. We will see difference in the example.


ref Example

using System;

using System.Collections.Generic;

using System.Linq;

 

namespace SoftwareEngineerDotNet

{

    class Program

    {

        static void Main(string[] args)

        {

            // Assign string value

            //parameters should initialize before it pass to ref

            string name = "Amit";

 

            //Pass as a reference parameter

            SetName(ref name);

 

            //Display name

            Console.WriteLine(name);

        }

 

        static void SetName(ref string name2)

        {

            Console.WriteLine(name2);

 

            //Assign the new value

            //Not necessary to initialize the value of a parameter before returning

            name2 = "Kumar";

        }

    }

}

 

Output:

 

Amit

Kumar

out keyword

using System;

using System.Collections.Generic;

using System.Linq;

 

namespace SoftwareEngineerDotNet

{

    class Program

    {

        static void Main(string[] args)

        {

            //Declaring variable without assigning value

            int salary;

 

            //Pass salary variable to method with out keyword

            GetSalary(out salary);

 

            //Display name

            Console.WriteLine("Sum of salary: {0}", salary);

        }

 

        //Method will return the value

        public static void GetSalary(out int salary)

        {

            salary = 5000;

            salary += salary;

        }

    }

}

 

Output:

 

Sum of salary: 10000

 

Sunday, 14 May 2023

What is the difference between readonly and const in C#?


In C# readonly and const are used to define constants but both have some differences. It is the most asked question by the interviewer.


Const

·         Const is used to declare a compile-time constant.

·         Const variable is evaluated at compile-time and cannot be changed at runtime.

·         Const are static by default, so it belongs to the type rather than the instance.

·         Const variables must be initialized with a value at the time of declaration and can only hold simple data types.

 

Example:

using System;

 

namespace SoftwareEngineerDotNet

{

    class MyMainClass

    {

        private const double PI = 3.14;

        static void Main(string[] args)

        {

            const int Age = 20;

            // compile time error.

            // Reassigning a const variable is not allowed

            Age++;

            Console.ReadLine();

        }

    }

}

 

Readonly

·         Readonly keyword is used to declare a runtime constant.

·         Readonly variables can be assigned a value either at the time of declaration or within the constructor of the class.

·         Readonly modifier ensures that the variable's value can only be changed during object initialization or within the constructor. Each instance of the class can have a different value for a readonly field.

 

Example:

using System;

 

namespace SoftwareEngineerDotNet

{

    public class MyClass

    {

        //Some valid scenario to initialize readonly variables

        public readonly int MyReadOnlyField;

        public readonly string MobileNumber = "5487458475";

 

        //readonly fields can be initlized in constructor 

        public MyClass(int value)

        {

            MyReadOnlyField = value;

        }

    }

 

    class MyMainClass

    {

        static void Main(string[] args)

        {

            MyClass myClass = new MyClass(2);

            Console.ReadLine();

        }

    }

}

 

 

Saturday, 21 January 2023

How does HTML Works


 HTML works by using a set of tags and attributes to describe the structure and layout of a web page.

  1. When a web browser requests a web page, the server sends back the HTML file for that page.
  2. The browser then reads the HTML code and converts it into a visual representation of the page, including text, images, and other media.
  3. HTML tags are used to create the structure of the page and define the layout, such as headings, paragraphs, lists, and links.
  4. Attributes are used to provide additional information about the elements, such as their size, color, or location.
  5. CSS can be used in conjunction with HTML to control the presentation and layout of elements on the page.
  6. JavaScript can be used to add interactivity and dynamic behavior to web pages.
The browser uses the HTML, CSS and JavaScript to render the page and display it to the user. Any interaction by the user with the rendered page such as click, form submission, and navigation are handled by the browser and communicated back to the server if the page is dynamic in nature.

In short, HTML provides the structure and content of a web page, CSS provides the presentation, and JavaScript provides interactivity and dynamic behavior.

HTML Introduction


HTML (Hypertext Markup Language) is the standard markup language for creating web pages. It provides a means to describe the structure and layout of a document, using a set of tags and attributes. HTML elements are the building blocks of HTML pages.

An HTML document is made up of a head and a body. The head contains meta-information about the document, such as the title and any linked CSS or JavaScript files. The body contains the actual content of the page, such as text, images, and other media.

HTML tags are used to create the structure and layout of the page, such as headings, paragraphs, lists, links, images, and more. These tags are enclosed in angle brackets and typically come in pairs, with an opening tag and a closing tag. For example, the opening tag for a heading is <h1> and the closing tag is </h1>.

HTML also allows for the use of CSS (Cascading Style Sheets) to control the appearance and layout of elements on the page. And JavaScript can be used to add interactivity and dynamic behavior to web pages.

Here is an example of the simple HTML document


<!DOCTYPE html>

<html>

  <head>

    <title>My HTML Page</title>

  </head>

  <body>

    <h1>Welcome to my HTML Page</h1>

    <p>This is an example of a simple HTML document.</p>

  </body>

</html>


Some of the key features of HTML include:

  1. Structure and layout: HTML provides a way to structure and organize the content of a web page using tags and attributes. This includes elements like headings, paragraphs, lists, links, images, and more.
  2. Links: HTML allows for the creation of hyperlinks, which enable users to navigate between web pages and other resources on the internet.
  3. Multimedia: HTML supports a wide range of multimedia elements, such as images, audio, and video, which can be embedded within web pages.
  4. Forms: HTML provides a way to create forms, which enable users to input and submit information to a web page.
  5. Compatibility: HTML is supported by almost all web browsers, making it a widely compatible language.
  6. Accessibility: HTML allows for the creation of web pages that are accessible to people with disabilities, by providing features like alternative text for images, and proper labeling of form controls.
  7. Semantic structure: HTML5 introduced a more semantic structure to the language, with tags like header, nav, article, section and footer which allows search engines and users to understand the context of the content on the page.
  8. Interactivity: HTML can be combined with JavaScript to create interactive web pages and dynamic behavior.
  9. Styling: HTML can be combined with CSS to control the presentation and layout of web pages.

Why the word HyperText & Markup Language:

"Hypertext" refers to the ability to create links between different pieces of text, allowing users to easily navigate between different pages or sections within a website. "Markup" refers to the way HTML uses tags and attributes to describe the structure and layout of a document. HTML uses a set of predefined tags, such as <p> for paragraphs and <h1> for headings, to mark up the content of a web page and give it structure.

Therefore, HTML is called Hypertext Markup Language because it allows for the creation of hypertext links and uses markup to structure and organize the content of a web page.



Sunday, 6 September 2020

Understand MVC 5 project structure


Hello friends, Here we will learn the structure of the MVC project folder. MVC folder structure guides you to choose a suitable folder to store different types of files. See the below image.


Thanks for reading this blog. We will learn what is Controller in MVC.


Saturday, 5 September 2020

Create MVC 5 Application and Run Application


Hello Friends, Here we will learn how to create default Asp.Net MVC application and run your application. So please follow the following step to creating a project which is easy. I will not take screenshot, it is only time waste. I hope you can create project to use the following steps.

Create Project

  • Launch Visual Studio
  • Go to File  New  Project.Make New Project
  • Select Template  Visual C#  Web in left panel and then select ASP.NET Web Application (.NET Framework) in middle Panel. Give Project Name and click OK.
  • In the next window, select MVC Template and change Authentication to No Authentication. Click OK.
  • Your ASP.NET MVC 5 Project is open now.

Build your Project

  • Build >> Build Solution(CTRL + SHIFT + B)

 

Debug, Compile or Run Your Project

  • Debug  >> Start Debugging(F5)


Project Without Debugging

  • CTRL + F5


Break Execution or Debugging

  • SHIFT + F5


Thanks for reading this blog. We will learn use of ASP.NET MVC 5 Folder Structure. 


 


Sunday, 30 August 2020

How to install Visual Studio 2017


Hello Friends, Here we will learn how to install visual studio 2017. Visual Studio has a complete set of development kit that allows you to develop Web-based apps, Windows Apps, Mobile Apps, Services, and other components in various languages like C#, Visual C++, Visual Basic, F#, etc.

Here we are going to install visual studio 2017 but we can use MVC 5 in Visual Studio 2013/2015.


System Requirement:


  • OS: Windows 7 (Service Pack 1) or higher (Windows 10 Recommended) 
  • Processor: 1.8GHz or higher (Dual Core Recommended) 
  • RAM: 2GB (4GB Recommended) Hard Disk: Minimum 20GB


Download:


Downloading Page: https://visualstudio.microsoft.com/vs/older-downloads/


Installation:


Step 1: Double click on downloaded Installer vs_Community.exe

Step 2: Click the Continue button to accept Microsoft License.

Step 3: Select workload, which you want.

Step 4: After selecting workloads click Install button.

Step 5: In the next screen, you will see the installation progress bar.

Step 6: Click Launch button to open Visual Studio 2017.


Thanks for reading this blog. We will learn how to create MVC 5 application.


Introduction to MVC and Asp.Net MVC 5


Hello Friends, Here we will learn what is MVC and Asp.net MVC. We will learn with pictures and simple ways so that you can understand the real use of MVC.

What is MVC?

MVC is Model View Controller.
MVC is a design pattern.
MVC pattern is used for building Web, Mobile, Desktop application, etc.
MVC is used by all the technologies like Java, .Net, PHP, Angular, etc.

See the below picture to understand MVC

MVC


To learn MVC we need to understand coupling, without couplings we can't understand MVC so see to following two types of coupling

  • Tightly Coupled
  • Loosely Coupled

Tightly Coupled: It means classes and objects are dependent on one another. 

Drawback

  • Reduces the flexibility of the code.
  • Re-usability of the code.

                              Example

  • Asp.Net is web forms is tightly coupled.


Loosely Coupled: It means reducing the dependencies of a class. we can make a separate class that uses different classes directly.

Real-Life Example


MVC stands for Model View Controller. It has different three logins. Now we will try to learn Model, View, Controller in detail. 


Model: 

The model is the c# class.

Perform the database operation like - update, delete, etc.

Business Logic.


View:

The view is the graphic user interface in which the user can interact with system ex- Html, CSS, bootstrap.

Presentation Login.


Controller:

Controllers are classes in c# which handles browser requests.

Mediator Between Model and View.

Get the data from Database.


What is Asp.Net MVC?

ASP.NET MVC is a lightweight, fast, secure, and highly testable framework that integrates existing ASP.NET features.

Asp.net MVC is based on MVC design pattern.

Asp.net MVC is used for web development.

Benefits:

  • Enables the full control over the rendered HTML.
  • Provides clean separation of concerns(SoC).
  • Enables Test Driven Development (TDD).
  • Easy integration with JavaScript frameworks.
  • Following the design of stateless nature of the web.
  • RESTful urls that enables SEO.
  • No ViewState and PostBack events.


Thanks for reading this blog. We will learn how to set up the environment for Asp.Net MVC 5.

Monday, 5 June 2017

How To Add Contact Form (Contact Us Page) in Blogger


Having a contact page on your blog is highly important. It is how visitors, brands and companies can reach you and it's something that every bloger should have. If sharing your email address on your blog is not your cup of tea, a contact form can serve as an easy way for others to get in tough. You can copy below code and paste there you want.

<div><div style="float:left">
<script>
var blogId = '<Enter your blogid>';//this number should be mandatorily edited.
//The below message 5 Strings can also be edited
var contactFormMessageSendingMsg ='Sending...';
var contactFormMessageSentMsg = 'Your message has been sent.';
var contactFormMessageNotSentMsg = 'Message could not be sent. Please try again later.';
var contactFormEmptyMessageMsg ='Message field cannot be empty.';
var contactFormInvalidEmailMsg = 'A valid email is required.'

var widgetLoaded=false;
function sendEmailMsg() {
if(widgetLoaded== false) {
_WidgetManager._RegisterWidget('_ContactFormView', new _WidgetInfo('ContactForm1', 'sidebar', null, document.getElementById('ContactForm1'), {'contactFormMessageSendingMsg': contactFormMessageSendingMsg , 'contactFormMessageSentMsg': contactFormMessageSentMsg , 'contactFormMessageNotSentMsg': contactFormMessageNotSentMsg , 'contactFormInvalidEmailMsg': contactFormInvalidEmailMsg , 'contactFormEmptyMessageMsg': contactFormEmptyMessageMsg , 'title': 'Contact Form', 'blogId': blogId, 'contactFormNameMsg': 'Name', 'contactFormEmailMsg': 'Email', 'contactFormMessageMsg': 'Message', 'contactFormSendMsg': 'Send', 'submitUrl': 'https://www.blogger.com/contact-form.do'}, 'displayModeFull'));
widgetLoaded=true;
document.getElementById('ContactForm1_contact-form-submit').click();
}
return true;
}
</script>
<form name='contact-form'>
<div>Your Name : </div>
<input class='contact-form-name' id='ContactForm1_contact-form-name' name='name' size='30' type='text' value=''/>
<div>Your Email: <em>(required)</em></div>
<input class='contact-form-email' id='ContactForm1_contact-form-email' name='email' size='30' type='text' value=''/>
<div>Your Message: <em>(required)</em></div>
<textarea class='contact-form-email-message' id='ContactForm1_contact-form-email-message' name='email-message' rows='5'></textarea>
<p></p>
<input class='contact-form-button contact-form-button-submit' id='ContactForm1_contact-form-submit' type='button' value='Send' onclick="sendEmailMsg()"/>
<div style='text-align: center; max-width: 450px; width: 100%'>
<p class='contact-form-error-message' id='ContactForm1_contact-form-error-message'></p>
<p class='contact-form-success-message' id='ContactForm1_contact-form-success-message'></p>
</div>
</form>
</div>
<div style="text-align:center"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn5Dn-qCbIqT949GcJ4eA-WRPenLjN5Yl1o8TD95fi1YMQjr5T-FBUIOKVe-7H4rZc7z1YADsV8nqgP_1_RZY8CdpbcZMRqz6vgpfRtNJfea2akXZfRDo16bxsTRFRyXktXGmcSY8Wu1k/s1600/noticeboard_savemoneyindia.jpg" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn5Dn-qCbIqT949GcJ4eA-WRPenLjN5Yl1o8TD95fi1YMQjr5T-FBUIOKVe-7H4rZc7z1YADsV8nqgP_1_RZY8CdpbcZMRqz6vgpfRtNJfea2akXZfRDo16bxsTRFRyXktXGmcSY8Wu1k/s320/noticeboard_savemoneyindia.jpg" width="320" height="201" data-original-width="310" data-original-height="195" /></a>
</div>
</div>

Popular Posts