Thursday 9 February 2017

ASP.NET interview questions Part-2

1. Ques: What are the step for Performance Optimization in ASP.NET Web Sites ?
Answer:
1. Before deployment of application Set debug=false in web.config.
2. Turn off Tracing.
3. Removed unnecessary HttpModules.
4. Set EnableSessionState="false" on page level.
5. Try to use Disable View State of a Page. ex <%@ Page EnableViewState="false" %>
6. Deploy application with Release Build mode.
7. Optimize Images and CSS Sprites.
8. Avoid Response.Redirect. this will take extra round trip Bowers to server.
9. Use Finally Method in try carch black. it destroy all object like closing db connection ,open file etc.
10. Always try to use Client-side Scripts for validations.
11. Try to use try catch black for exceptions handling.
12. Use Page.ISPostBack property for for first time only neccessaery code executed.
13. Always use Paging in Gied system when larg no of data showing.
14. Try to Use Ajax calls instead of ASP.NET code behind code.
15. Use Caching Mechanism.
12. Avoid web server controls and use html control.
13  Validate user input before page submit.
13. Use Bundling and minification technique in application.
15. Use Async Threading call.
16. Make JavaScript and CSS External call.
17. Compression/Zip.
18. Use connection pooling.
19. Avoid using unmanaged code.
20. Put StyleSheets into the Header
21. Put Scripts to the end of Document.


2. Ques: What is difference between ASP.NET HttpHandler and HttpModule ? In which case we can use these two. 
Answer:
Http Handler:
  • An http handler returns a response to a request that is identified by a file name extension. i.e; .aspx (page handler).
  • Httphandlers is an file extension based processor.
  • HTTP Handler actually processes the request and produces the response.
  • It implemented by IHttpHandler Interface.
  • In the asp.net request pipe line ,http handler comes after http Module.
  • During the processing of an http request, only one HTTP handler will be called.

Http Modules:
  • Http modules are part of the ASP.NET request pipeline and have access to life-cycle events throughout the request.
  • Http module is an event based processor.
  • It uses IHttpModule Interface.
  • In the asp.net request pipe line, http Module comes first.
  • During the processing more than one HTTP modules may be called.
  • HTTP module can work on request before and on the response after HTTP Handler.
  • it is used for security, logging and custom headers/footers etc.

Http Handler are used for:
RSS feeds: To create an RSS feed. we can create a handler that emits RSS-formatted XML.
Image server: If Web application to serve images in a variety of sizes, we can write a custom handler to resize images and then send them to the user as the handler’s response.

Http modules are used for:
Security: For authenticating a request before the request is handled.
Statistics and Logging: Since modules are called for every request they can be used for gathering statistics and for logging information.
Custom header:  Since response can be modified, one can add custom header information to the response.


3. Ques: What is Caching ? What are the different types of caching?
Answer:
Caching is a technique to increase performance by frequently accessed data in server memory.
caching is used to retain the pages or data across HTTP requests and reuse them without the expense of recreating them.

There are 3 kinds of caching in asp.net.
Output Caching(Page Caching)
Fragment Caching
Data Caching

Output Caching (Page Caching):
Caches the dynamic output generated by a request.it avoid round trip of request which use for  better performance website.
 The OutputCache directive use for caching the whole page. ex
<%@ OutputCache Duration = 10 VaryByParam = "None" %>

Fragment Caching:
Caches the portion of the page like user control etc.
Fragment caching refers to the caching of individual user controls within a Web Form.
Navigation bars, header, and footers are good candidates for fragment caching.
<%@ OutputCache Duration="10" VaryByParam="ID" VaryByControl="TextBox"%>

Data Caching:
Data Cache is used to access frequently used data in the Cache memory.
It's much easy to retrieve data from cache memory instead of database or other sources.
eg: cache["States"] = dsStates;
Dataset dsStates= (Dataset) Cache ["States"]


4. Ques:  What is the difference between URI, URL and URN?
Answer:
URI (Uniform Resource Identifier)
URIs are a standard for identifying documents using a short string of numbers, letters, and symbols

URL  (Uniform Resource Locator)
Contains information about how to fetch a resource from its location.
ex: http://google.com/mypage.html
URLs always start with a protocol (http) and usually contain network host name (example.com) and often a document path (/mypage.html).
URLs may have query parameters and fragment identifiers.

URN (Uniform Resource Name)
Identifies a resource by a unique and persistent name. It usually starts with the prefix urn:
ex :urn:publishing:book


5. Ques:  How do you sign out from forms authentication?
Answer: The FormsAuthentication.Signout() method is used to sign out from the forms authentication.


6. Ques:  What are benefits and Limitation of using Hidden fields?
Answer: 
Benefits of Hidden field
  • They are simple to implement.
  • As data is cached on client side they work with Web Farms.
  • All browsers support hidden field.
  • No server resources are required.
Limitations of Hidden field
  • They can be tampered creating a security hole.
  • Page performance decreases if you store large data, as the data is stored in pages itself.
  • Hidden fields do not support rich structures as HTML hidden fields are only single valued. Hence delimiters can be used to handle complex structures.

7. Ques: What is difference between Client-side validation and Server-side validation ?
Answer: 
Client-side validation

  • In client-side validation method, all the input validations and error recovery process is carried out on the client side i.e on the user’s browser. It can be done using JavaScript, AJAX, HTML5 etc.
  • Client-side validation is faster than server-side because, the validation takes place on client side (on browser) and the networking time from client to server is saved.

Server-side validation

  • In server-side validation, all the input validations and error recovery process is carried out on the server side. It can be done using programming languages like C#.NET, VB.NET Shop etc.
  • On the other hand, server-side validation is done on the web server. Then the server renders the data into html page and sends back to the client (browser).
  • Server-side validation is more secure than the client-side as the user cannot see the code even he does a view-source.

No comments:

Post a Comment

Thank you for comment