Quick Reference and FAQ: in Multinational Companies
Quick Reference and FAQ: in Multinational Companies
Quick Reference and FAQ: in Multinational Companies
Abhishek Goenka
CIBERSITES INDIA
Version 1.0
.Net Interview Questions 2011
From constructor to destructor (taking into consideration Dispose() and the concept of non-
deterministic finalization), what are the events fired as part of the ASP.NET System.Web.UI.Page
lifecycle. Why are they important? What interesting things can you do at each?
As all of us know a request comes from Client (Browser) and sends to Server (we call it as Web server) in
turn server process the request and sends response back to the client in according to the client request.
But internally in the web server there is quite interesting process that happens. To get aware of that
process we should first of all know about the architecture of the IIS It mainly consists of 3 Parts/Files
Inetinfo.exec
ISAPI Filer (Container for Internet Server Application Interface dlls),
Worker Process (aspnet_wp.exe)
Inetinfo.exe is the ASP.Net request handler that handles the requests from the client .If it's for static
resources like HTML files or image files inetinfo.exe process the request and sent to client. If the request
is with extension aspx/asp, inetinfo.exe processes the request to API filter. ISAPI filter will have several
runtime modules called as ISAPI extensions. To process the request ISAPI filter takes the help of these
runtime modules. The runtime module loaded for ASP page is asp.dll. And for ASP.NET page it's
ASPNET_ISAPI.dll. From here the request is processed to the "worker process". Worker Process will have
several application domains.
Worker process sends the request to HTTPPIPE line.(HTTP Pipeline is nonetheless collection of .net
framework classes). HTTP Pipeline compiles the request into a library and makes a call to HTTP runtime
and runtime creates an instance of page class
ASP.Net web page is a class derived from page class, this page class resides in system.web.dll
After creating instance pf page class HTTP Runtime immediately invokes process request method of
page class
Page|2
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
Use this event to make changes to view state that you want to make sure are
persisted after the next postback.
Raised after the page loads view state for itself and all controls, and after it
PreLoad
processes postback data that is included with the Request instance.
The Page object calls the OnLoad method on the Page object, and then
recursively does the same for each child control until the page and all controls
are loaded. The Load event of individual controls occurs after the Load event of
Load the page.
Use the OnLoad event method to set properties in controls and to establish
database connections.
Use these events to handle specific control events, such as a Button control's
Control events
Click event or a TextBox control's TextChanged event.
Raised at the end of the event-handling stage.
LoadComplete Use this event for tasks that require that all other controls on the page be
loaded.
Raised after the Page object has created all controls that are required in order to
render the page, including child controls of composite controls. (To do this, the
Page object calls EnsureChildControls for each control and for the page.)
PreRender
The Page object raises the PreRender event on the Page object, and then
recursively does the same for each child control. The PreRender event of
individual controls occurs after the PreRender event of the page.
Page|3
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
Use the event to make final changes to the contents of the page or its controls
before the rendering stage begins.
Raised after each data bound control whose DataSourceID property is set calls its
PreRenderComplete DataBind method. For more information, see Data Binding Events for Data-
Bound Controls later in this topic.
Raised after view state and control state have been saved for the page and for all
SaveStateComplete controls. Any changes to the page or controls at this point affect rendering, but
the changes will not be retrieved on the next postback.
This is not an event; instead, at this stage of processing, the Page object calls this
method on each control. All ASP.NET Web server controls have a Render method
that writes out the control's markup to send to the browser.
If you create a custom control, you typically override this method to output the
control's markup. However, if your custom control incorporates only standard
Render
ASP.NET Web server controls and no custom markup, you do not need to
override the Render method. For more information, see Developing Custom
ASP.NET Server Controls.
A user control (an .ascx file) automatically incorporates rendering, so you do not
need to explicitly render the control in code.
Raised for each control and then for the page.
In controls, use this event to do final cleanup for specific controls, such as closing
control-specific database connections.
Unload
For the page itself, use this event to do final cleanup work, such as closing open
files and database connections, or finishing up logging or other request-specific
tasks.
Although both Init and Load recursively occur on each control, they happen in reverse order. The Init
event (and also the Unload event) for each child control occur before the corresponding event is raised
for its container (bottom-up). However the Load event for a container occurs before the Load events for
its child controls (top-down). Master pages behave like child controls on a page: the master page Init
event occurs before the page Init and Load events, and the master page Load event occurs after the
page Init and Load events.
What is EnableViewStateMAC?
Setting EnableViewStateMac=true is a security measure that allows ASP.NET to ensure that the
viewstate for a page has not been tampered with. If on Postback, the ASP.NET framework detects that
there has been a change in the value of viewstate that was sent to the browser, it raises an error -
Validation of viewstate MAC failed.
Page|4
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
Use <%@ Page EnableViewStateMac="true"%> to set it to true (the default value, if this attribute is not
specified is also true) in an aspx page.
But this has a side effect: it also prevents multiple servers from processing the same ViewState. One
solution is to force every server in your farm to use the same key-- generate a hex encoded 64-bit or
128-bit <machineKey> and put that in each server's machine.config :
<!-- validation="[SHA1|MD5|3DES]" -->
<machineKey validation="SHA1"
validationKey="F3690E7A3143C185A6A8B4D81FD55DD7A69EEAA3B32A6AE813ECEEC" />
Page|5
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
controls etc. Cache should be used or frequently used pages, controls, and data structures. Data cache
can be used to cache frequently used list of values e.g. list of products
Cookies - Cookies are some values saved in browsers by the website to retrievable and use afterwards.
Usually cookies are used to help dynamic websites to identify visitors and retrieve their saved
preferences. Cookies are also used to facilitate auto login by persisting user id in a cookie save in user's
browser. Because cookies have been saved at client side, they do not create performance issues but
may create security issues as they can be hacked from browser.
Page|6
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
Page|7
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
@Import: 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.
<% @ Import Namespace="System.web" %>
@Implements: Indicates that the current page or user control implements the specified .NET framework
interface.<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
@Register: Associates aliases with namespaces and class names for concise notation in custom server
control syntax.<%@ Register Tagprefix="Acme" Tagname="AdRotator" Src="AdRotator.ascx" %>
@Assembly: Links an assembly to the current page during compilation, making all the assembly's classes
and interfaces available for use on the page. <%@ Assembly Name="MyAssembly" %><%@ Assembly
Src="MySource.vb" %>
@OutputCache: Declaratively controls the output caching policies of an ASP.NET page or a user control
contained in a page<%@ OutputCache Duration="#ofseconds" Location="Any | Client | Downstream |
Server | None" Shared="True | False" VaryByControl="controlname" VaryByCustom="browser |
customstring" VaryByHeader="headers" VaryByParam="parametername" %>
@Reference: Declaratively indicates that another user control or page source file should be dynamically
compiled and linked against the page in which this directive is declared.
What are ASHX files? What are HttpHandlers? Where can they be configured?
ASP.NET programming supports the creation of custom HttpHandler components, which provide a
flexible and efficient way to process requests that don't return standard HTML-based pages. For
example, HttpHandler components are great for situations in which you want to return simple text,
XML, or binary data to the user.
The easiest way to create a custom HttpHandler component is to create a source file with an .ashx
extension. You must then add a @WebHandler directive to the top of the .ashx file, along with a class
definition that implements the IHttpHandler interface. Any class that implements the IHttpHandler
interface must provide an implementation of the IsReusable method and the ProcessRequest method.
<%@ Assembly Name="Microsoft.SharePoint, [full assembly name]"
%> <%@ WebHandler Language="C#" Class="HelloHttpHandler" %>
using System;
using System.Web;
using Microsoft.SharePoint;
Page|8
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
After you deploy your .ashx file within a directory nested within the \LAYOUTS directory, it is accessible
to any site in the farm by using a site-relative path.
http://MyWebServer/sites/Sales/_layouts/Litware/HelloHttpHandler.ashx
What is needed to configure a new extension for use in ASP.NET? For example, what if I wanted my
system to serve ASPX files with a *.jsp extension?
It is possible to configure new extension for use in ASP.Net. This as to be configured in IIS actually in
order for IIS to route your pages to the proper ISAPI
Follow this: http://blogs.msdn.com/gduthie/archive/2007/03/14/custom-file-extensions-in-asp-net-2-
0.aspx
What events fire when binding data to a data grid? What are they good for?
ItemCreated: The ItemCreated event is fired when an item in a DataGrid control is created. This means
that at the time the event is fired, the DataGrid does not yet know about the data that will be bound to
it. So, if the logic of your method depends on this data being available to the control, you’re better off
using the ItemDataBound event. Other than that, the ItemCreate event differentiates itself in one other
way from the ItemDataBound event: the ItemCreated event is raised when data is bound to the control
and during round-trips (postbacks). These qualities make the event especially well-suited to add custom
attributes to a DataRow (such as onmouseover or other javascript events) or to control the appearance
in ways that do not depend on the data within the DataRow (such as making every 10th row a different
color).
ItemDataBound: The ItemDataBound event is fired after after an item in a DataGrid control is bound.
This means that (unlike the ItemCreated event) you can add special formatting to a DataRow that is
dependent upon the data contained within that row. Since ItemDataBound is fired after the
ItemCreated event, it is within this event that you are presented with the final opportunity to access the
data before it is rendered to the client. These qualities make the event well-suited for changing the
appearance of a row or cell based on the data within that row or cell (such as highlighting outliers or
other important information).Example:
<asp:DataGrid ID="MainDataGrid"
runat="server"
AutoGenerateColumns="true"
OnItemDataBound="MainDataGrid_ItemDataBound"
OnItemCreated="MainDataGrid_ItemCreated" />
On the code behind page then, we can create the following two methods to handle adding
titles to header row, to specify more descriptive headers, and to change the row
background color based on an employee’s salary:
Page|9
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
P a g e | 10
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
Let’s have a look at the different types of syntax we can use for code blocks in ASP.NET pages. There are
really four types of code blocks, and the first one is different from the others:
<%$ %>
<%# %>
<% %>
<%= %>
ASP.NET Expression Syntax
First of all we have ASP.NET expressions which look like <%$ AppSettings:Key %>
<asp:Label runat="server" Text="<%$ AppSettings:Key %>" />
ASP.NET Data-Binding syntax
The next code construct is the data-binding syntax: <%# Eval("Value") %> which is used to bind to
properties to data on demand.
Statement and Expression/Evaluated Code Blocks
Display some values
<%
string message = "Hello World!";
Response.Write(message);
%>
These are delimited by <%= and %> and the content of this code block becomes the parameter to the
HtmlTextWrite.Write() method. Therefore, the code inside this type of code block should be an
expression, and not a statement.
<%= String.Format("The title of this page is: {0}", this.Title ?? "n/a") %>
1. RequiredFieldValidator
2. RangeValidator
3. RegularExpressionValidator
4. CompareValidator
5. CustomValidator
P a g e | 11
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
ValidationSummary is not a validation control but a control that displays summary of all error occurs
while validating the page.
How to get the authentication mode from web.config file programmatically at runtime?
System.Web.Configuration.AuthenticationSection section =
(AuthenticationSection)WebConfigurationManager.GetSection("system.web/authentication");
Label1.Text = section.Mode.ToString();
Compilation for deployment can be performed in one of two ways: one that removes all source files,
such as code-behind and markup files, or one that retains the markup files.
P a g e | 12
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
If you create a cookie without specifying an expiration date, you are creating an in-memory cookie,
which lives for that browser session only. The following illustrates the script that would be used for an
in-memory cookie:
Response.Cookies("SiteArea") = "TechNet"
TODO List
Explain how PostBacks work, on both the client-side and server-side. How do I chain my own JavaScript?
How does ViewState work and why is it either useful or evil?
What is the OO relationship between an ASPX page and its CS/VB code behind file in ASP.NET 1.1? In
2.0?
What happens from the point an HTTP request is received on a TCP/IP port up until the Page fires the
On_Load event?
How does IIS communicate at runtime with ASP.NET? Where is ASP.NET at runtime in IIS5? IIS6?
What is an assembly binding redirect? Where are the places an administrator or developer can affect
how assembly binding policy is applied?
Compare and contrast LoadLibrary(), CoCreateInstance(), CreateObject() and Assembly.Load().
P a g e | 13
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
System.Web.Mvc.Html namespace
Contains classes that help render HTML controls in an MVC application. The namespace includes classes
that support forms, input controls, links, partial views, and validation.
MVC.NET provides helper function to check for Ajax requests which internally inspects X-Requested-
With request header to set IsAjax flag.
HelperPage.IsAjax Property
Gets a value that indicates whether Ajax is being used during the request of the Web page.
Namespace: System.Web.WebPages
Assembly: System.Web.WebPages.dll
However, same can be achieved by checking requests header directly:
Request["X-Requested-With"] == “XmlHttpRequest”
P a g e | 15
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
// overloaded constructor
public myController(IMyRepository repository)
{
this.repository = repository;
}
Giving this level of authority to the controller isn’t an easy task in most cases. Users interaction in an
application happen most of the time on the View.
Thus to adopt MVC pattern in a web application, for example, the url need to become a way of
instantiating a specific controller, rather than ‘simply’ finding the right View (webform/ html page) to
render out. Every requests need to trigger the instantiation of a controller which will eventually produce
a response to the user.
P a g e | 16
Prepared by Abhishek Goenka
Email – [email protected]
.Net Interview Questions 2011
This is the reason why it’s alot more difficult to implement pure MVC using Asp.Net Webform. The Url
routing system in Asp.Net webform by default is tied in to the server filesystem or IIS virtual directory
structure. Each of these aspx files are essentially Views which will always get called and instantiated first
before any other classes in the project. (Of course I’m overgeneralizing here. Classes like IHttpModule,
IHttpHandler and Global.asax would be instantiated first before the aspx web form pages).
MVP (Supervising Controller) on the other hand, doesn’t mind for the View to take on a bigger role.
View is the first object instantiated in the execution pipeline, which then responsible for passing any
events that happens on itself to the Presenter.
The presenter then fetch the Models, and pass it back to the view for rendering.
How to call javascript function on the change of Dropdown List in ASP.NET MVC?
Create a java-script function:
<script type="text/javascript">
function selectedIndexChanged() {
}
</script>
P a g e | 17
Prepared by Abhishek Goenka
Email – [email protected]
Thank You for previewing this eBook
You can read the full version of this eBook in different formats:
To download this full book, simply select the format you desire below