How to encrypt and decrypt C# console application with example
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Friday, August 7, 2020
Wednesday, August 5, 2020
Dependency Injection in C#
Dependency Injection (DI) is a software design pattern. It allows us to develop a loosely-coupled code. The intent of Dependency Injection is to make code maintainable. Dependency Injection helps to reduce the tight coupling among software components. Dependency Injection reduces the hard-coded dependencies among your classes by injecting those dependencies at run time instead of design time technically. This article explains how to implement Dependency Injection in C# and .NET code.
We have the following ways to implement Dependency Injection.
1) Constructor Injection
2) Property Injection
3) Method Injection
We have the following ways to implement Dependency Injection.
1) Constructor Injection
2) Property Injection
3) Method Injection
Sunday, August 2, 2020
Recent questions asking in interview - C# , asp.net , asp.net mvc , asp.net core , sql , entity framework
Q. Sql Injection
Q. Sql cache
Q. Exception Filter purpose
Q. MVC Validations - Jquery ka use yaha par
Q. Await Async
1. What is the difference between SingleOrDefault and FirstOrDefault?
LINQ provides element operators that return a single element or a specific element from a collection. The elements operators are Single, SingleOrDefault, First, FirstOrDefault, Last, LastOrDefault.
LINQ provides element operators that return a single element or a specific element from a collection. The elements operators are Single, SingleOrDefault, First, FirstOrDefault, Last, LastOrDefault.
Single
It returns a single specific element from a collection of elements if element match found. An exception is thrown, if none or more than one match found for that element in the collection.
SingleOrDefault
It returns a single specific element from a collection of elements if element match found. An exception is thrown, if more than one match found for that element in the collection. A default value is returned, if no match is found for that element in the collection.
First
It returns first specific element from a collection of elements if one or more than one match found for that element. An exception is thrown, if no match is found for that element in the collection.
FirstOrDefault
It returns first specific element from a collection of elements if one or more than one match found for that element. A default value is returned, if no match is found for that element in the collection.
When to use Single, SingleOrDefault, First and FirstOrDefault
You should take care of following points while choosing Single, SingleOrDefault, First and
FirstOrDefault:
When you want an exception to be thrown if the result set contains many records, use Single or SingleOrDefault.
When you want a default value is returned if the result set contains no record, use SingleOrDefault.
When you always want one record no matter what the result set contains, use First or FirstOrDefault.
When you always want one record no matter what the result set contains, use First or FirstOrDefault.
When you want a default value if the result set contains no record, use FirstOrDefault.
Perfomance of SingleOrDefault and FirstOrDefault
FirstOrDefault usually performs faster as compared to SingleOrDefault, since these iterate the collection until they find the first match. While SingleOrDefault iterates the whole collection to find one single match.
Q.2 AllowAnonymous Attribut and Authorize Attribute.?
One of the new features in ASP.NET MVC 4 is the AllowAnonymous Attribute that helps you secure an entire ASP.NET MVC 4 Website or Controller while providing a convenient means of allowing anonymous users access to certain controller actions, like the login and register Actions.
AllowAnonymous Attribute in ASP.NET MVC 4
As mentioned, if you create a new ASP.NET MVC 4 Internet Project in Visual Studio 2010 or Visual Studio 11 and view the AccountController you will notice the generous use of the AllowAnonymous Attribute on various login and register controller actions. Here are a few of those controller actions.
[Authorize]
public class AccountController : Controller
{
[AllowAnonymous]
public ActionResult Login()
{
// ...
}
[AllowAnonymous]
[HttpPost]
public JsonResult JsonLogin(LoginModel model, string returnUrl)
{
// ...
}
[AllowAnonymous]
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
// ...
}
[AllowAnonymous]
public ActionResult Register()
{
// ...
}
[AllowAnonymous]
[HttpPost]
public ActionResult JsonRegister(RegisterModel model)
{
// ...
}
[AllowAnonymous]
[HttpPost]
public ActionResult Register(RegisterModel model)
{
// ...
}
}
The idea is pretty simple. The Authorize Attribute on the AccountController in this ASP.NET MVC 4 Application denies anonymous access to every controller action. However, we need to allow anonymous access to the login and register controller actions so we decorate them with the AllowAnonymous Attribute which negates the Authorize Attribute and allows anonymous access.
The idea is pretty simple. The Authorize Attribute on the AccountController in this ASP.NET MVC 4 Application denies anonymous access to every controller action. However, we need to allow anonymous access to the login and register controller actions so we decorate them with the AllowAnonymous Attribute which negates the Authorize Attribute and allows anonymous access.
Q.3 What is mvc Filters and custom filters . ?
ASP.NET MVC provides Action Filters for executing filtering logic either before or after an action method is called. Action Filters are custom attributes that provide declarative means to add pre-action and post-action behavior to the controller's action methods.
In software engineering, dependency injection is a technique in which an object receives other objects that it depends on. These other objects are called dependencies. In the typical "using" relationship the receiving object is called a client and the passed object is called a service.
Q.4 What is Dependency injection with examples . ?
Wednesday, July 29, 2020
Microsoft SEAL is an easy-to-use and powerful open source homomorphic encryption library,
Microsoft SEAL is an easy-to-use and powerful open-source homomorphic encryption library, developed by researchers in the Cryptography and Privacy Research Group at Microsoft Research. Microsoft SEAL is licensed under the MIT license.
How to use this Microsoft SEAL open source in .net
Examples : -
Subscribe to:
Posts (Atom)
Rewrite whole Web Site System and Sub System with data migration to new system.
Can you please share me your skype id or whats up number for better communications my skype id is - jitendra.tech whats up - +919617741414...
-
Step 1. First of all create a table named ImagesDisplay to store Image Paths and their names. Step 2. Add this HTML cod...
-
DotNetNuke is a web content management system base on Michrosoft .NET. The Community Edition is open source DotnetNuke was written in VB...
-
You all welcome on dotnetstory.com dotnetstory
-
We need to follow this steps Step - 1 public ActionResult Index() { ViewBag.ProjectCategory = db.DNS_ProjectCategory.ToList();...
-
Step 1. Make a table named tblFiles for storing files in SQL. Step 2. Make required HTML changes and add this piece of code ...
-
Some time there would be requirement of scrollable gridview, but no pagination, at that time we have to take help of traditional HTML a...
-
Step 1. First create a new table named tbl_ClientInformation for showing data in gridview and which we have to convert in Word, Exc...
-
C# Programming Features & Programs Design Principle in C# OOP'S in C# C# - Tutorials C# - Interview
-
What is asp.net core and history of asp.net core with a different version Asp.net Core is not an updated version of ASP.NET, asp.net...
-
Step1. First of all make a table named tblUpload for storing files. Step2. Make HTML for showing files i...