Download Logo

ActionResult types

What is the difference between ‘ViewResult’ and ‘ActionResult’? In ASP.NET MVC, both ViewResult and ActionResult are classes that represent the result of an action method. The primary difference between them lies in their level of abstraction. ActionResult: ActionResult is the base class for all action results in ASP.NET MVC. It provides a high level of abstraction, allowing action methods to return various types of results, such as ViewResult, RedirectResult, JsonResult, etc. ...

August 3, 2024 · 2 min · 251 words · PrashantUnity
Download Logo

ADO.NET Q&A

1. What is ADO.NET? ADO.NET (ActiveX Data Objects) is a data access technology in the .NET framework used to interact with data sources, such as databases. It provides a set of classes for connecting to databases, executing commands (queries, updates), and retrieving results into datasets or data readers. 2. Differentiate between DataSet and DataReader DataSet: It’s an in-memory cache of data retrieved from the database. It can hold multiple DataTables, relationships, and constraints. It is disconnected, meaning it doesn’t need an active connection to the database once data is loaded. DataReader: It provides a read-only, forward-only stream of data from the database. It’s faster and uses less memory compared to DataSet but is less flexible as it doesn’t store data locally. 3. Explain the steps to connect to a database using ADO.NET To connect to a database using ADO.NET: ...

August 3, 2024 · 3 min · 437 words · PrashantUnity
Download Logo

App settings in .NET

Reading Configuration from appsettings.json 1 2 3 4 5 var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); var val =config["randomString"]; Binding Configuration to Static Classes 1 2 3 4 5 6 7 8 9 10 11 12 13 public static class RandomClass { public const string hello = "hello"; public static readonly string bello = "90"; static RandomClass() { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); bello = configuration["MySettings:Bello"]; } } 1. Add appsettings.json to Your Project Ensure you have an appsettings.json file in the root of your project. It might look something like this: ...

August 3, 2024 · 3 min · 434 words · PrashantUnity
Download Logo

ASP.NET Core middleware

How does middleware differ from HTTP modules in ASP.NET? Middleware in ASP.NET Core is a more flexible and lightweight approach compared to HTTP modules in traditional ASP.NET. Middleware can be added or removed easily in the application’s startup configuration. It allows for better control over the request pipeline and can be organized into a pipeline of components, whereas HTTP modules are more tightly coupled and don’t offer the same level of flexibility. ...

August 3, 2024 · 2 min · 414 words · PrashantUnity
Download Logo

Last-minute interview prep

Programming Questions 1. Array Manipulation: Move all zeros to the end of a given array. Solve the problem of buying and selling a product to maximize profit, given its prices on different days from a given price array. Find the 3rd highest element in an array. Find the 2nd duplicate number in an array. 2. String Manipulation: Given a string s, find the length of the longest substring without repeating characters. (Example: s = "abcabcbb") Find the first repeating number in an array. (Example: arr[] = {10, 5, 3, 4, 5, 3, 6}) Given a List<string>: var list = new List<string> {"Ravi Kumar", "Neha Gupta", "Arti Gupta", "Kamal Rai"}; get the count of the surnames and maintain the order. 3. C# Code Execution: Determine the order of printing in a C# class with static constructors, instance constructors, and regular constructors. General Problem-Solving: Dry run a piece of code and optimize its complexity. C# Core Concepts 1. LINQ (Language Integrated Query): Steps for initializing LINQ queries. How intermediate operations work in LINQ (e.g., Where, Select). How terminal operations work in LINQ (e.g., ToList(), FirstOrDefault()). What is a parallel LINQ (PLINQ) query? 2. Collections Framework: Difference between IComparable and IComparer. How Dictionary<TKey, TValue> works in C#. Difference between ICollection and IEnumerable. Overview of the Collection framework starting from the base interface IEnumerable and its methods. 3. Exception Handling: How to create custom exceptions in C#. Difference between Thread.Sleep() and Task.Delay() methods. 4. Polymorphism and OOP Concepts: Method overloading and method overriding. Difference between == and .Equals() in string comparison. Multithreading and the use of lock statements. Understanding marker interfaces, functional interfaces (like delegates), and design patterns such as Singleton and Factory. SOLID principles. 5. ASP.NET Core: Difference between ASP.NET Core MVC and Web API, and which is better and why. ASP.NET Core inbuilt server (Kestrel). Difference between Razor Pages and MVC. Understanding JWT tokens and how they secure applications using HTTPS. 6. Miscellaneous C#: Understanding the order of execution in blocks (static constructor, instance constructor, regular constructor). Questions related to classes and methods, such as Animal and Cat with overridden methods. SQL: 1. Complex Queries: Find the third-highest salary in SQL. Understanding the order of execution in SQL queries (e.g., Empid, dept, manager id). 2. Data Structures and Algorithms (DSA): Array and String Problems: ...

August 3, 2024 · 12 min · 2456 words · PrashantUnity
Download Logo

MVC filters

What do you understand by filters in MVC? Filters are components that enable developers to inject logic into the request processing pipeline at various stages. Filters are used to perform tasks such as logging, authentication, authorization, exception handling, caching, and more. Filters provide a way to encapsulate cross-cutting concerns. Filters can be applied globally to the entire application or selectively to specific controllers or action methods. There are several types of filters in ASP.NET MVC: ...

August 3, 2024 · 3 min · 585 words · PrashantUnity
Download Logo

MVC request lifecycle

Explain the MVC application life cycle Any web application has two primary execution steps: Understanding the request Sending out an appropriate response MVC application life cycle includes two main phases: Creating the request object Sending response to the browser The steps included in creating a request object are: Request Routing: When a user makes a request, the ASP.NET MVC application starts by using a routing engine to determine which controller and action method should handle the request. The route configuration defines how URLs map to controllers and actions. Controller Execution: ...

August 3, 2024 · 3 min · 432 words · PrashantUnity
Download Logo

MVC routing Q&A

How is routing carried out in the MVC pattern? The routing mechanism in ASP.NET MVC is responsible for determining which controller and action should handle a particular request based on the URL of the request. The routing process typically involves the following steps: Incoming Request: When a user makes a request to our ASP.NET MVC application by entering a URL in the browser, the request is received by the ASP.NET runtime. ...

August 3, 2024 · 4 min · 802 words · PrashantUnity
Download Logo

MVC set — starter

What is ASP.NET MVC Core? ASP.NET MVC Core is a modern, open-source, cross-platform framework for building web applications. It is a part of the larger ASP.NET Core framework and follows the Model-View-Controller (MVC) architecture pattern. MVC Core is designed to offer greater performance, scalability, and flexibility compared to its predecessors. It allows developers to create web applications that can run on various platforms (Windows, Linux, macOS) and supports cloud-based deployment. Key features include: ...

August 3, 2024 · 40 min · 8437 words · PrashantUnity
Download Logo

Services in Razor views

Accessing Services in Views 1. Using Dependency Injection in Views with Razor Pages To use services directly in Razor Pages, follow these steps: 1.1. Register Services in Startup.cs Ensure your service is registered in the DI container within Startup.cs (or Program.cs in .NET 6 and later). 1 2 3 4 5 public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddScoped<IMyService, MyService>(); // Register your service } 1.2. Inject Services into the View In Razor Pages (.cshtml files), you can inject services directly into the page using the @inject directive. ...

August 3, 2024 · 3 min · 530 words · PrashantUnity