Showing posts with label ASPDOTNET. Show all posts
Showing posts with label ASPDOTNET. Show all posts

Monday, 20 March 2017

ASP.NET interview questions Part-8

1. Ques: What are the difference between Web services and .Net Remoting ?
Answer:
Web services
  • Web Services are meant to be interoperable, meaning that they can be used across platforms. 
  • Web service create a Web service class derived from the System.Web.Services.WebService class and add the methods (functionality) with the WebMethod attribute. These methods can be invoked by sending HTTP requests using SOAP.
  • Web service create a proxy class for your Web service using either wsdl.exe utility or the Add Web Reference option in VS.NET. The Web service proxy hides all the network and marshaling plumbing from the application code, so using the Web service looks just like using any other local object
  • ASP.NET Web Services may be accessed using HTTP only.
  • Web Service is Stateless
Dot Net Remoting
  • The primary distinction is that .NET Remoting is only useful for .NET to .NET scenarios. 
  • the remote object is implemented in a class derived from System.MarshalByRefObject and MarshalByRefObject class provides the core foundation for enabling remote access of objects across application domains.
  • Remote object is confined to the application domain where it is created. In .NET remoting, a client doesn't call the methods directly; instead a proxy object is used to invoke methods on the remote object. Every public method that we define in the remote object class is available to be called from clients.
  • Remoting objects may be accessed over any protocol like TCP, SMTP, and HTTP. 
  • Remoting has support for both stateless and with-state environment, which is achieved using Singleton and Singlecall activation 

2. Ques:  What is the purpose of HTTP, SOAP in web-service ?
Answer:
HTTP(Hyper Text Transfer Protocol) is the set of slandered for the web requests. SOAP ( Simple Object Access Protocol) is the message format which is used to send and receive data in the specific message format in case of services.
Web Service transmits and receive the data in form of Message and each message should have some format so that it will be understandable by the browser and getting the responses in the same format. SOAP defines the common format of the messages which is XML format and understandably by all the technologies(as XML is platform independent).


3. Ques: What is  absolute expiration and sliding-time expiration ? What is the difference between them ?
Answer:
ASP.NET provides the functionality to create cache. It also provides the option to set the expiration time after which the cache would no longer be available. This is called "Time Based Expiration".
This expiration is of 2 types: 1. Absolute Expiration 2. Sliding ExpirationIn

Absolute Expiration the cache will be expired after a particular time irrespective of the fact whether it has been used or not in that time span. Whereas, in Sliding Time Expiration, the cache will be expired after a particular time only if it has not been used during that time span.The syntax to declare them are as follow:string cacheData = "Let's cache this data";
//Absolute Expiration Cache.Insert("AbsoluteCacheKey", cacheData, null,DateTime.Now.AddMinutes(1), System.Web.Caching.Cache.NoSlidingExpiration);
//Sliding Expiration Cache.Insert("SlidingExpiration", cacheData, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1));

Ex: I have created the a string to be cache that can be any serialized data. In the absolute expiration you can see that it will expires after one minute whether its accessed or not. While in sliding expiration it will expire cache if cache is not accessed within specified time like one minute.

Absolute expiration
It will expire the entry after a set amount of time.

sliding-time expiration
It will expire the entry if it hasn't been accessed in a set amount of time.


4. Ques:  What are the important Namespaces in Asp.net ?
Answer:
Namespaces in Asp.net  given as
System.Web 
System.web namespace holds some basic ingredients which includes classes and built-in Objects like
  • Server
  • Application
  • Request
  • Response
And Classes used for managing
  • Cookies
  • Configuring page caching
  • Tracing Implementation
  • Retrieving Information of Web Server and client browser
System.Web.services 
The System.Web.services namespace is a initial point for creating the web services. It contains web service classes , which allow to create XML web services using Asp.Net . XML web services provides feature to exchange messages in loosely coupled environment. using protocol like SOAP , HTTP , XML .

Some classes are as
  • WebMethodAttribute
  • Webservice
  • WebServiceAttribute
  • WebServiceBindingAttribute
System.web.UI.WebControls 
he System.web.UI.WebControls namespace contains classes that provides to create web server controls on web pages. These controls run on the server so we can programmaticaly control elements
Some classes are as follows
  • Calendar
  • Check Box
  • Button
  • Base Data Bound Control
System.web.UI 
The System.web.UI namespace includes classes that allows to create server controls with data- binding functionality , which has ability to save view state of given control and pages (.aspx pages) .
Many of these types allows to support for controls System.web.UI .Html controls. It is a base class for all HTML ,Web, and User Controls. Every aspx pages comes under it. Control classes provides common set of functionslity

System.web.sessionstate
Session state management comes under The System.web.sessionstate namespace . That enable storage of data specific to a single client with in a web application on the server. Session state is ideal for sensitive data such as mailing address , credit card number , password , important numbers etc. Sesssion state can be used with clients that do not support cookies.

Some classes are as follows
  • HttpSessionState
  • HttpSessionStateContainer
  • SessionIDManager
  • SessionStateModule etc


5. Ques: What are different types of directives in .NET? Explain each of them .
Answer:
@Page
@Control
@Import
@Implements
@Register
@Assembly
@MasterType
@Output Cache
@PreviousPageType
@Reference
@Master

 @Page Directive
This directive use for page-specific attributes by the ASP.NET page parser and compiler. Can be included only in .aspx files and also define the page language used just like c#,VB etc.

<%@Page Language="C#" AutoEventWIreup="false" CodeFile="Default.aspx.cs" Inherits="_Default"%>

@Control
control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files.
This directive also define the view state of page. <%@ Control Language="VB" EnableViewState="false" %>

@Import
It is Explicitly imports a namespace into a page or user control. The Import directive cannot have more than one namespace attribute. To import multiple namespaces, use multiple @Import directives.Its helps in importing of files. <% @ Import Namespace="System.web" %>

@Register 
when we create a user control and you drag that user control onto your page then you will see the @Register directive. This directive registers your user control on the page so that the control can be accessed by the page.
<%@ Register TagPrefix="MayTag Namespace="MyName.MyNameSpace" Assembly="MyAssembly"%>

@Assembly 
The @Assembly Directive attaches assemblies to the page or an ASP.NET user control thereby all the assembly classes and interfaces are available to the class. 
 <%@ Assembly Name="MyAssembly" %>
 <%@ Assembly Src="MySource.vb" %>

@Previouspagetype
This directive specifies the page from which any cross-page posting originates.

@Implements
The @Implements Directive gets the ASP.NET pages to implement .Net framework interfaces. This directive only supports a single attribute interface.
<%@Implements Interface="System.Web.UI.IValidator"%>

@MasterType 
The @MasterType Directive connects a class name to the ASP.NET page for getting strongly typed references or members contained in the specified Master Page. This directive supports the two attributes Typename and virtualpath. Typename sets the name of the derived class from which to get the strongly typed or reference members and virtualpath sets the location of the page from which these are retrieved.
<%@MasterType VirtualPath="/MasterPage1.master"%>

@output cache
It controls the output caching policies of an ASP.NET page.
<%@ OutputCache Duration ="180" VaryByParam="None"%>

Thursday, 9 March 2017

ASP.NET interview questions Part-7

1. Ques: What is differentiate between web.config and machine.config files ?
Answer:
Machine.Config
  • Machine.config is configuration file for all the application in the IIS.
  • Machine.config is automatically installed when you install Visual Studio. Net.
  • This is also called machine level configuration file.
  • Only one machine.config file exists on a server.
  • This file is at the highest level in the configuration hierarchy.
  • machine.config would be to share values between many applications on the server such as SMTP server settings
Web.Config
  • Web.config is a configuration file for a particular application or folder.
  • Web.Config is automatically created when you create an ASP.Net web application project.
  • This is also called application level configuration file.
  • This file inherits setting from the machine.config 
  • Web.config files contain application specific items such as database connection strings.

2. Ques: What is Global.asax file in asp.net ? What are the main event and their work in  ASP.Net Application ?
Answer:
The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules. The Global.asax file resides in the root directory of an ASP.NET-based application.The Global.asax file is parsed and dynamically compiled by ASP.NET.The Global.asax file itself is configured so that any direct URL request for it is automatically rejected; external users cannot download or view the code written within it.

Main event in global.asax in given bellow.

Application_Start() 
Application_Start() event occurs when the application starts, which is the first time it receives a request from any user. It doesn’t occur on subsequent requests. This event is commonly used to create or cache some initial information that will be reused later.

Application_End()
Application_End() event occurs when the application is shutting down, generally because the web server has restarted. You can insert cleanup code here.

Application_BeginRequest()
Application_BeginRequest() event occurs with each request the application receives, just before the page code is executed.

Application_EndRequest()
Application_EndRequest() event occurs with each request the application receives, just after the page code is executed.

Session_Start()
Session_Start() event occurs whenever a new user request is received and a session is started.

Session_End()
Session_End() event occurs when a session times out or is pro grammatically ended. This event is only raised if you are using in-process session state storage (the InProc mode, not the StateServer or SQLServer modes ).

Application_Error()
Application_Error() event occurs in response to an un-handled error.


3. Ques: What is a Cookieless Session in ASP.Net?
Answer:
You can configure your application to store Session IDs not in a cookie, but in the URLs of pages in your site. By keeping the Session ID in the URL, ASP.NET stores the ID in the browser, in a manner of speaking, and can get it back when the user requests another page. Cookieless sessions can get around the problem of a browser that refuses cookies and allow you to work with Session state.

ASP.NET Session State by default uses a cookie to store session ID. Session ID is a unique string, used to recognize individual visitor between visits. But, if client's web browser doesn't support cookies or visitor has disabled cookies in web browser's settings, ASP.NET can't store session id on client's machine. In this case, new session will be created for every request. This behavior is useless because we can't remember information for certain visitor between two requests. We can say that, by default, sessions can't work if browser doesn't support cookies.

4. Ques:  What is Tracing in ASP.Net ?
Answer:
Tracing is a way to monitor the execution of your ASP.NET application.ASP.NET tracing enables you to follow a page's execution path, display diagnostic information at run time, and debug your application.
here are two ways to implement Tracing in ASP.Net :

Page Level Tracing
Application Level Tracing

Page level Tracing - Enabled on a page-by-page basis by adding "Trace=true" to the Page directive
Application Tracing - You can enable tracing for the entire application by adding tracing settings in web.config. In below example, pageOutput="false" and requestLimit="20"


5. Ques: What is the Difference between Client Side and Server Side Code?
Answer:
Client Side
  • The client-side environment used to run scripts in a browser. 
  • Code is written in a scripting language such as JavaScript and HTML.
  • The browser itself executes the code in response to a user action and no server round trip is involved.
  • Client browser executes code to dynamically modify the HTML. This is called Dynamic HTML.
  • Code is script and therefore it is interpreted.
Server Side
  • The server-side environment that runs a language in a web server. 
  • Code is written in VB, C# or other compiled languages.
  • Code is executed by the server during a roundtrip in response to a user request or action.
  • The server executes server side code and returns HTML code to the client browser for display.
  • Code is either compiled dynamically or precompiled into assemblies.

6. Ques:  What are the different types of IIS Isolation Levels in ASP.Net?
Answer:
IIS5 supports three isolation levels

Low (IIS Process)

  • ASP pages run in INetInfo.Exe, the main IIS process
  • ASP crashes, IIS crashes
Medium (Pooled)

  • ASP runs in a different process, which makes this setting more reliable
  • If ASP crashes IIS won't.
High (Isolated)

  • Each ASP application runs out-process in its own process space
  • If an ASP application crashes, neither IIS nor any other ASP application will be affected

Tuesday, 7 March 2017

ASP.NET interview questions Part-6

1. Ques: Explain the two different types of remote object creation mode in .NET?
Answer:
The two different ways by which object can be created using Remoting is:-
  • SAO (Server Activated Object): It lasts the lifetime of the server. They are activated as SingleCall/Singleton objects. It makes objects stateless. A SingleCall object gets created for each request by client and A Singleton object is created once on the server and is shared by all the clients.
  • CAO (Client Activated Objects): CAO creates stateful objects. The object creation request is based on the request by client side. Therefore, the lifetime is based on client and not server. Single instance of object is created for every call.

2. Ques:  Explain the role of inetinfo.exe aspnet_isapi.dll and aspnet_wp.exe ?
Answer:
Inetinfo.exe is the Microsoft IIS server running, handling ASP.NET requests among other
things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request to the actual worker process aspnet_wp.exe.


3. Ques:  What’s the difference between Response.Write() and Response.Output.Write()? 
Answer:

Response.Write()

  • Response.Write() does not allows you to write formatted output.
  • It writes the text stream.
  • It just output a string to web page.

Response.Output.Write()

  • Response.Output.Write() allows you to write formatted output.
  • It writes the HTTP Output Stream.
  • it formats the string and then write to web page.


4. Ques:  When during the page processing cycle is ViewState available?
Answer:
After the Init() and before the Page_Load(), or OnLoad() for a control.


5. Ques: In what order do the events of an aspx page execute ?
Answer:
These are the order of Page events
Page_PreInit
Page_Init
Page_LoadViewState
Page_LoadPostData
Page_Load
Page_RaisePostDataChanged
Page_RaisePostBackEvent
Page_PreRender
Page_SaveViewState
Page_Render
Page_Dispose
Page_Error (this is caused whenever there is an exception at the page level).


6. Ques:  What are the contents of assembly?
Answer:
A assembly can consist of four elements:
  • Assembly manifest:Contains the assembly metadata. An assembly manifest contains the information about the identity and version of the assembly. 
  • It also contains the information required to resolve references to types and resources.
  • Type metadata - Binary information that describes a program.
  • Microsoft intermediate language (MSIL) code.
  • A set of resources.

7. Ques: What is the difference between ‘Web.config’ and ‘Machine.config’?
Answer:
  • Web.config files are used to apply configuration settings to a particular web application.
  • machine.config file is used to apply configuration settings for all the websites on a web server.
  • Web.config files are located in the application's root directory or inside a folder situated in a lower hierarchy. 
  • The machine.config is located in the Windows directory Microsoft.Net\Framework\Version\CONFIG.
  • There can be multiple web.config files in an application nested at different hierarchies. 
  • However there can be only one machine.config file on a web server.

8. Ques:  What is a Query String in ASP.Net?  What are the Benefits and limitations of a Query String in ASP.Net?
Answer:
QueryString is way to transfer information from one page to another through the URL.
A Query String is helpful when we want to transfer a value from one page to another. When we need to pass content between the HTML pages or aspx Web Forms in the context of ASP.NET, a Query String is very easy to use and the Query String follows a separating character, usually a Question Mark (?)

Benefits 
  • Supported by all the browsers
  • No extra effort is needed to code.
  • Easy to use.
limitations 
  • All the attributes and values are visible to the end user. Therefore, they are not secure. 
  • There is a limit to URL length of 255 characters.

Monday, 20 February 2017

ASP.NET interview questions Part-5

1. Ques: What are the new features in ASP.NET 4.5 ?
Answer:
Following are the new feature in asp.net 4.5
  • Bundling and Minification Feature
  • Strongly Typed Data Controls
  • Model Binding - Isolating the Web Form from the Model
  • Value Providers
  • Support for OpenID in OAuth Logins
  • Improved paging in ASP.NET 4.5 GridView control
  • Improved asynchronous programming.
  • Support for web sockets.
  • Support for HTML5 form types.
  • Page Inspector.
  • ASP.NET Web API
  • NET for Metro style Apps
  • Portable Class Libraries
  • Core New Features and Improvements
  • Parallel Computing.
  • Networking.
  • Support for Arrays Larger than 2 GB on 64-bit Platforms.
  • Enhanced Background Server Garbage Collection.
  • Support for Timeouts in Regular Expression Evaluations.
  • Support for Unicode 6.0.0 in Culture-Sensitive Sorting and Casing Rules on Windows 8.
  • Simple Default Culture Definition for an Application Domain.
  • Internationalized Domain Names in Windows 8 Apps.

2. Ques: What is the difference between user control and custom control?
Answer:
User Control:-

  • A tightly coupled control w.r.t code and UI
  • Derives from UserControl
  • Has static layout
  • It Can't be added to the toolbox.
  • Defines a set of controls.
  • Not very flexible like a Custom Control
  • It is useful static layout
  • Defines UI as normal XAML.
  • It can not compled into DLL.
  • Hard to Create.
  • A Seprate Copy of control required in each application.

Custom Control:-

  • A loosely coupled control w.r.t code and UI
  • Derives from Control
  • Has dynamic layout
  • It can be added in toolbox.
  • Defines a single control.
  • More flexible.
  • It is useful Dyanamic layout.
  • Defines UI in a ResourceDictionary.
  • It can compled into DLL.
  • Easy to Create.
  • A single Copy of control required in each application.


3. Ques: What is difference between server control and html control in asp.net ?
Answer: 
Server Controls:-
Server Controls are Server side controls and it executed on Server.
These controls Trigger Server side events.
Server Controls provides maintained State(view state) across requests.
It Provides set of properties that can be manipulated from server side code.
Server control inherits from System.Web.UI.

HTML Controls:
Html controls are client side controls and it executed on Browser.
These controls Trigger client side events.
HTML Controls can be maintained State using Page-level scripts.
It has the basic set of HTML attributes attached to each element.


4. Ques: What is Ispostback in asp.net and how to use it ?
Answer: 
IsPostBack is a property of the Asp.Net page that tells whether or not the page is on initial load.
using of the IsPostback Property we can check that page is Postback or not if page postback property is true then page is being post back if property is false then page is not postback.

Is Postback is normally used on page _load event to detect the Is page is getting loaded for the first time or not
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // generate form;
    }
    else
    {
        //process submitted data;
    }
}

5. Ques: What's the difference between eval() and bind() in asp.net
Answer:
eval()
  • eval() is one way binding.
  • If you bind a value using Eval, it is like a read only. You can only view the data.
bind()
  • Bind() is two way binding.
  • If you bind a value using Bind and if you do some change on the value it will reflect on the database also

6. Ques:  What is difference between View State and Session State ?
Answer:
View State
  • View State is maintained the state in page level only.
  • View State of one page is not visible in another page.
  • It store information on client side.
  • View State persist the value of page in the client side(browser) when post back operation done.
  • View State used to persist the page specific data on the client side.
Session state
  • Session state is maintained the state in Session level.
  • Session state value is available in all page within a user session.
  • Session state information stored in server.
  • Session state persist the data of particular user in the server.This data available till user close the browser or session time complete.
  • Session state used to persist the user specific data on the server side

7. Ques:  What is Cross Page Posting in ASP.Net?
Answer:
Cross page postback is the concept which is used to submit one page (Default.aspx) controls to another page (Default2.aspx) and access those page (Default.aspx) control values in another page

Cross page posting is a new feature introduced in ASP.NET 2.0, which eases the life of developers previously they have to use Server.Transfer which has its own advantages and disadvantages but now this is a part of ASP.NET which results flexibility and efficiency.


8. Ques: How ViewState affect performance? What is the ideal size of a ViewState ? How can you compress a viewstate?
Answer:
Viewstate stores the state of controls in HTML hidden fields. At times, this information can grow in size. This does affect the overall responsiveness of the page, thereby affecting performance. The ideal size of a viewstate should be not more than 25-30% of the page size.

Viewstate can be compressed to almost 50% of its size. .NET also provides the GZipStream orDeflateStream to compress viewstate.


9. Ques:  What is protected configuration in asp.net ?
Answer:
ASP.NET 2.0 includes a protected configuration system for encrypting and decrypting configuration information. This includes methods in the .NET Framework that can be used to programmatically encrypt or decrypt configuration information.
   The sensitive information is stored in an ASP.NET application is the Web.config file. To help secure information in configuration files, ASP.NET provides a feature called protected configuration, which enables you to encrypt sensitive information in a configuration file. A configuration file that encrypts the connection string values using protected configuration does not show the connection strings in clear text, but instead stores them in encrypted form.

ASP.NET interview questions Part-4

1. Ques: What is the difference between WCF  and web services? 
Answer:
Windows Communication Foundation : (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. It is framework to make inter-process communication easier like web services, Remoting, MS Message Queuing,
  • It can be hosted in many form like IIS, windows activation service, Self-hosting, Windows service 
  • One-Way, Request-Response, Duplex are different type of operations supported in WC.
  • System.Runtime.Serialization namespace is used for serialization.
  • Can be accessed through HTTP, TCP, Named pipes, MSMQ, Pear to pear .
  • Supports multi-threading by using ServiceBehaviour class.
  • Security, Reliable messaging, Transactions.
  • WCF are faster than Web Services.
  • Supports various protocols like HTTP, HTTPS, TCP, Named Pipes and MSMQ.
  • ServiceContract and OperationContract attributes are used for defining WCF service.

Web Services: A Web Service is programmable application logic accessible via standard web protocols. One of these web protocols is the Simple Object Access Protocol (SOAP).

  • It can be hosted in IIS Only.
  • One-way, Request- Response are the different operations supported in web service.
  • System.Xml.serialization name space is used for serialization.
  • Can be accessed through HTTP, TCP, Custom.
  • Support security but is less secure as compared to WCF.
  • Web Services are slower than WCF.
  • Doesn’t support multi-threading.
  • Supports only HTTP, HTTPS protocols.
  • WebService and WebMethod attributes are used for defining web service.

2. Ques: Difference between HttpGet and HttpPost requests?
Answer:
GET Request:-
Data is submitted as a part of url.
Data is visible to the user as it posts as query string.
It is not secure but fast and quick.
It can be cached.
GET requests remain in the browser history.
GET requests can be bookmarked.
GET requests should never be used when dealing with sensitive data.
GET requests have length restrictions.
GET requests should be used only to retrieve data.

POST Request:-
Data is submitted in http request body.
Data is not visible in the url.
It is more secured but slower as compared to GET.
It can not be cached.
POST requests do not remain in the browser history.
POST requests cannot be bookmarked.
In this no restrictions on data length.


3. Ques: What is difference between file-based dependency and key-based dependency ?
Answer:
file-based dependency:-  file-based dependency, the dependency is on a file saved in a disk.
key-based dependency:- In key-based dependency, It depend on another cached item.


4. Ques: What are the various types of validation controls provided by ASP.NET?
Answer:
ASP.NET provides 6 types of validation controls

1. RequiredFieldValidator - It is used when Use does not want the filed to be empty. It checks if the control has any value or not.
2. RangeValidator - It checks if the value in validated control is within the specified range or not.
3. CompareValidator -It checks if the value in controls matches  specific values or not.
4. RegularExpressionValidator -It checks if the value matches a specific regular expression or not.
5. CustomValidator -It Used to define User Defined validation.
6. Validation Summary - Displays summary of all current validation errors on an ASP.NET page.


5. Ques: What is the Global.asax.cs used for?
Answer:
The Global.asax.cs is used to implement application and session level events in asp.net application.


6. Ques: What is the difference between server.transfer and response.redirect in asp.net ?
Answer:

Response.Redirect 
  • In this redirect the request to some plain HTML pages on our server or to some other web server
  • we don't care about causing additional roundtrips to the server on each request.
  • we do not need to preserve Query String and Form Variables from the original request.
  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary).
Server.Transfer
  • In this transfer current page request to another .aspx page on the same server.
  • we want to preserve server resources and avoid the unnecessary roundtrips to the server.
  • we want to preserve Query String and Form Variables (optionally).
  • we don't need to show the real URL where we redirected the request in the users Web Browser.

7. Ques:  What is Scavenging?
Answer:
It is the process of deleting items from the cache when memory is scarce. Items are removed when they have not been accessed in some time or when items are marked as low priority when they are added to the cache. ASP.NET uses the CacheItemPriority object to determine which items to scavenge first. CacheItemPriority.High assigns a priority level to an item so that the item is least likely to be deleted from the cache.


8. Ques:  What is Cross Page Posting? How is it done?
Answer:
Cross page postback is the concept which is used to submit one page (Default.aspx) controls to another page (Default2.aspx) and access those page (Default.aspx) control values in another page (Default2.aspx).
                By default, ASP.NET submits a form to the same page. In cross-page posting, the form is submitted to a different page. This is done by setting the ‘PostBackUrl’ property of the button(that causes postback) to the desired page. In the code-behind of the page to which the form has been posted, use the ‘FindControl’method of the ‘PreviousPage’ property to reference the data of the control in the first page.


9. Ques: What are Master Pages?
Answer:
ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application.

  • Master pages is a template that is used to create web pages with a consistent layout throughout your application.
  • Master Pages contains content placeholders to hold page specific content.
  • When a page is requested, the contents of a Master page are merged with the content page, thereby giving a consistent layout.

Thursday, 16 February 2017

ASP.NET interview questions Part-3

1. Ques: What is serialization ? What is uses for serialization ?
Answer:
Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file.

Uses for serialization as given bellow
  • Storing user preferences in an object.
  • Maintaining security information across pages and applications.
  • Modification of XML documents without using the DOM.
  • Passing an object from on application to another.
  • Passing an object from one domain to another.
  • Passing an object through a firewall as an XML string. 

2. Ques: What is difference between XML Serialization and Binary Serialization ?
Answer:
XML Serialization:
  • XML serialization is serializing an object into an XML file.
  • It use namespace named System.Xml.Serialization. 
  • XML Serialization is more efficient and fast than Binary Serialization.
  • Xml is more interoperable and human readable than binary.
  • Xml Serializer need not mention serializable attribute on the class.
Binary Serialization:
  • Binary serialization is  serializing an object into a Binary file.
  • It use namespace System.RunTime.Serialization.Formatters.Binary.
  • Binary Serialization is more efficient and fast than XML Serialization.
  • Binary serializer need serializable attribute.     

3. Ques: What is of Globalization and Localization in ASP.NET? 
Answer :
Globalization is the process of designing the application for users of different languages across the Globe (multiple cultures). To do globalization we need to use Resource Files.

In Localization designing the application so that application behave as per the current culture and locale.

4. Ques: What is the App Domain in ASP.NET? What are the features of App Domain.
Answer :
App Domain is Lightweight process which is both a container and boundary. it is logical isolation boundary created around .NET applications so that applications do not access or affect each other.
App Domains are generally created by Hosts for example Internet Explorer and Asp.net.

Application domains have the following features:
  • Better efficiency by executing long-running processes. 
  • It provides security by restricting the direct access code from one application to the code of another application.
  • Reliability by using isolation of tasks.
  • App Domain makes the boundary for code safety.
  • Each app domain runs on its own security level.

5. Ques: What is the authentication in ASP.NET? 
Answer :
Authentication is the process of determining the authenticity of a user based on the user’s credentials.
ASP.NET provides three ways to authenticate a user:

Forms authentication: This authentication mode is cookies based authentication, where the user name and the password are stored either in a text file or the database
<configuration>
    <system.web>    
    <authentication mode="Forms">
    <forms loginUrl="login.aspx">
        <credentialspasswordFormat="Clear">
            <user name="admin" password="admin!@#" />
        </credentials>
    </forms>
    </authentication>        
    <authorization>
    </system.web>
</configuration>

Windows authentication: It authenticates users based on the users' Windows accounts.
<authentication mode="Windows"/>
<authorization>
<allow users ="*" />
</authorization>

Passport authentication: Passport authentication is a centralized authentication service that uses Microsoft's Passport Service to authenticate the users of an application.

<configuration>
  <system.web>
    <authenticationmode="Passport">
      <passportredirectUrl="login.aspx" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>
</configuration>


6. Ques: What is Authorization in ASP.NET? 
Authorization is provide the accessibility to a resource for a authenticated user. authorization can only work with authenticated users.
Three types of authorization in ASP.NET.

  • 1. URL Authorization
  • 2. File Authorization
  • 3. Authorization based on ACLs

7. Ques: What is an Impersonation?
Answer:
  • It is the process of executing code in the context of another user identity.
  • It is the mechanism in the ASP.NET which decide under which account web application should be run.
  • By default Impersonation is off, we need to enable it in Web.config file.
  • By default all the ASP.NET applications run under the ASP.NET user account. If you set the impersonation to TRUE in the Web.config file then that application runs under the current user's account who has logged in that machine. <identity impersonate="true" /> 
We can use the impersonation in this two scenarios:
  • To give each web application different permissions.
  • To use existing Windows user permission.

8. Ques: How Can you change a Master Page dynamically at runtime?
Answer:
Yes. To change a master page, set the MasterPageFile property to point to the .master page during the PreInit page event.


9. Ques:  How many web.config files can I have in an application?
Answer:
You can keep multiple web.config files in an application. You can place a Web.config file inside a folder or wherever you need (apart from some exceptions) to override the configuration settings that are inherited from a configuration file located at a higher level in the hierarchy.


10. Ques: What are Themes?
Themes are made up of skins, cascading style sheets (CSS), images, and other resources, and they are created within special folders in the server structure. Themes are like CSS styles - they both define a set of common attributes that can be applied to controls and elements on any page, however CSS is limited to the presentation elements of a control. Themes allow the customisation of any property of an Asp.net control, such as text values, icon glyphs, template layouts and so on.

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.

Sunday, 29 January 2017

ASP.NET interview questions Part-1

1. Ques: Brief about ASP.NET Page Life Cycle ?
Answer: 
Page request
Page Start
Page Initialization
Page Load
Postback event handling
Page Rendering
Page Unload


2. Ques: Brief about ASP.NET Page Life Cycle event ?
Answer: 
The following lists are the asp.net page life-cycle events.
1.PreInit event
2.Init event
3.InitComplete event
4.PreLoad event
5.Load event
6.LoadComplete
7.PreRender event
8.PreRenderComplete event
9.SaveStateComplete event
10 Render event
11.Unload event

PreInit:  PreInit is the first event in asp.net page life cycle.
               it set a master page dynamically.
               it set the theme property dynamically.
               it create or re-create dynamic controls.
               IsCallback and IsCrossPagePostBack properties have also been set in this event.
               Read or set profile property values.

Init: This event called when you can initialize your page controls property.

InitComplete: This event Raised at the end of the page's initialization stage. InitComplete event allows tracking of view state.

PreLoad: This event viewstate starts retrieving their values from controls.

Load: This Load event is raised for the page first and then recursively for all child controls.

Control: This events raised  to handle specific control events, such as a Button control's Click event.

LoadComplete: This events raised after loading process is completed.

PreRender: This events raised just before the output is rendered.

PreRenderComplete: This events raised after output is completed.

SaveStateComplete: This events saved the view state information.

Render: This is not an event; instead, at this stage of processing HTML of your page writes out the control's markup to send to the browser.

Unload: This events is last event that gets fired in Page Life Cycle .this event use for cleaning process like closing the open file connections etc..


3. Ques :  What is State Management in ASP.NET.? How many are State Managements and explain them.
Answer: 
State management is the process that maintain state of control and page over multiple requests for the same or different pages.

There are two types of state management techniques  in ASP.Net
Client side state management
  • Hidden Field
  • View State
  • Cookies    
  • Query Strings
Server side state management
  • Session 
  • Application
Client side state management

Hidden Field: 
 Hidden Fields are small amounts of data on the client side.
 It does not get displayed on the UI(browser).
 It Contains a small amount of memory.
 No server resource required.

View State: 
View State use preserve page and control values between round trips.
 It is Page-Level State Management technique .when request go from one page to other page                View State data lost.
 It Can store any type of data.
 View State use for to track the values in the Controls in asp.net.

Cookies: 
A small text file that is stored in the user's browser.
If new session created then A new cookie will be generated and store your browser until you           close your browser.
Generally cookie is used to identify users.and it Store information temporarily.
Cookies are not good for storing sensitive data.
       
 Two type of Cookie
Persist Cookie - A cookie has not have expired time Which is called as Persist Cookie.it                    exist on hard drive until you erase them or they expire
(Session cookies) Non-Persist Cookie - These cookies are saved in memory and will be lost               while closing your browser.
A new session cookie will be generated, which will store your browsing information and will             be active until you leave the site and close your browser.

Query Strings:
Query String sent information to the server by URL that are visible to the user.
It is way to transfer information from one page to another through the URL.
It store the value in the form of Key-Value pair.

Server side state management 
Session:Session state stores user specific information and the information is visible within that session only. sessions are stored in server memory called as In-Process.and sessions are stored out server memory called out- Proc.Session object store any type of data.

Application: The data stored in an application object can be Access by all user of the application.
The application object stores data in the key value pair.Data stored in the application object should be of small size.


5. Ques :What are the different types of sessions in ASP.Net? Explain them.
Answer: 
Session Management can be achieved in two ways

1) InProc
2) OutProc

OutProc is again two types
a)State Server
b)SQL Server

InProc: It stores state in Web server memory. This is the default sessions sate.
Advantages:
1) Faster as session resides in the same process as the application
2) No need to serialize the data

 Dis Advantages:
1) Will degrade the performance of the application if large chunk of data is stored
2) On restart of IIS all the Session info will be lost


State Serve: Stores session state in a separate process called the  state service.
Advantages:
1) Faster then SQL Server session management
2) Safer then InProc. As IIS restart session data not lost.
3) won't effect the session data

Dis Advantages.:
1) Data need to be serialized
2) On restart of ASP.NET State Service session info will be lost
3) Slower as compared to InProc.

SQL Server: Session state store in a SQL Server database.
Advantages
1) Reliable and Durable.
2) IIS and ASP.NET State Service restart won't effect the session data
3) Good place for storing large chunk of data

Dis Advantages:
1) Data need to be serialized
2) Slower as compare to InProc and State Server
3) Need to purchase Licensed version of SQL Serve


6. Ques : What is the difference between GET method() and POST method()?
Answer
GET method( )

  • Data is affixed to the URL.
  • Data is not secured.
  • Data transmission is faster in this
  • This is a single call system.
  • Only limited amount of data can
  • be sent.
  • It is a default method for many
  • browsers.

POST method( )

  • Data is not affixed to the URL.
  • Data is secured.
  • Data transmission is comparatively slow.
  • This is a two call system
  • Large amount of data can be sent.
  • It is not set as default. it should be explicitly specified.