Latest ASP.Net Interview Questions Part – 2
1) What is ASP.NET ?
ASP.NET is a Server-Side technology which uses object-oriented programming approach. Every element in ASP.NET is treated as an object and run on the server.
ASP.NET allows you to use a fully featured programming language like C-Sharp (C#) or VB.NET to build web applications easily.
2) What is Common Language Runtime or CLR ?
CLR handles the compilation and execution of .NET programs. CLR uses JIT and compiles the IL code to machine code and then executes.
Below are the list of responsibilities of Common Language Runtime –
Garbage Collection
Code Verification
Code Access Security
Intermediate language -to-native translators and optimizer’s
3) What are Assemblies and Namespaces and explain the difference between them ?
Namespaces are the containers for holding the classes. In Object Oriented world, it is possible that programmers will use the same class name. By using namespace along with class name this collision can be removed.
An assembly exists as a .DLL or .EXE that contains MSIL code that is executed by CLR.
An assembly contains interface and classes and it can also contain other resources like files, bitmaps etc.
4) Describe the Events in the Life Cycle of a Web Application ?
A web application starts, when a browser requests a page of the application for the first time. The request will be received by the IIS which then starts ASP.NET worker process. The worker process then allocates a process space to the assembly and loads it.
An Application_Start() event will fire on start of the application and it’s followed by Session_Start(). ASP.NET engine then processes the request and sends back response in the form of HTML to the user and user receives the response in the form of page.
5) Explain the application event handlers in ASP.NET ?
Below are the event handlers in sequence of their execution –
Application_Start – Fired when the first user visits a page of the application or first resource is requested from the server.
Application_End – Fired when there are no more users of the application.
Application_BeginRequest – Fired at the beginning of each request to the server.
Application_EndRequest – Fired at the end of each request to the server.
Session_Start – Fired when any new user visits.
Session_End – Fired when the users stop requesting pages and their session times out.
6) What are the Web Form Events available in ASP.NET ?
Following are the Web Form Events in the sequence of their execution –
Page_Init
Page_Load
Page_PreRender
Page_Unload
Page_Disposed
Page_Error
Page_AbortTransaction
Page_CommitTransaction
Page_DataBinding
7) What is Global Assembly Cache ?
GAC (Global Assembly Cache) is used to share .NET assemblies.
GAC will be used in the below scenarios –
If the multiple application wanted to use the same assembly.
If the assembly has security requirements. For example, if only administrators have the permission to remove the assembly.
8) Explain the Server Control Events of ASP.NET ?
ASP.NET offers many server controls like Textbox, Button Dropdown List etc. Each control will respond to the user’s actions using events and event handler mechanism.
Following are the Server Control Events:
Postback events – These events sends the web page to the server for processing. Once processing is finished, web page will send data back to the same page on the server.
Cached events – These events are processed when a postback event occurs.
9) What are Strong Names ?
Strong names are unique names for assemblies. Strong name is similar as GUID in COM components. When we want to deploy the assembly in GAC, then we need to give the strong name for the assemblies. Strong name helps GAC to differentiate between two versions.
10) Explain the steps to generate the strong name ?
Go to Visual Studio Command Prompt
Type – “sn.exe –k “D:\TestingStrongName.snk” in command prompt.
Once SNK file is generated, sign the project with this SNK file. Go to project properties and browse the SNK file generated and build the project.
11) What are the State Management options in ASP.NET ?
Client-side state management – This maintains information on the client’s machine using either of the following options –
Cookies – Cookie is a small sized text file on the client machine either in the client’s file system or memory of client browser session.
View State – Each page and control on the page has View State property. This allows automatic retention of page and control’s state between each trip to server.
Query string – Query strings can maintain limited state information. Data has been passed from one page to another with the URL, but you can send limited size of data with the URL.
Server-side state management – This mechanism retains state in the server. Below are the options to achieve it –
Application State – The data stored in the application object can be shared by all the sessions of the application.
Session State – Session State stores session-specific information and the information is visible within the session only.
12) Explain the garbage collection in .NET ?
Garbage collection is a CLR feature which automatically manages memory. CLR automatically releases objects when they are no longer used and referenced.
Following methods are used for garbage collection –
GC.Collect()
Dispose()
Finalize()
13) What is Reflection in .NET?
Reflection is a mechanism through which types defined in the metadata of each module can be accessed. The System. Reflection namespace will have the classes required for reflection.
14) Define Resource Files?
Resource files contains non-executable data like strings, images etc. that can be used by an application and deployed along with it. You can change these data without recompiling the whole application.
15) What are different types of caching using cache object of ASP.NET?
We can use two types of output caching to cache information that is to be transmitted to and displayed in a Web browser –
Page Output Caching
Page Fragment Caching
16) How can you cache different version of same page using cache in ASP.NET?
Output cache functionality is achieved by using “OutputCache” attribute on ASP.NET page header.
It uses following parameters –
VaryByParam – Caches different version depending on input parameters send through HTTP POST/GET.
VaryByHeader – Caches different version depending on the contents of the page header.
17) Explain the concept of Globalization and Localization?
Globalization is used to create a multilingual application by defining culture specific features like text, date etc. Localization is used to accommodate the cultural differences in an application.
18) What is Satellite Assemblies?
Satellite Assemblies are the special kinds of assemblies that exist as DLL and contain culture specific resources in a binary format.
They stores compiled localized application resources. This can be created using the AL utility and can be deployed even after deployment of the application.
Satellite Assemblies encapsulates the resources into binary format and thus makes resources lighter and consume lesser space on the disk.
19) What are the settings that can be done in Web.config file in .NET?
Below are the settings we can have in web.config –
Connection String of the database.
Error Page setting.
Culture specific setting.
Session States.
WCF Binding and endpoint details.
Error Handling
20) What is Post Back?
There will be a roundtrip of the page between client and a server in request-response model, so this mechanism is called Post Back.
21) How do we identify that the Page is PostBack ?
In server side code we have a property called “IsPostBack” which is used to identify whether page is posted back or not. We can set the “AutoPostBack” at the control level where page is posted back when the state of control is changed.
22) How the ASP.NET events are processed?
ASP.Net events are processed in the following sequence –
Page_Init
Page_Load
Control events
Page_Unload
23) What is AppSetting Section in “Web.Config” file?
Web.config file defines configuration for a web project. Using “AppSetting” section we can define user defined values. Rather than hard coding the values in an application, developers prefer to keep the key,value pair in appsettings. Below is the sample for adding key value pair–
<appSettings>
<add key = “yourkey” value=”yourvalue”/>
</appSettings>
24) Explain form authentication using login control?
Login controls encapsulate all the features offered by Forms authentication. Login controls internally use Forms Authentication class to implement security, by prompting for user credentials validating them.
25) Explain Web and Machine configs?
“Web.config” files apply settings to each web application, while “Machine.config” file apply settings to all ASP.NET applications. Basically “Machine.Config” at the machine level and “Web.Config” is at the application level.
26) Explain Session state management options in ASP.NET?
ASP.NET provides In-Process and Out-of-Process state management. In-Process will store the session in memory on the web server. Out-of-Process will store data in an external data source such as SQL Server or a State Server service. Out-of-Process requires that all objects stored in session are serializable.
27) How to turn off cookies for a page?
Cookie.Discard Property when set true will instruct the client application not to save the Cookie on the user’s hard disk when a session ends.
28) What is the difference between Server.Transfer and Response.Redirect ?
Response.Redirect sends message to the browser saying it to move to some different page, but Server.Transfer does not send any message to the browser but rather redirects the user directly from the server itself. So in ServerTransfer there is no round trip while Response.Redirect has a round trip and will puts more load on server.
29) What is the difference between Authentication and Authorization?
Authentication is the process in which we are checking the identity of the user to allow the user into the application. So Login is the process of authentication for the application. Now social media authentication is also allowed in many websites to identify the user.
Authorization sounds same as authentication but it is different. Authorization handles the permission stuff for the user at web page level.
Better example will be if the user is authenticated in the website does not mean that user has full permission on all the pages so that can be controlled by authorization.
30) What are the various ways of authentication techniques in ASP.NET?
There are basically three types of authentication modes in ASP.NET –
Windows Authentication – windows authentication uses our system credentials for the authentication purpose.
Forms Authentication – This is a form based authentication. Login Control in ASP.NET supports this kind of authentication.
Passport Authentication – Passport authentication lets you to use Microsoft’s passport service to authenticate users of your application.
31) Explain how to retrieve property settings from .config file ?
By creating an instance of AppSettingsReader class, GetValue method is used by passing the name of the property and the type expected and assign the result to the appropriate variable.
32) What is side-by-side execution?
This means multiple version of same assembly can run on the same computer. This feature will enable to deploy multiple versions of the component.
33) What is application domain?
It is the process space within which the application will be running. Every application has its own process space which isolates it from other application. If one of the application domain throws error, it does not affect the other application domains.
34) What is impersonation in ASP.NET?
ASP.NET executes in the security context of a restricted user account on the local machine. Sometimes, we need to access network resources such as a file on a shared drive, which will require additional permissions. One way to restrict this, is to use impersonation.
ASP.NET with impersonation can execute the request using the identity of the client or ASP.NET can impersonate a specific account by the values in web.config.
35) How many types of validation controls are provided by ASP.NET ?
There are FIVE types of validators in ASP.NET and they are –
RequiredFieldValidator – It checks whether the control have any value or not. It is used, when you want the control not to be empty.
RangeValidator – It checks, if the value in validated control is in that specific range. Eg: Range of Date Birth.
CompareValidator – It checks that the value in controls should match the value in other control. Eg : Password and Retype Passwords.
RegularExpressionValidator – When we want the control value that matches a specific regular expression. Eg : Checking for valid Email ID.
CustomValidator – It is used to define User Defined validation.
36) What does AspCompat=”true” mean and when should you use it?
The AspCompat attribute forces the page to execute in STA mode. ASP.NET runtime throws an exception, if the compatibility tag is omitted and an STA component is referenced in the page. If you convert the STA component to an assembly using Tlbimp.exe, runtime does not detect that the component uses the STA model and does not throw an exception, but the application can suffer from poor performance.
<%@Page AspCompat=true Language = C# %>
37) What are HttpHandlers?
ASP.NET programming supports the creation of custom HttpHandler components, which provide an efficient way to process requests that don’t return standard HTML-based pages.
E.g. : HttpHandler components are good for situations in which you want to return XML, simple text or binary data to the user.
The easiest way to create a custom HttpHandler component is to create a source file with an .ashx extension. You must then add a @WebHandler directive to the top of the .ashx file with a class definition that implements the IHttpHandler interface.
38) Explain the differences between Server-side and Clientside code?
Server side code is executed at the server side on IIS in ASP.NET framework, these code will be written either in C#, VB.NET or VC++.
Client side code is executed on the browser. JavaScript is the typical example for this.
39) What is Custom Control in ASP.NET?
Custom controls are compiled code, which makes them easier to use but difficult to create one. Once you have created the control, we can add it to the Toolbox and display it in a visual designer. We can deploy custom control in GAC and can be shared between the applications. This is either extended from Control/WebControl class.
40) What is User Control in ASP.NET?
User controls are easy to build, but they are less convenient to use in complicated scenarios. User controls are developed in the same way as we develop Web Forms pages in the visual designer. User controls can handle execution events.
41) What’s a bubbled event?
When you have a complex control, like GridView, writing an event processing routine for each object like cell, button, row, etc. is tedious. The controls can bubble up their event handlers, allowing the main GridView event handler to take care of its constituents.
42) What is ASP.NET Compilation Tool?
The ASP.NET Compilation tool enables you to compile an ASP.NET application either In-place or for deployment to a target location. In-place compilation always helps application performance, because end users do not encounter a delay on the first request to the application while the application is compiled.
Compilation for deployment can be done in one of two ways: one that removes all source files, such as code behind files and markup files, or one that always retains the markup files.
43) What is the basic difference between ASP and ASP.NET?
The basic difference between ASP and ASP.NET is that, ASP.NET is compiled whereas ASP is interpreted whereas. This implies that since ASP mainly uses VBScript, when an ASP page is executed, it is interpreted. On the other hand, ASP.NET uses .NET languages, such as C# and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL).
44) In which event, controls will be fully loaded?
Page load event guarantees that all controls are fully loaded. Controls are accessed in Page_Init event, but you will see that view state is not fully loaded during this event.
45) What is the difference between a default skin and a named skin?
The default skin is applied to all the Web server controls in a Web form and it does not provide a Skin ID attribute. The named skin provides an attribute Skin ID and users have to set the Skin ID property to apply it.
46) What is IIS? Why is it used?
Internet Information Services (IIS) is created by Microsoft to provide Internet-based services to ASP.NET Web applications. It makes your system to work as a Web server and provides the functionality to develop and deploy Web applications on the server. IIS handles the request-response cycle on the Web server. It offers the service of SMTP and front-page server extensions. As you know SMTP is used to send emails and use FrontPage server extensions to get the dynamic features of IIS, such as form handlers.
47) What you mean by Query String? What are its advantages and limitations?
The Query String helps to send the page information to the server.
Advantages of Query String are –
All browsers works with Query Strings.
Query String would not not require any server resources so it does not exert any sort of burden on the server.
Limitations of Query String are –
Browser URL does not support many characters and it has limit.
Information will be visible to the user, which leads to security issues.
48) In ASP.NET how many types of cookies are there?
There are two types of cookies –
Session cookie – A session cookie goes away when the user shuts the browser down.
Persistent cookie – This resides on the hard drive of the user and is retrieved when the user comes back to the Web page.
49) What is smart navigation?
Using the Page.SmartNavigation property, we can enable smart navigation. When we set the property – Page.SmartNavigation to true, the following features are enabled for smart navigation. Scroll position of a Web page will be maintained after postback.
Element which focus on a Web page is maintained during navigation.
Most recent Web page state is only retained in the Web browser history folder.
Flicker effect which could occur on a Web page during navigation will be minimized.
50) Which method has been used in ASP.NET 4.0 to redirect a page permanently?
The RedirectPermanent() method used in ASP.NET 4.0 is used to redirect a page permanently.
The below code snippet is an example of the RedirectPermanent() method:
RedirectPermanent(“/path/Test.aspx”);
51) How can you send an email message in ASP.NET?
We can use classes – MailMessage and SmtpMail, which are under namespace System.Net.Mail to send the email from our Web pages. To send an email through our mail server, we need to create an object of the SmtpClient class and set the credentials, name of server and port.
52) Explain methods Response.Write() and Response.Output.Write()?
Response.Write() – allows you to write the normal output.
Response.Output.Write()- allows you to write the formatted output.
53) What is master page in ASP.NET?
Master Page acts like a normal page. Master Pages can contain controls, code or markup as in web form. Master page will have a control called “ContentPlaceHolder”, which defines region of master page which renders HTML content of child pages which uses master page. Master pages will have extension “.master” and there will be a master directive at the top of the page as shown below –
<%@ Master Language=”C#” AutoEventWireup=”true” CodeFile=”TestOurSite.master.cs” Inherits=” TestOurSite ” %>
54) How does the content page differ from a master page?
A content page would not be having the complete HTML source code; whereas a master page has complete HTML source code inside its source file.
55) Why do you use the App_Code folder in ASP.NET?
App_Code folder is part of ASP.NET folders. It stores any type of objects like text files, classes or reports. Advantage of App_Code folder is that if multiple classes or objects been added into this folder it creates a single dll for all.
56) What is tracing? Where is it used?
Tracing displays the details about the code execution. It is meant for getting the details of application when it is in running mode, which is really useful for troubleshooting the application. It gives an option to log the details to a file. So from the file it’s easy to figure out the root cause for an issue. .NET supports Trace Listeners, which gets the trace output and it is used to store the information in different places.
57) What is the timeout of Cookie?
The default time for a Cookie to expire is 30 minutes.
58) What are modes of Session state in ASP.NET?
In-Process – It stores the session in local system.
State Server – It stores the session in a process called “ASP.NET state service”.
SQLServer – It stores the session in SQL Server database.
Custom – It allows the custom storage provider.
59) Which namespace is used to implement debug and trace methods?
Namespace used for both these methods – “System.Diagnostic”.
60) What are the difference between Web server and Web Service?
Web Server is the one which gives the response to all the requests of the clients. Client can use either HTTP, SOAP protocols for request. Web Server is a computer and it turns to be a server once server software is installed. Every Web Server will have its domain possibly.
Web Services are one of the components of Web Server which is callable from client side. Client will call the Web Service by making HTTP or SOAP requests. ASP.NET allows to create a custom Web Services which is in turn called from client side.
61) How would you enable automatic paging in DataGrid ?
Below are the list of points which are to be followed in order to enable paging in Datagrid –
Set the “AllowPaging” to true.
Set the current page index to clicked in PageIndexChanged event.
62) What is difference between Data list, Grid view and Repeater?
All these controls have many things in common like Data Source Property, Data Bind Method ItemDataBound and ItemCreated.
When Data Source Property of a Grid view is assigned to a Dataset then each Data Row present in the Data Row Collection of Data
Table is assigned to a corresponding DataGridItem and this is same for the rest of the two controls also. But The HTML code generated for a Grid view has an HTML TABLE element created for the particular Data Row and it’s a Table form representation with Columns and Rows.
For a Data list it’s an Array of Rows and based on the Template Selected and the RepeatColumn Property value we can specify how many Data Source records should appear per HTML row.
In short in Grid view we have one record per row, where as in data list we can have five or six rows per row. In Repeater Control the data records which are to be displayed depends upon the Templates specified and the only HTML generated is the due to the Templates.
63) What are the difference between adding the items into cache through the Add () method and through the Insert () method?
Cache.Add() will return an object that represents the item added in the cache.
Cache.Insert() is going to replace the existing item in the cache which will not happen in Cache.Add().
64) What is the use of “EnableViewState” property?
This property is used to enable the ViewState property on the page. It is set to ON, to allow it to save the input values of the user between postback requests. When is set to OFF, it won’t allow to save the user input in postbacks.
65) List all different typesS of directives in .NET?
The different types of directive in .Net –
@Import
@Page
@Control
@Register
@Reference
@Assembly
@OutputCache
@Implements
66) How to decide on the design consideration to take a GridView, Datalist or Repeater?
GridView provides ability to allow the end-user to edit the page data or sort the page records. But it comes at a cost of speed. Secondly, the display format is very simple i.e. is in row and columns.
With its templates, DataList provides more control over the look and feel of the displayed data than the GridView. And it offers better performance than GridView.
With Repeater, the only HTML emitted are the values of the databinding statements in the templates along with the HTML markup specified in the templates—no “extra” HTML is emitted, as with the Grdiview and DataList.
67) Which Javascript file is responsible for validation at the client side?
WebUIValidation.js javascript file is mainly used for validation by the validators at client side. This file will be installed at “aspnet_client” at IIS directory.
68) What is .Net Remoting?
.Net Remoting is considered as the replacement for DCOM. Using .Net remoting remote object calls can be done which lies in different Application domains. As the remote objects runs under different process, client which calls remote object cannot call directly.
69) What is Application Domain?
Application Domain is logical boundary created for .NET applications so that one application does not affect the other applications. .NET runtime uses Appdomain as a container for data and code.
70) In ASP.NET how many navigation controls are there?
Navigation controls will be used to navigate in a Web application. These controls will store the links either in hierarchical structure or drop-down structure.
Navigation controls available in ASP.NET are –
Tree View
Menu
Sitemap Path
71) What is Delay signing?
During development process, you will need strong name keys to be exposed to developer which is not a good practice from security point of view. In these situations you can assign the key later on and during development, you can use delay signing.
72) What are server-side comments?
Server side comments are used in ASP.NET page.
This is used to describe the purpose of code snippet.
<%–This is how server-side comments can be done — %>
Server side comments always begins with
“<%–“ and ends with “– %>”.
73) What are the common properties of all validation controls?
ControlToValidate – control name to be validated.
ErrorMessage – error message to be displayed on validation fail.
IsValid – Boolean value for checking control’s validation has succeeded or not.
Text – displaying the text before validation for validation control.
74) What is cross-page posting?
Server.Transfer() method is used for posting the data from one page to another.
In cross page posting, data collected from different pages and will be displayed in single page. So, for doing this we need to set “PostBackUrl” property of the control, in which target page is specified and in target page we can use “PreviousPage” property. For doing this we need to set the directive – @PreviousPageType. Previous page control can be accessed from the method – “FindControl()”.
75) How to differentiate a sub master page from a top-level master page?
As content page, sub master page will not be having complete HTML source code. But at top level master page unlike sub master page it will have complete HTML source code in source file.
76) What’s the difference between Linkbutton control and Hyperlink control?
Link buttons will have events which can be handled in code behind file.
Hyperlink control will not be having events like click and command events.