ASP. NET Interview Questions And Answers. Question 1: What is ASP.
NET? Answer: ASP. NET was developed in direct response to the problems that developers had with classic ASP.
Version 2.0 of Microsoft's cross-platform,NET pivot changes everything. Join us as we explore.NET Core 2.0, ASP.NET Core 2.0, and.NET Standard 2.0. What is the essence of AJAX? For example, I want to have a link on my page such that when a user clicks this link, some information is sent to my server without the. Even more » Account Options. Sign in; Search settings. The SAP Community is the quickest way for users to solve problems, learn more about SAP solutions, and invent new ways to get things done.
Since ASP is in such wide use, however, Microsoft ensured that ASP scripts execute without modification on a machine with the . NET Framework (the ASP engine, ASP. DLL, is not modified when installing the . NET Framework). Thus, IIS can house both ASP and ASP.
NET scripts on the same machine. Advantages of ASP. NETSeparation of Code from HTML: To make a clean sweep, with ASP. NET you have the ability to completely separate layout and business logic. This makes it much easier for teams of programmers and designers to collaborate efficiently.
Support for compiled languages: Developer can use VB. NET and access features such as strong typing and object- oriented programming. Using compiled languages also means that ASP. NET pages do not suffer the performance penalties associated with interpreted code. ASP. NET pages are precompiled to byte- code and Just In Time (JIT) compiled when first requested. Subsequent requests are directed to the fully compiled code, which is cached until the source changes.
Use services provided by the . NET Framework: The . NET Framework provides class libraries that can be used by your application. Some of the key classes help you with input/output, access to operating system services, data access, or even debugging. We will go into more detail on some of them in this module.
Graphical Development Environment: Visual Studio . NET provides a very rich development environment for web developers. You can drag and drop controls and set properties the way you do in Visual Basic 6.
And you have full Intelli. Sense support, not only for your code, but also for HTML and XML. State management: To refer to the problems mentioned before, ASP. NET provides solutions for session and application state management. State information can, for example, be kept in memory or stored in a database. It can be shared across web farms, and state information can be recovered, even if the server fails or the connection breaks down. Update files while the server is running: Components of your application can be updated while the server is online and clients are connected.
The framework will use the new files as soon as they are copied to the application. Removed or old files that are still in use are kept in memory until the clients have finished. XML- Based Configuration Files: Configuration settings in ASP.
NET are stored in XML files that you can easily read and edit. You can also easily copy these to another server, along with the other files that comprise your application.
ASP. NET Overview. Here are some points that give the quick overview of ASP. NET. ASP. NET provides services to allow the creation, deployment, and execution of Web Applications and Web Services. Like ASP, ASP. NET is a server- side technology.
Web Applications are built using Web Forms. ASP. NET comes with built- in Web Forms controls, which are responsible for generating the user interface.
They mirror typical HTML widgets like text boxes or buttons. If these controls do not fit your needs, you are free to create your own user controls. Web Forms are designed to make building web- based applications as easy as building Visual Basic applications. For further information click on the link: Question 2: What are the different validators in ASP.
NET? Answer: ASP. NET validation controls define an important role in validating the user input data.
Whenever the user gives the input, it must always be validated before sending it across to various layers of an application. If we get the user input with validation, then chances are that we are sending the wrong data. So, validation is a good idea to do whenever we are taking input from the user. There are the following two types of validation in ASP.
NET: Client- Side Validation. Server- Side Validation.
Client- Side Validation: When validation is done on the client browser, then it is known as Client- Side Validation. We use Java. Script to do the Client- Side Validation. Server- Side Validation: When validation occurs on the server, then it is known as Server- Side Validation.
Server- Side Validation is a secure form of validation. The main advantage of Server- Side Validation is if the user somehow bypasses the Client- Side Validation, we can still catch the problem on server- side.
The following are the Validation Controls in ASP. NET: Required. Field. Validator Control. Compare. Validator Control.
Range. Validator Control. Regular. Expression. Validator Control. Custom. Field. Validator Control. Validation. Summary. For further information click on the link: Question 3: What is View State?
Answer: View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page- Level State Management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post- back.
A web application is stateless. That means that a new instance of a page is created every time when we make a request to the server to get the page and after the round trip our page has been lost immediately. Features of View State. These are the main features of view state: Retains the value of the Control after post- back without using a session. Stores the value of Pages and Control Properties defined in the page. Creates a custom View State Provider that lets you store View State Information in a SQL Server Database or in another data store.
Advantages of View State. Easy to Implement. No server resources are required: The View State is contained in a structure within the page load.
Enhanced security features: It can be encoded and compressed or Unicode implementation. For further information click on the link: Question 4: What are the different Session state management options available in ASP. NET? Answer: State Management in ASP. NETA new instance of the Web page class is created each time the page is posted to the server. In traditional Web programming, all information that is associated with the page, along with the controls on the page, would be lost with each roundtrip. The Microsoft ASP. NET framework includes several options to help you preserve data on both a per- page basis and an application- wide basis.
These options can be broadly divided into the following two categories: Client- Side State Management Options. Server- Side State Management Options.
Client- Side State Management. Client- based options involve storing information either in the page or on the client computer. Some client- based state management options are: Hidden fields. View state. Cookies.
Query strings. Server- Side State Management. There are situations where you need to store the state information on the server side.
Server- side state management enables you to manage application- related and session- related information on the server. ASP. NET provides the following options to manage state at the server side: Application state. Session state. For further information click on the link: Question 5: What is caching in ASP. NET? Answer: Caching is one of the most interesting concept and operation in ASP. NET. If you can handle it, you can run any web application by applying the caching concept depending on the requirements. Caching is for providing solutions or the results to the users depending on their request, admin needs to recreate the pages often depending on user requests…STOP!!! A cache simply stores the output generated by a page in the memory and this saved output (cache) will serve us (users) in the future.".
Types. For further information click on the link: Question 6: How can we apply themes in ASP. NET application? Answer: A theme is a collection of settings that define the look of controls and web pages. These themes are applied across all the pages in a web application to maintain a consistent appearance.
Uploading Multiple Records Via Excel Upload in Database Using Entity. Framework 6. 0 in ASP. Net MVC4. This article explains how to insert multiple records into a database using an Excel upload. When working on a project there was a requirement for me to upload an Excel file, let's say with the number of records up to 5. But while uploading the Excel file there were certain validations that needs to be done and if any of the records fail then the error message needs to be displayed for that respective row of the Excel on the page and none of the records needs to be saved inside the database table. Validations could be in any sense, for example: The age of all employees needs to be > = 1.
The age column should not have a non- numeric value. There were certain columns that were mandatory, if the value is not filled in that column of the Excel then the user should be notified of the error. Like name of the Employee should not be null. Checking thar a date value is in the format of DD/MM/YYYY.
When uploading this Excel file, if the preceding validations are successfully satisfied then the data needs to be saved in the database against a specific batch id that is basically a unique number to identify the records inserted within that specific batch and when they all were inserted. Also a special attention needs to be provided on the Excel column headings that we provided to the user for data entry purposes. Let's say there are 1.
Excel and if the user changes the order of the Excel column heading or if they delete some column or changes the name of the column, this validation also needs to be performed against the uploaded file. For performing this validation we have made use of an Excel. Structure Table that will have Excel fields/columns stored with their respective sizes, types, parameters and whether these fields/columns are mandatory or not.
The following is the structure of the Excel. Structure Table. Remember we are using Entity. Framework with the Code First Approach. But just for demo/looking purposes our SQL table will have the following query. CREATETABLE [dbo].[Excel.
Structure]( [Row_ID] INT IDENTITY (1, 1)NOTNULL, [File_ID] INT NOTNULL, [File_Name] NVARCHAR (MAX)NULL, [Field_Name] NVARCHAR (MAX)NULL, [Field_Data] NVARCHAR (MAX)NULL, [Active_Flag] INT NOTNULL, [Row_No] INT NOTNULL, [Field_Delimeter] NVARCHAR (MAX)NULL, CONSTRAINT [PK_dbo. Excel. Structure] PRIMARYKEYCLUSTERED ([Row_ID] ASC)); Now let's move to the code. Here the technology that we are using is ASP. NET MVC4 and Entity. Framework 6. 0. I'm naming my solution name Import. From. Excel that will have two projects, one would be of type Class Library with the name Import.
From. Excel. Domain and the other would be our MVC4 project with the name Import. From. Excel. Web.
UI with basic as its type. Our Import. From.
Excel. Domain project will have the entire model and Db. Context classes we are following here the separation of concerns between model and Web. Application. Install the Entity. Framework Package inside the Import. From. Excel. Domain and Import.
From. Excel. Web. UI Project using the Package Manager Console by typing the command as: Install- package Entity. Framework. Note: Make sure you install it in both the projects otherwise a version issue might occur. We need to add the reference to System. Component. Model. Data. Annotations namespace.
We have added creation folders to our Domain class library project and these folders contain several classes and interface that we'll require to query our database or manipulate the database. Here is the hierarchy of the Import. From. Excel. Domain project application: Here are the definitions of the files. Employee. csusing System; using System. Collections. Generic; using System.
Component. Model. Data. Annotations; using System. Component. Model.
Data. Annotations. Schema; namespace Import. From. Excel. Domain. Entities{ [Table("Employee")] publicclass. Employee { [Key] publicint. Employee. ID { get; set; }//mvc convention by default it will make it as primary key with autogenerated feature turned on [Required(Error. Message = "Name is Required")] publicstring Name { get; set; } [Required(Error.
Message = "Address is Required")] publicstring Address { get; set; } publicstring DOB { get; set; } publicint Age { get; set; } publicstring Email { get; set; } }}Excel. Structure. csusing System; using System. Component. Model.
Data. Annotations; using System. Component. Model. Data. Annotations. Schema; namespace Import. From. Excel. Domain. Entities{ [Table("Excel. Structure")] publicclass.
Excel. Structure { [Key] [Database. Generated(Database. Generated. Option. Identity)] publicint Row_ID { get; set; } publicint File_ID { get; set; } publicstring File_Name { get; set; } publicstring Field_Name { get; set; } publicstring Field_Data { get; set; } publicint Active_Flag { get; set; } publicint Row_No { get; set; } publicstring Field_Delimeter { get; set; } } } In order to reduce the dependency between higher end modules and lower end modules we implemented an interface that will help us to do loose coupling between the various components. IEmployee. Repository. System; using System.
Collections. Generic; using System. Linq; using System. Text; using Import. From. Excel. Domain. Entities; namespace Import. From. Excel. Domain.
Abstract{ publicinterface. IEmployee. Repository { IQueryable< Employee> Employee { get; } IQueryable< Excel. Structure> Excel. Structure { get; } void Save. Employee(IList< Employee> lst. Employees); }}EFDBContext. This is our Db. Context classusing System; using System.
Collections. Generic; using System. Data. Entity; using System. Linq; using Import. From. Excel. Domain. Entities; namespace Import.
From. Excel. Domain. Concrete{ publicclass. EFDb. Context : Db. Context { public. Db. Set< Employee> Employee { get; set; } public. Db. Set< Excel.
Structure> Excel. Structure { get; set; } }}Employee. Repository. csusing System; using System. Collections. Generic; using System.
Linq; using Import. From. Excel. Domain. Abstract; namespace Import. From. Excel. Domain. Concrete{ publicclass. Employee. Repository : IEmployee. Repository { EFDb.
Context context = new. EFDb. Context(); public. IQueryable< Entities. Employee> Emp { get { return context. Employee; } } public. IQueryable< Entities. Excel. Structure> Excel.
Structure { get { return context. Excel. Structure; } } publicvoid Save. Employee(IList< Entities. Employee> lst. Employees) { try { context. Employee. Add. Range(lst.
Employees); context. Save. Changes(); } catch (Exception ex) { throw ex; } } }}Inside the Concrete folder we have a class named Excel. Structure. Initializer. Database Excel. Structure Table when we run the application for the first time or even when the model changes or the database is dropped and recreated by the entity. Framework. This class inherits from Drop.
Create. Database. If. Model. Changes class in order to maintain the synchronization between the Model and the Entity. Framework Database. The following is the definition of the class.
System; using System. Collections. Generic; using System. Linq; using System. Text; using System. Threading. Tasks; using Import. From. Excel. Domain. Entities; using System.
Data. Entity; namespace Import. From. Excel. Domain. Concrete{ publicclass. Excel. Structure. Initializer : Drop.
Create. Database. If. Model. Changes< EFDb. Context> { protectedoverridevoid Seed(EFDb. Context context) { //base.