ASP.NET interview question pdf: We have compiled most frequently asked .NET Interview Questions which will help you with different expertise levels.
C#.NET Interview Questions and Answers for Freshers Pdf Free Download
Question 1.
What is ASP.Net?
Answer:
It is a framework developed by Microsoft on which we can develop new generation websites using web forms(aspx), MVC, HTML, Javascript, CSS, etc. Its successor of Microsoft Active Server Pages(ASP). Currently, there is ASP.NET 4.0, which is used to develop websites. There are various page extensions provided by Microsoft that are being used for website development. Eg: aspx, asmx, ascx, ashx, cs, vb, HTML, XML etc.
Question 2.
What are the advantages of ASP.NET?
Answer:
ASP.Net is the next generation of ASP technology platform. It is superior to ASP in the following ways:
- Highly Scalable
- Compiled Code
- User Authentication
- Language Support
- Third-party control
- Configuration and Deployment are easy,
- Object and Page caching
- Strict coding requirements
Question 3.
What’s the use of Response.Output.Write( )?
Answer:
We can write formatted output using Response.Output.Write( ).
Question 4.
In which event of page cycle is the ViewState available?
Answer:
After the lnit( ) and before the Page_Load().
Question 5.
What is the difference between Server. Transfer and Response. Redirect?
Answer:
In Server. Transfer page processing transfers from one page to the other page without making a round-trip back to the client’s browser. This provides a faster response with a little less overhead on the server. The client url history list or current url Server does not update in the case of the Server. Transfer.
Response. Redirect is used to redirect the user’s browser to another page or site. It performs a trip back to the client where the client’s browser is redirected to the new page. The user’s browser history list is updated to reflect the new address.
Question 6.
From which base class all Web Forms are inherited?
Answer:
Page class.
Question 7.
What are the different validators in ASP.NET?
Answer:
- Required Field Validator
- Range Validator
- Compare Validator
- Custom Validator
- Regular expression Validator
- Summary Validator
Question 8.
Which validator control do you use if you need to make sure the values in two different controls matched?
Answer:
Compare Validator control.
Question 9.
What is the concept of Postback in ASP.NET?
Answer:
Postback is a request which is sent from a client to the server from the same page user is working with. There is an HTTP POST request mechanism in ASP.NET. It posts a complete page back to the server to refresh the whole page.
Question 10.
What is the use of “isPostBack” property?
Answer:
The “IsPostBack” property of the page object is used to check that the page is posted back or not.
Question 11.
How do you identify that the Page is PostBack?
Answer:
There is a property named “IsPostBack” property in Post object, which can be checked to know that the page is posted back.
Question 12.
What is ViewState?
Answer:
ViewState is used to retain the state of server-side objects between page post-backs.
Question 13.
Where the ViewState is stored after the page postback?
Answer:
ViewState is stored in a hidden field on the page on the client-side. ViewState is transported to the client and back to the server and is not stored on the server or any other external source.
Question 14.
How long the items in ViewState exists?
Answer:
They exist for the life of the current page.
Question 15.
What are the different Session state management options available in ASP.NET?
Answer:
- In-Process
- Out-of-Process.
In-Process stores the session in memory on the web server.
Out-of-Process Session state management stores data in an external server. The external server may be either a SQL Server or a State Server. All objects stored in session are required to be serializable for Out-of-Process state management.
Question 16.
How you can add an event handler?
Answer:
Using the Attributes property of server side control, e.g.
btnSubmit.Attributes.Add(“onMouseOver,,;,,JavascriptCode( );”)
Question 17.
What is caching?
Caching is a technique used to increase performance by keeping frequently accessed data or files in memory. The request for a cached file/data will be accessed from cache instead of actual location of that file.
Question 18.
what are the main requirements for caching?
Answer:
- By caching the response, your request is served by the response already stored in memory.
- You must be very careful while choosing the items to cache because Caching incurs overhead.
- A frequently used web form which data doesn’t frequently change is good for caching.
- A cached web form freezes form?s server-side content, and changes to that content do not appear until the cache is refreshed.
Question 19.
What are the different types of caching?ASP.NET has 3 kinds of caching :
Answer:
- Output Caching,
- Fragment Caching,
- Data Caching.
Question 20.
Which type if caching will be used if we want to cache the portion of a page instead of whole page?
Answer:
Fragment Caching: It caches the portion of the page generated by the request. For that, we can create user controls with the below code:
<%@ OutputCache Duration=”120″ VaryByParam=”CategorylD;SelectedlD”%>
Question 21.
List the events in page life cycle.
Answer:
- Page_Prelnit
- Page_lnit
- Page_lnitComplete
- Page_PreLoad
- Page_Load
- Page_LoadComplete
- Page_PreRender
- Render
Question 22.
Can we have a web application running without web.Config file?
Answer:
Yes
Question 23.
What is the difference between ASP.NET Webforms and ASP.NET MVC?
Answer:
ASP.NET Webforms uses the page controller approach for rendering layout. In this approach, every page has its controller.
On the other hand, ASP.NET MVC uses the Front Controller approach. In this approach, there is a common controller for all pages.
Question 24.
Is it possible to create a web application with both webforms and MVC?
Answer:
Yes. We have to include the below MVC assembly references in the web forms application to create a hybrid application.
System.Web.Mvc System.Web.Razor System. ComponentModel.DataAnnotations
Question 25.
Can we add code files of different languages in the App_Code folder?
Answer:
No. The code files must be in the same language to be kept in the App_code folder.
Question 26.
What is Protected Configuration?
Answer:
It is a feature used to secure connection string information.
Question 27.
Write code to send e-mail from an ASP.NET application?
Answer:
MailMessage mailMess = new MailMessage ( ); mailMess.From = "abc@gmail.com "; mailMess.To = "xyz@gmail.com"; mailMess.Subject = "Test email"; mailMess.Body = "Hi This is a test mail."; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send (mailMess);
MailMessage and SmtpMail are classes defined System.Web.Mail namespace.
Question 28.
How can we prevent browser from caching an ASPX page?
Answer:
We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:
Response.Cache.SetNoStore ( );
Response.Write (DateTime.Now.ToLongTimeString ());
Question 29.
What is the good practice to implement validations in aspx page?
Answer:
Client-side validation is the best way to validate data of a web page. It reduces the network traffic and saves server resources.
Question 30.
What is the use of Global.asax file?
Answer:
The Global.asax file is used to execute the application-level events and sets application- level variables.
Question 31.
What is event bubbling?
Answer:
When child control sends events to parent, it is termed as event bubbling. Server controls like Data Grid, Data List, and Repeater can have other child controls inside them.
Question 32.
What are the event handlers that we can have in Global.asax file?
Answer:
Application Events: Application_Start, Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed, Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache
Session Events: Session_Start,Session_End
Question 33.
Which protocol is used to call a Web service?
Answer:
HTTP Protocol
Question 34.
Can we have multiple web config files for an asp.net application?
Answer:
Yes.
Question 35.
What is the difference between web config and machine config?
Answer:
Web config file is specific to a web application where as machine config is specific to a machine or server. There can be multiple web config files into an application where as we can have only one machine config file on a server.
Question 36.
Explain role based security ?
Answer:
Role-based security is used in almost all organization, and the Role-based security assigns certain privileges to each role.
- Each user is assigned a particular role from the list.
- Privileges as per role restrict the user’s actions on the system and ensure that a user can do only what he is permitted to do on the system.
<AUTHORIZATION>< authorization > < allow roles="Domain_Name\Administrators" / > < !-- Allow Administrators in domain. — > < deny users-'*" /> < !-- Deny anyone else. -- > < /authorization >
Question 37.
What is Cross Page Posting?
Answer:
When we click submit button on a web page, the page post the data to the same page. The technique in which we post the data to different pages is called Cross Page posting. This can be achieved by setting POSTBACKURL property of the button that causes the postback. Findcontrol method of PreviousPage can be used to get the posted values on the page to which the page has been posted.
Question 38.
How can we apply Themes to an asp.net application?
Answer:
We can specify the theme in web.config file. Below is the code example to apply the theme:
<configuration> <system.web> <pages theme="Windows7" /> </system.web> </configuration>
Question 39.
What is RedirectPermanent in ASP.Net?
Answer:
RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.
Question 40.
What is MVC?
Answer:
MVC is a framework used to create web applications. The web application base builds on Model-View-Controller pattern which separates the application logic from Ul, and the input and events from the user will be controlled by the Controller.
Question 41.
Explain the working of passport authentication.
Answer:
First of all it checks passport authentication cookie. If the cookie is not available then the application redirects the user to Passport Sign on page. Passport service authenticates the user details on sign on page and if valid then stores the authenticated cookie on client machine and then redirect the user to requested page
Question 42.
What are the advantages of Passport authentication?
Answer:
All the websites can be accessed using single login credentials. So no need to remember login credentials for each web site.
Users can maintain his/ her information in a single location.
Question 43.
What are the asp.net Security Controls?
Answer:
- <asp:Login>: Provides a standard login capability that allows the users to enter their credentials
- <asp:Loginl\lame>: Allows you to display the name of the logged-in user
- <asp:LoginStatus>: Displays whether the user is authenticated or not
- <asp:LoginView>: Provides various login views depending on the selected template
- <asp:PasswordRecovery>: email the users their lost password
Question 44.
How do you register JavaScript for webcontrols ?
Answer:
We can register javascript for controls using <CONTROL -name>Attribtues.Add(scriptname,scripttext) method.
Question 45.
In which event are the controls fully loaded?
Answer:
Page load event.
Question 46.
what is boxing and unboxing?
Answer:
Boxing is assigning a value type to reference type variable. Unboxing is reverse of boxing ie. Assigning reference type variable to value type variable.
Question 47.
Differentiate strong typing and weak typing
Answer:
In strong typing, the data types of variable are checked at compile time. On the other hand, in case of weak typing the variable data types are checked at runtime. In case of strong typing, there is no chance of compilation error. Scripts use weak typing and hence issues arises at runtime.
Question 48.
How we can force all the validation controls to run?
Answer:
The Page.Validate( ) method is used to force all the validation controls to run and to perform validation.
Question 49.
List all templates of the Repeater control.
Answer:
- ItemTemplate
- AlternatingltemTemplate
- SeparatorTemplate
- HeaderTemplate
- FooterTemplate
Question 50.
List the major built-in objects in ASP.NET?
Answer:
- Application
- Request
- Response
- Server
- Session
- Context
Question 51.
What is the appSettings Section in the web.config file?
Answer:
The appSettings block in the web config file sets the user-defined values for the whole application.
For example, in the following code snippet, the specified Connectionstring section is used throughout the project for database connection:
<emxconfiguration> <appSettings> <add key-'ConnectionString" value="server=local; pwd=password; database=default" /> </appSettings></em>
Question 52.
Which data type does the RangeValidator control support?
Answer:
The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.
Question 53.
What is the difference between an HtmllnputCheckBox control and an HtmllnputRadioButton control?
Answer:
In HtmllnputCheckBoxcontrol, multiple item selection is possible whereas in HtmllnputRadioButton controls, we can select only single item from the group of items.
Question 54.
Which namespaces are necessary to create a localized application?
Answer:
System.Globalization
System.Resources
Question 55.
What is a cookie?
Answer:
A Cookie is a small piece of information which is stored at the client side. There are two types of cookie:
- Session/Temporary Cookie: valid for a single session
- Persistent Cookie: valid for multiple session
Question 56.
What is the default timeout for a cookie?
Answer:
30 minutes.
Question 57.
How would you turn off cookies on a page of a website?
Answer:
You have to follow the procedures given below:
- Use the “Cookie.Discard” property,
- It gets or sets the discard flag set by the server.
- When set to true, this property instructs the client application not to save the Cookie on the hard disk of the user at the end of the session.
Question 58.
What are the different types of cookies in ASP.NET?
Answer:
Session Cookie – Resides on the client machine for a single session until the user does not log out.
Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.
Question 59.
What is the file extension of web service?
Answer:
Web services have file extension .asmx..
Question 60.
What are the components of ADO.NET?
Answer:
The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.
Question 61.
What is the difference between ExecuteScalar and ExecuteNonQuery?
Answer:
ExecuteScalar returns output value where as ExecuteNonQuery ctoes not return any value but the number of rows affected by the query. ExecuteScalar used for fetching a single value and ExecuteNonQuery used to execute Insert and Update statements.
Question 62.
What is IIS?
Answer:
IIS stands for Internet Information Services. It is created by Microsoft to provide Internet-based services to ASP.NET Web applications.
Question 63.
What is the usage of IIS?
Answer:
Following are the main usage of IIS:
- IIS is used to make your computer to work as a Web server and provides the functionality to develop and deploy Web applications on the server,
- IIS handles the request and response cycle on the Web server,
- IIS also offers the services of SMTP and Frontpage server extensions.
- The SMTP is used to send emails and use Frontpage server extensions to get the dynamic features of IIS, such as form handler.
Question 64.
What is a multilingual website?
Answer:
If a website provides content in many languages, it is known as a multilingual website. It contains multiple copies of its content and other resources, such as date and time, in different languages.
Question 65.
What is the parent class of all web server control?
Answer:
System. Web. Ul.Control class
Question 66.
What is the difference between the GET method () and POST method ()?
Answer:
GetMethod
Data is affixed to the URL.
Data is not secured.
Data transmission is faster in this method.
It is a single call system.
Only a limited amount of data can be sent.
It is a default method for many browsers.
PostMethod
Data is not affixed to the URL Data is secured.
Data transmission is comparatively slow
It is a two call system
A large amount of data can be sent
It is not set as default. It should be explicitly specified
Question 67.
What is the difference between session object and application object?
Answer:
The session object is used to maintain the session of each user. A session id is generated if a user enters in the application and when the user leaves the application, the session id is automatically deleted.
On the other hand, the application object is used to store the information and access variables from any page in the application.
Debug class is used to debug builds. Trace class is used for both debug and release builds.
Question 68.
What is the difference between trace and debug?
Answer:
Debug class is used to debug builds. Trace class is used for both debug and release builds.
Question 69.
What is the difference between client-side and server-side validations in WebPages?
Answer:
The client-side validation happens at the client’s side with the help of JavaScript and VBScript. This validation has occurred before the Web page is sent to the server. The server-side validation happens at the server side.
Question 70.
What is the difference between file-based dependency and key-based dependency?
Answer:
File-based dependency: File-based dependency facilitates you to save the dependency on a file in a disk.
Key-based dependency: In key-based dependency, you depend on another cached item.
Question 71.
What is the difference between globalization and localization?
Answer:
Globalization: Globalization is a technique to identify the part of a Web application that is different for different languages and separate it out from the web application.
Localization: In localization, you try to configure a Web application so that it can be supported for a specific language or locale.
Question 72.
What is the difference between a page theme and a global theme?
Answer:
Page Theme: The page theme is applied to particular web pages of the project. It is stored inside a subfolder of the App_Themes folder.
Global Theme: The Global theme is applied to all the web applications on the web server. It is stored inside the Themes folder on a Web server.
Question 73.
What is the difference between early binding and late binding?
Answer:
Early Binding: In early binding, a non-virtual method is called which is decided at a compile time.
Late Binding: In late binding, a virtual method is called which is decided at runtime.
Question 74.
What is the difference between server-side scripting and client-side scripting?
Answer:
Server-side scripting: In server-side scripting, all the script are executed by the server and interpreted as needed.
Client-side scripting: In client-side scripting, the script will be executed immediately in the browser such as form field validation, email validation, etc. The client-side scripting is usually carried out in VBScript or JavaScript.
Question 75.
How to sign out from forms authentication?
Answer:
FormsAuthentication.Signout() method is used to sign out from forms authentication.
Question 76.
How to display validation messages in one control?
Answer:
By the help of ValidationSummary control, we can display all validation messages in one control.
Question 77.
What is the difference between authentication and authorization?
Answer:
Authentication is a process of identifying user whereas authorization is used to check the access rights of an identified user.
Question 78.
Which object encapsulates state or data of a user?
Answer:
Session object.
Question 79.
What are the differences between the Response.Write() and Response.Output.Write()?
Answer:
Response.Write( ) is used for normal output whereas Response.Output.Write() is used for formatted output.
Question 80.
Define the types of configuration files.
Answer:
There are two types of configuration files:
- Application Level config = Web.config.
- Machine Level config = Machine.config.
Question 81.
What is the difference between Web config and Machine config files?
Answer:
Web config file is specific to web application whereas Machine config file is specific to machine or server.
There can be multiple web config files in an application but only one machine config file.
Question 82.
What are the HTML server controls in ASP.NET?
Answer:
- HTML server controls are just like HTML elements that we use on HTML pages.
- HTML server controls are used to expose properties and events for use.
- To make these controls programmatically accessible, we specify that the HTML controls act as a server control by adding the runat=Mserver” attribute.