Monday, April 18, 2016

ASP.Net Interview Questions



     What is AutoPostback in ASP.Net
  • It is the Property of the control by which page will be posted back to server based on the Web server controls like Button click event and Drop-down selected index change event etc..
     How can we identify that Page is Posted or not
  • Page Object has "Ispostback" Property to check whether page is posted to server or not.
  • Ispostback returns a Boolean value.It returns "True" if page is posted to server else returns false.
   What is the Lifespan for Items stored in Viewstate
  • The data present in View state exists until the Current page is Active.
  • If Current page gets expired or any post-back happens to the same page then View state information will be lost.
  • If end user redirects to different page and comes back to the same page then also view state information will be lost.
    Why do we use APP_Code folder in ASP.Net
  • APP_Code folder contains Class files,Report files,data set files and all the items stored in this folder can be accessible through out the Application.
  • Only One APP_Code folder exists in the Application path.If folder contains two files with two different languages then we will get an Compile error as all the files present in this folder will  are build with one Assembly.
  • If we want to add two files with two different languages then we need to create two sub folders and we need to add files to it.
    What is Tracing and where it is used
  • Tracing helps us to view the information about the execution of  a specific page which is executed on the Web server.
  • Tracing can be enabled at Application level or Page level.
  • Enabling tracing at Application level can be done with in the Web.config file as listed below
                            <system.web>
                              <trace enabled="true"/>
                           </System.web> 
  • At page level add trace="True" attribute to the page directive. which is shown below
                      <%@ Page language="C#" Trace="true" %>
  • If tracing is enabled(means true) then all the messages are written in a trace.axd file and this file will be available to local users or remote users based on the configuration.
  • If localonly="true" then trace messages are available to local users not to Remote Users.
  • If localonly="False" then trace messages are available to Remote users not to local users.
System.web>
<trace enabled="true" localonly="true"/>
</System.web>
     Uses of Tracing:

  • If any Troubleshoot(Issues) happens then developers will debug the application at development phase and can solve the issues but at Production level it is not possible to debug the application to overcome this issue we make use of Tracing.
  What is Authentication and Authorization in ASP.net
  • Authentication:It is the Process of identifying the user based on the User credentials like User Name and Password.
  • Authorization:It is the Process of determining what rights and permissions that Authenticated user had.
  What is Globalization and Localization in ASP.Net
  • Let say we have an Application developed using English Culture and accessed the application.But some users want the Application to be developed using Hindi Culture or any other Culture.To overcome the problem we make use of Globalization and Localization.
  • Globalization:It is the process of designing and developing an Application in such a way that an Application need to support Multiple Cultures.
  • Localization:It is the Process of Customizing an Globalized Application as per our Current Culture.
  What is View state in ASP.Net
  • View State:It is a Client side State Management technique which is used to maintain the state of the page between Round trip to Server.
  • View state information exists until current page is Active.If Current page gets expired including the post back to same page then View state information will be lost.
  • We can configure the View state at Page level or at  Application level.
  • Application Level:If we enable view state at Application level then view state information will be available for entire Application.Enabling View state at Application level  should be done in web.config file is shown below
                                            <System.web>
                                       <pages enableviewstate="True"/>
                                           </System.web>
  • Page level:If we enable View state at page level then View state information will be available only to that particular page itself.Enabling view state at page level is shown below
               <%@ Page language="C#" enableviewstate="true"%>
  • Advantages:
  1. It is easy to implement.
  2. No server resources are required.
  3. It is secured as the View state information is Encoded.
   Which Method is used to force all the Validation controls to run
  • Page.Validate() Method is used to force all the Validation controls to run and perform validation.
    Difference between Page.Validate() and Page.Isvalid property
  • IsValid: IsValid is a Page property to check whether the page validation gets succeeded or not.
  • Validate:It is the property of the control which is fired automatically if the Web server controls like button,drop down and other server controls has causevalidation property set to true.
   Difference between Client side and Server side validation in Web page

Client Side
Server Side
It performs validation at client side with the help of javascript before page is submitted to Server. It performs validations at server side and one of the main advantage of server side validation is if javascript is disabled then client side validation will not work then we make use of server side validation


  Difference between Response.Write and Response.Output.Write methods.
  • Response.Write:It allows us to write the Normal output.
  • Response.Output.Write:It allows us to write formatted Output.     
  • Response.write(".Net{0}","ASP"); it will not work for Response.Write as it is formatted Output but it will work for Response.Output.Write.
  • Response.Write(".Net ASP");It will work for both Response.Write and Response.Output.Write.
   What are Event handlers  available in Global.asax file
  • Global.asax file is used to server Application and session level events and we can have only one Global.asax file in our Application.
  • Events available in Global.asax file are
  1. Application_Start: It is automatically fired when the first instance of HTTP Application class is created.
  2. Application_Error: If any unhandled exceptions occurs in the Application then this event gets fired.
  3. Application_End: It is fired when Last instance of HTTP Application  is destroyed.
  4. Session_Start: It is fired automatically when new user visits the Application.
  5. Session_End: When session state's Mode is set to Inproc then this event gets fired otherwise it will not get fired.We can also call this event explicitly by using session.Abandon.
What are validation controls in ASP.Net
  • Validation controls allows us to validate the user input data whether the information entered is valid or not.Validation controls are of 6 types which are listed below
  • Required Field Validator:It allows us to check whether the data entered for input control or not.If input control is empty then it will display an error message.
  • <asp:Requiredfieldvalidator id="rfv1" runat="Server" controlToValidate="txtid" ErrorMessage="Input control should not be blank"/>
  • ControlToValidate and ErrorMessage ate important properties.
  • CompareValidator:It allows us to compare the data entered in an input control against the value in a different control.
  • <asp:comparevalidator id="cmpval" runat="Server" controltocompare="Textbox1" controlToValidate="Textbox2" ErrorMessage="Should be same" operator="Equal"/>.
  • If both the textboxes are empty then Validation gets succeeded so we need to make use of RequiredfieldValidator.
  • RangeValidator:It allows us to check whether the control value is within the Range.
  • <asp:Rangevalidator id="Rngv" runat="Server" controlToValidate="Textbox1" Maximumvalue="50" MinimumValue="10" type="Integer" ErrorMessage="Should be with in the range"/>
  • Regular Expression Validator:It allows us to check the User input data based on the pattern specified using Regular Expression.
  • <asp:RegularExpressionValidator id="regv" runat="Server" ErrorMessage="Not valid" ValidationExpression="\b123\b"/>
  • CustomValidator:CustomValidator can be used on both  Client side and Server Side and we can perform Custom Validations on client side with the help of Javascript.
  • Validation Summary:It allows us to display the summary for all the validation error that occurs on a page.
   Which methods are used to Post from one page to another page in Asp.Net
  • Response.Redirect
  • server.Transfer
  • Hyperlink
  • Server.Execute
  • Link Button
     Above methods are used to Redirect from one page to Another page in Asp.Net

    What is a Cookie in ASP.Net
  • Cookies: Cookies allows us to store small amount of information like user name,Password etc  on client machine
  • Cookies allows us to send information from one page to another page.
  • Cookies are classified into two types
  1. Persistent Cookie:If we set an Expiry date then it is said to be Persistent cookie.
  2. Non Persistent Cookie:If we don't set an Expiry date then it is said to be Non Persistent cookie
  Example
                :Response.Cookies["Data"].value="Venkat";
                 Response.Cookies["Data"].Expires=DateTime.Now.AddSeconds(1);// Persistent cookie


    What is Impersonation in ASP.Net and how to configure it
  • Impersonation:It is the Process of executing code in context of  another user identity is Impersonation.
  • By default All the Asp.Net application code is executed using fixed Machine specific account
  • In order to execute the code using another identity we make use of Impersonation.
  • Configuring Impersonation in Web.config file is shown below  
                <System.Web>
               <identity Impersonate="true"/>
               </System.Web>

   What is difference between Application state and Session State
  • Application State:These Application state variables are available for all users and across all the sessions.
  • But Session state are available for all users and for a given session.
  • Session State Variables are cleared when Timeout Occurs but Application state Variables are cleared when worker process is Restarted.
  • Application state Variables are stored on Web server itself but for session it can store in ASP.Net state server or it can store in SOL Server or it can store on Web server with in  Worker process.  
    How can you ensure that no one has tampered View state with in the Web page
  • To make sure that no one has tampered the View state in a Web oage we need to set "EnableViewstateMac" to true in Page directive
          <$@ Page language="C#" enableviewstatemac="true" %>

   Explain Cookieless session and its Working
  • Bydefault Session uses cookie.When end user sends a request to server,it creates a session id and this session id is stored as a cookie on client machine.
  • The Session ID is then used by web server to identify if the Request is coming from same server or different server.
  • If user disables cookie then it will not work.In order to Overcome we make use of Cookie less sessions.
  •  Enabling cookie less in web config is shown below
                   <System.web>
                           <Sessionstate cookieless="true"/>
                   </System.web>

     What is a Round Trip
  • The trip of a web page from client to server and again back to client is known as Round Trip.
    Where is View State information stored
  • The View state information is stored in a HTML hidden field with name _Viewstate.
    What is difference between HTML and Web server controls
  • HTML controls are client side controls therefore all the validations for HTML controls can be performed at client side.
  • Web server controls are Server side controls therefore all the validations can be performed at the server side.
  • We can convert HTML controls into web server controls by adding runat="Server" attribute which is shown below
  <input type="Text" name="txtname" runat="server"/> 

   What is difference between Hyper link and Link button
  • Hyper link does not have any Click and Command events where as for Link button we have click and command events.
  • Hyper link navigates to URL when user clicks on it where as for Link button the page is posted to server before navigating to URL  
    What are different types of Authentication Techniques
  • Windows Authentication:In this Authentication ASP.net web pages uses Local window users and groups to Authenticate and Authorize the resources.(web pages etc).
  • Implementation:
  • First we need set Authentication mode to Windows in web.config file.
  • Then in Authorization tag we need to deny anonymous users.
  • Finally we need to enable Window authentication in IIS.
  • Form Authentication:It is a cookie based authentication where username and password are stored on a client machine.We can also provide our own credential verification by comparing user credentials against database or xml file etc.
  • Implementation:
  • First we need to set authentication mode to forms in Web.config.
  • Then in Authorization tag we need to deny anonymous users.
  • Passport Authentication:It depends upon on the centralized services provided by the Microsoft.It identifies a user with E-mail address and a password and a single password account can be used with different websites.

    Difference between Machine.config and Web.config


Machine.Config
Web.config
It is automatically installed created when we install Visual studio. It is automatically created when we create an ASP.net application/td>
Configurations present in Machine.config is available for all the applications running the machine. Configurations present in Web.config is available to that Application itself/td>
Only one Machine.config exists on a server. We can have Multiple web.config files in a Application/td>


Where does Machine.config resides

  • For 32 bit machine machine.config exists in below location
  • C:\Windows\Microsoft.NET\Framework\[Version]\config\machine.config
  • For 64 bit Machine.config exists in
  • C:\Windows\Microsoft.NET\Framework64\[Version]\config\machine.config

What is an Event bubbling

  • Basically we have a controls like Data grid,Repeater Controls,grid view can have a child controls inside them.
  • For example data grid control can have a child control like button control and this child control(button) does not raise their event by themselves instead it pass the event to parent control(data grid).As child control pass the event to parent is termed as Event bubbling.

    What is difference between Custom control and User control
  • Custom Controls are compiled into their own Assembly where as User control is compiled along with the Application.
  • Custom controls can be added to Tool box where as user controls cannot be added.
  • User controls are easy to create as it is similar to Web page where as Custom control is complex as there is no designer every thing has to be done in code.
  • A separate copy of user control is required in each application where as single copy of custom control can be used in Multiple projects.
   Difference between Response.Redirect and Server.Transfer
  • Response.Redirect involves round trip to server where as Server.Transfer conserves resources by avoiding round trip to Server.
  • Response.Redirect can be used for both  aspx and html pages where as  Server.Transfer can be used for aspx pages.
  • Response.Redirect  can be redirect to an external pages which is on another server where as Server.Transfer can be used to redirect to a page which is on same server but it cannot redirect to a page which is on different Server.
    Difference between Server.Transfer and Server.Execute
  • Server.Execute method redirects to a different page,execute the code and again come back to the initial page.
  • But Server.Transfer redirects to the different page but it will not come back to the Initial page
    What are Session State Modes in ASP.Net
  • There are Five types of Session state Modes in ASP.Net
  • Off: If we set the Session State Mode to Off then Session State is disabled for an Entire Application.We need to configure Session State mode in Web.config as shown below
           <System.web>
                <Sessionstate Mode="Off"/>
         </System.web>

  • In Proc: If the session state is set to Inproc then Session State Variables are stored on Web server Memory with in the Worker Process.Configuration for Session State mode is hsown below
         <System.web>
            <Sessionstate Mode="Inproc"/>
          </System.web>

  • State Server If we set the Session State Mode to State Server then all the Session Variables are stored in a process called ASP.Net State Server.
  • Steps to Implement ASP.Net Session State Server is shown below
        1. As ASP.Net State Server is a Window Service first we need to start the Window service.
        2. We need to configure the Mode as State Server in Web.config as  shown below

            <System.web>
          <Sessionstate mode="Stateserver" stateconnectionstring="tcpip=localhost:portnumber"/>
            </System.web>
  • SQL Server: If we set the Session State Mode to SQL Server then all the Session Variables are stored in the SQL Server database.
  • Custom:If we want to Save the Session Variables in another databases like ORACLE,DB2 etc then we make use of Custom Mode.
    Describe MAster Page in ASP.Net
  • Master Page allows us to create Consistent look and behavior for all the web pages in an Application.
  • Master pages acts as a fixed template for all other web pages and master page should contain at one Contentplaceholder where a web page will be merged with Master page at run time.
  • Extension for the Master page is .Master.
    Difference between Master page and User Control
  • Master page has a file extension of .Master where as for User control it has a file extension of .ascx
  • User control does not contains ContentPlaceholder where as for master page it contains Contentplaceholder
  • User control does not work like a fixed template.It can display in different manner in different situation.But Master page acts as a Fixed Template.
     What is Caching in ASP.Net
  • Caching allows us to store the entire Rendered HTML in the browser.Then for the subsequent request it will not process the whole web page again instead it will fetch the data from the browser which will improve performance.
 

  • From the above image it contains duration="5" means web page will be stored in the browser for 5 Seconds.Once after duration of 5 seconds is completed again  Web page will be processed once again and stores it in the Web browser.     
   Different Types of Caching in ASP.Net
  • There are 3 different tyoes of Caching as shown below
  1. Page Output Caching: In this Caching,the Entire Rendered HTML of a page will be cached with in the browser.When the sae page is requested again the Cached copy present in browser will be fetched,
     

    2. Fragment Caching: It allows us to cache the Portions(Parts) of page instead of caching
        whole page is Fragment Caching.In this Caching it will not cache the Web page instead it
        allows us to cache the User Control.
   


  • The above piece of code shown in the image above should be placed in User Control not in the Web page.        

      3. Data Caching: Data Caching allows us to fetch the data for a Complex query which will take
          a  lot of time from the data source and caches the data.Then for the Subsequent Request it
         will not  fetch the data from Data source instead it will serve(take) the Cached data.

    What is Cross Page posting in ASP.Net
  • Cross Page Posting allows us to post from one web page to another Web page.By default when we click on Button  then it will not post(goes) to another page it will be on same page.If we want to post to different page on Button click then we need to set Postbackurl property which is refereed as Cross page Posting.
   

     What is the use of Custom Error tag in Web.config file
  • If there is any Unhandled exception by default ASP.Net shows an default error page as shown below
  • In order to display an Custom error page we make use of  Custom Error.
  • We can display Custom Error at Page level or at Application level.
  • Setting Error Attribute at page level is shown below




  • Setting Error tag at Application level in web.config file is shown below
     

  What are different Custom Error Modes in ASP.Net
  • Different Modes available in Custom Error tag are
  1. On: If Custom Error Mode is set to "ON" then  Custom Error pages are displayed on both local and Remote Machines






  2. Off: If Custom error Mode is set to "Off" then Custom Error pages are not displayed.




  3. Remote Only: If Custom error mode is set to "Remote Only"then Custom error pages are displayed on Remote Machine and Error pages are displayed on Local Machine




   What is an  AutoEventWireup in ASP.Net
  • If AutoEvent Wireup is set to True the page event handler methods like page_Load,Page_init etc are automatically wired up with the Respective controls.
  • If we set to false then Page event handler methods are not fired automatically we need to call it Explicitly as shown below


  • .

 What is an Application Pool in IIS
  • Application Pool: It is used to separate the set of Worker process in IIS which shares the Same configuration.
  • Application pool are also used to separate Application for better performance and Reliability.
  • When Worker process or application is having any issue only that worker process gets affected without affecting another Worker process.
 What is Worker Process
  • Worker Process(W3WP.exe) runs the Application with in the IIS.
  • This Process is responsible for managing all the request and responsible which are coming from client system.
  • All the ASP.Net functionality runs under the scope of Worker Process.
What is Web Farming and Web Gardening
  • Web Farming: When we host an Application in Web server and multiple clients are requesting for resources then one web server is not sufficient as there might be huge amount of incoming traffic.Hence we need to host the Web Application in Multiple servers and divide the incoming traffic among them.This process is called Web Farming.
  • Web Gardening:When a Single Application pool contains multiple worker process then it is said to be Web Gardening
What is 3-Tier Architecture 
  • Presentation Layer: In this layer we design an User interface with the help of Web server or Html controls.End user will use this layer to enter the input data and this data is forwarded to Business logic Layer.
  • Business Logic Layer: It is the Middle layer which acts as a bridge between Presentation Layer and Data Access Layer.In this layer it performs an Business logic and validations as per business requirement.Once the validations or logic has been performed then it forwards the data to Data Access layer/
  • Data Access Layer: This layer communicates with database,Fetches the data from database and forwards the data to Business layer which in turn forwards the data to Presentation layer.
What is Instrumentation in ASP.Net
  • Instrumentation: It is nothing but the ability to monitor the execution of Application.Tracing and Debugging are subsets of Instrumentation.
  • Debugging is monitoring the execution of Application at Development phase.
  • Tracing is monitoring the execution of Application at Production level.

Will Website run without web.config
  • If our webpages does not make use of Keys present in Web.config file then our Web application will run.
  • If Application does not contains Web.config file then it will  read the configuration details from Machine.config file.
What is Response.Redirect True VS False
  • Basically Response.Redirect allows us to Redirect from one page to another page.
  • If Response.Redirect is "False" then the Current page is not terminated  but the code after the Response.Redirect will get executed and then it will redirect to different page.
  • But if we set to "True" then the current page will get terminated and the code written after the Response.Redirect will not get executed but it redirects to different page.
Difference between Session.Clear and Session.Abandon.
  • Session.Clear will clear all the session variable values where as Session.Abandon will kills(Terminates) the session.
What are page life cycle events in ASP.Net
  • When we send a request to server then it goes through series of page life cycle events as shown below
  • Page PreInit:First it checks for IsPostback property to determine whether it is the first time page is processed or not.
  • We can also creates an dynamic controls.
  • We can set theme property and master page dynamically.
  • Init Event:In this event each controls unique ID is set.
  • We can also read or initialize the control properties.
  • Init Complete:This event is raised once after the initialization of page and control is completed.
  • In this event page's state is not yet populated,we can access the server controls but it will not contains the information returned from the user.
  • PreLoad Event:In this event Viewstate information will be loaded to all the controls.
  • Page Load:This is the most commonly used event on Server side.All the code inside this event will execute once.
  • Control Events:This event is used to handle specific control events like Button click,Dropdown selectedindexchanged etc.
  • PreRender Event:This is the event where final changes to page or control is allowed.After this event we cannot change any control or Viewstate values.
  • Render Event:In this event It renders the HTML Page to the end user.
  • Unload Event:This event is used for clean up.Once after the page is rendered the objects get disposed.
What is ASP.Net Application life cycle
  • Application Life Cycle:When an end user sends a request to server an APPDomain is created by the Application manager where an Application runs and it creates a separation between two or more web applications.
  • With in APP Domain an instance of hosting environment is created which provides the information of av Application.
  • Then after Response objects are created like HTTPRequest,HTTPResponse and HTTPContext.
  • Finally an Application starts by creating the instance of HTTPApplication.
What is the order of execution of execution of Master page,User control and Content page
  • Initialization event(init event) will be raised from inner most control to outer most control like User control,Master page and Content page(Web page).
  • For remaining event like page load,pre Render and other events it will be raised from Outer most control to inner most control like Content page(Web page),Master page and User control.
Will website run without Web.config file
  • Yes it will run as it take the configuration settings from Machine.config file.
What is difference between Http and Https

HTTP
HTTPS
It is a hyper text transfer protocol which is responsible for sending and receiving information across network It is a secure http which is used for exchanging confidential information with server and it need to be secured in order to prevent from unauthorized access.
It is transmitted over network via port80 It uses port 443 instead of Http port 80

What is difference between Viewstate and Hidden field

View-State
Hidden-Field
View-State is a Variable Hidden-Field is a Server control
It can store large amount of data It stores small amount of data.
It is secure It is insecure

Can we store a datatable in cookie
  • Storing datatable in cookie is not a recommended one as cookie size is very small and in some cases cookie may be disabled by the browser.Hence it is not recommended to store datatable in cookie.
What are Http handlers and Http Modules in ASP.net
  • If we need to inject any pre processing logic before request hits the IIS then we need to make use of Http Handler and Http Module.
  • Http Handler:It allows us to inject the pre-processing logic based on the extension of file name requested.So when a page is requested,Http handle gets executed based on extension of file name and on base of verbs.
  • Http Module:It is a event based method which allows us to inject pre processing logic before resource is requested.when ever client sends a request for resource then request goes through events with in the pipeline.



No comments:

Post a Comment