Your Ad Here

Wednesday, October 28, 2009

ASP.Net

1) What is CLS (Common Language Specificaiton)?
It provides the set of specificaiton which has to be adhered by any new language writer /
Compiler writer for .NET Framework. This ensures Interoperability. For example: Within a
ASP.NET application written in C#.NET language, we can refer to any DLL written in any other
language supported by .NET Framework. As of now .NET Supports around 32 languages.

2) What is CTS (Common Type System)?
It defines about how Objects should be declard, defined and used within .NET. CLS is the
subset of CTS.

3) What is Boxing and UnBoxing?
Boxing is implicit conversion of ValueTypes to Reference Types (Object) . UnBoxing is explicit conversion of Reference Types (Object) to its equivalent ValueTypes. It
requires type-casting.

4) What is the difference between Value Types and Reference Types?
Value Types uses Stack to store the data where as the later uses the Heap to store the data.

5) What are the different types of assemblies available and their purpose?
Private, Public/shared and Satellite Assemblies.
Private Assemblies : Assembly used within an application is known as private assemblies
Public/shared Assemblies : Assembly which can be shared across applicaiton is known as
shared assemblies. Strong Name has to be created to create a shared assembly. This can be
done using SN.EXE. The same has to be registered using GACUtil.exe (Global Assembly Cache).
Satellite Assemblies : These assemblies contain resource files pertaining to a locale
(Culture+Language). These assemblies are used in deploying an Gloabl applicaiton for
different languages.

6) Is String is Value Type or Reference Type in C#?
String is an object (Reference Type). 7) What’ is the sequence in which ASP.NET events are processed?Following is the sequence in which the events occur:-• Page_Init.• Page Load.• Control events• Page- Unload event.Page_init event only occurs when first time the page is started, but Page Load occurs in
subsequent request of the page.

8) In which event are the controls fully loaded?
Page load event guarantees that all controls are fully loaded. Controls are also accessed in
Page_Init events but you will see that view state is not fully loaded during this event.

9) How can we identify that the Page is Post Back?
Page object has an “IsPostBack” property, which can be checked to know that is the page
posted back.

10) What is event bubbling?
Server controls like Data grid, Data List, and Repeater can have other child controls inside
them. Example Data Grid can have combo box inside data grid. These child control do not
raise there events by themselves, rather they pass the event to the container parent (which
can be a data grid, data list, repeater), which passed to the page as “ItemCommand” event.
As the child control send events to parent it is termed as event bubbling.

11)How do we assign page specific attributes?
Page attributes are specified using the @Page directive.

12) How do we ensure view state is not tampered?
Using the @Page directive and setting ‘EnableViewStateMac’ property to True.

13) What is the use of @ Register directives?
@Register directive informs the compiler of any custom server control added to the page.

14) What is the use of Smart Navigation property?
It’s a feature provided by ASP. NET to prevent flickering and redrawing when the page is
posted back.Note:- This is only supported for IE browser. Project is who have browser compatibility as requirements have to think some other ways of avoiding flickering.

15) What is AppSetting Section in “Web.Config” file?
Web.config file defines configuration for a web project. Using “AppSetting” section, we can
define user-defined values.
Example below defined is “Connection String” section, which will
be used through out the project for database connection.

16) Where is View State information stored?
In HTML Hidden Fields.

17) How can we create custom controls in ASP.NET?
User controls are created using .ASCX in ASP.NET. After .ASCX file is created you need to
two things in order that the ASCX can be used in project:.
• Register the ASCX control in page using the
• Now to use the above accounting footer in page you can use the below directive.

18) How many types of validation controls are provided by ASP.NET?
There are six main types of validation controls:-
RequiredFieldValidator
It checks whether the control have any value. It is used when you want the control should
not be empty.
RangeValidator
It checks if the value in validated control is in that specific range. Example
TxtCustomerCode should not be more than eight lengths.
CompareValidator
It checks that the value in controls should match some specific value. Example Textbox
TxtPie should be equal to 3.14.
RegularExpressionValidator
When we want the control, value should match with a specific regular expression.
CustomValidator
It is used to define User Defined validation.Validation SummaryIt displays summary of all current validation errors on an ASP.NET page.
Note: - It is rare that some one will ask step by step all the validation controls. Rather
they will ask for what type of validation which validator will be used. Example in one of
the interviews i was asked how will you display summary of all errors in the validation
control...just uttered one word Validation summary.

19) Can you explain “AutoPostBack”?
If we want the control to automatically post back in case of any event, we will need to
check this attribute as true. Example on a Combo Box change we need to send the event
immediately to the server side then set the “AutoPostBack” attribute to true.

20) How can you enable automatic paging in Data Grid?
Following are the points to be done in order to enable paging in Data grid:-• Set the “Allow Paging” to true.• In PageIndexChanged event set the current page index clicked.
Note: - The answers are very short, if you have implemented practically its just a revision.
If you are fresher, just make sample code using Datagrid and try to implement this functionality.

21) What is the use of “GLOBAL.ASAX” file?
It allows to execute ASP.NET application level events and setting application-level variables

22) What is the difference between “Web.config” and “Machine.Config”?
“Web.config” files apply settings to each web application, while “Machine.config” file apply
settings to all ASP.NET applications.

23) What is a SESSION and APPLICATION object?
Session object store information between HTTP requests for a particular user, while
application object are global across users.

24)Define Page..::.EnableViewStateMac Property
Gets or sets a value indicating whether ASP.NET should verify message authentication codes
(MAC) in the page's view state when the page is posted back from the client. a message authentication code (often MAC) is a short piece of information used to authenticate a message.
A MAC algorithm, sometimes called a keyed (cryptographic) hash function, accepts as input a
secret key and an arbitrary-length message to be authenticated, and outputs a MAC (sometimes known as a tag). The MAC value protects both a message's data integrity as well as its
authenticity, by allowing verifiers (who also possess the secret key) to detect any changes
to the message content.

25)Global.asax
It allows to execute ASP.NET application level events and setting application-level
variables.
The First Thing is that the file is global.asax not gobal.spx
1. this is the single file in all over the application. i.e. you can't add the file with the
same name in another location
2. it is used to set the variable or other global settings..
3. it has events fora) application startb) application endc) session startd) session starte) application errorf) application Authenticate Requestwe can use appropriate event for appropriate workThe Global.asax file, sometimes called the ASP.NET application file, provides a way to respond to application or module level events in one central location. You can use this file
to implement application security, as well as other tasks. Let's take a closer look at how
you may use it in your application development efforts.
Overview
The Global.asax file is in the root application directory. While Visual Studio .NET
automatically inserts it in all new ASP.NET projects, it's actually an optional file. It's
okay to delete it—if you aren't using it. The .asax file extension signals that it's an
application file rather than an ASP.NET file that uses aspx.
The Global.asax file is configured so that any direct HTTP request (via URL) is rejected
automatically, so users cannot download or view its contents. The ASP.NET page framework
recognizes automatically any changes that are made to the Global.asax file. The framework
reboots the application, which includes closing all browser sessions, flushes all state
information, and restarts the application domain.
Programming
The Global.asax file, which is derived from the HttpApplication class, maintains a pool of
HttpApplication objects, and assigns them to applications as needed. The Global.asax file
contains the following events:
Application_Init: Fired when an application initializes or is first called. It's invoked for
all HttpApplication object instances. Application_Disposed: Fired just before an application is destroyed. This is the ideal
location for cleaning up previously used resources. Application_Error: Fired when an unhandled exception is encountered within the application. Application_Start: Fired when the first instance of the HttpApplication class is created. It
allows you to create objects that are accessible by all HttpApplication instances. Application_End: Fired when the last instance of an HttpApplication class is destroyed. It's
fired only once during an application's lifetime. Application_BeginRequest: Fired when an application request is received. It's the first
event fired for a request, which is often a page request (URL) that a user enters. Application_EndRequest: The last event fired for an application request. Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework begins
executing an event handler like a page or Web service. Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework is finished
executing an event handler.
Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends HTTP headers to a requesting client (browser).
Application_PreSendContent: Fired before the ASP.NET page framework sends content to a
requesting client (browser).
Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current
state (Session state) related to the current request.
Application_ReleaseRequestState: Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data. Application_ResolveRequestCache: Fired when the ASP.NET page framework completes an
authorization request. It allows caching modules to serve the request from the cache, thus
bypassing handler execution.
Application_UpdateRequestCache: Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent requests.
Application_AuthenticateRequest: Fired when the security module has established the current user's identity as valid. At this point, the user's credentials have been validated. Application_AuthorizeRequest: Fired when the security module has verified that a user can access resources.
Session_Start: Fired when a new user visits the application Web site.
Session_End: Fired when a user's session times out, ends, or they leave the application Web
site. The event list may seem daunting, but it can be useful in various circumstances.
A key issue with taking advantage of the events is knowing the order in which they're
triggered.
The Application_Init and Application_Start events are fired once when the
application is first started. Likewise, the Application_Disposed and Application_End are
only fired once when the application terminates.
In addition, the session-based events (Session_Start and Session_End) are only used when users enter and leave the site. The remaining events deal with application requests, and they're triggered in the following order:
Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_ResolveRequestCache Application_AcquireRequestState Application_PreRequestHandlerExecute Application_PreSendRequestHeaders Application_PreSendRequestContent
Application_PostRequestHandlerExecute Application_ReleaseRequestState Application_UpdateRequestCache Application_EndRequest A common use of some of these events is security. The following C# example demonstrates various Global.asax events with the Application_Authenticate event used to facilitate forms-based authentication via a cookie. In addition, the Application_Start event populates an application variable, while Session_Start populates a session variable.
The Application_Error event displays a simple message stating an error has occurred.
protected void Application_Start(Object sender, EventArgs e)

{
Application["Title"] = "Builder.com Sample";}protected void Session_Start(Object sender, EventArgs e) {Session["startValue"] = 0;
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
// Extract the forms authentication cookiestring cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if(null == authCookie)
{// There is no authentication cookie.return;}FormsAuthenticationTicket authTicket = null;
try {authTicket = FormsAuthentication.Decrypt(authCookie.Value);
} catch(Exception ex)
{
// Log exception details (omitted for simplicity)return;
}
if (null == authTicket)
{
// Cookie failed to decrypt.return;
}
// When the ticket was created, the UserData property was assigned// a pipe delimited string of role names.string[2] rolesroles[0] = "One"roles[1] = "Two"// Create an Identity objectFormsIdentity id = new FormsIdentity( authTicket );// This principal will flow throughout the request.GenericPrincipal principal = new GenericPrincipal(id, roles);// Attach the new principal object to the current HttpContext objectContext.User = principal;}protected void Application_Error(Object sender, EventArgs e) {Response.Write("Error encountered.");}
This example provides a peek at the usefulness of the events contained in the Global.asax
file; it's important to realize that these events are related to the entire application.
Consequently, any methods placed in it are available through the application's code, hence
the Global name.


26)What is the difference between Server.Transfer and Response.Redirect? Why would I hoose
one over the other?

Server.Transfer transfers page processing from one page directly to the next page without
making a round-trip back to the client's browser. This provides a faster response with a
little less overhead on the server. Server.Transfer does not update the clients url history
list or current url. Response.Redirect is used to redirect the user's browser to another
page or site. This performas a trip back to the client where the client's browser is
redirected to the new page. The user's browser history list is updated to reflect the new
address.


27)Differentiate the Server side And Client side scripting?
Server side scripting(whatever the language it may be i.e. VB.NET C# ASP etc) will always
run on server side and create roundtrip on server but in case of client side scpripting it
will always run on client side(mainly used for information or control validation).As it runs
on client's brower it does not create any roundtrip to the server.Javascript is a popular
clientside scripting language.


28)what is Session?
Sessions in ASP.NET are simply hash tables in the memory with a timeout specified
Session Type What it does Example Session.Abandon Abandons (cancels) the current session. Session.Remove Delete an item from the session-state collection. Session(“username”) =
“Aayush Puri” (Initialize a session variable)
Session.Remove(“username”) (Deletes the session variable “username”) Session.RemoveAll Deletes all session state items Session.Timeout Set the timeout (in minutes) for a session Session.Timeout=30 (If a user
does NOT request a page of the ASP.NET application within 30 minutes then the session
expires.) Session.SessionID Get the session ID (read only property of a session) for the current
session. Session.IsNewSession This is to check if the visitor’s session was created with the current
request i.e. has the visitor just entered the site. The IsNewSession property is true within
the first page of the ASP.NET application.


29)Session and Application Object in ASP.Net
Sessioin object is used to store user specific data into server memory. Session["MyData"] = Store This data"; Application object is used to store application specific data into server memory. Application["MyData"] = "Global value";Session object is used to maintain the session of each user.
If one user enter in to the application then they get seesion id if he leaves from the application then the session id is deleted.
If they again enter in to the application they get different session id.But for application object the id is maintained for whole application.it doesn't differ for any userSession variables are used to store user specific information where as in application variables we can't store user specific information.Default lifetime of the session variable is 20 mins and based on the requirement we can
change it.
Application variables are accessible till the application ends.sessions allows information to be stored in one page and accessed in another,and it supports
any type of object,including your own custom data types.
Application state allows you to store global objects that can be accessed by any client.
The coomon thing b/w session and application is both support the same type of objects,retain
information on the server, and uses the same dictionary -based syntax.


30)What are the features of SmartNavigation property are namely:
1. Maintaining element focus between post backs:
When a post back occurs, the active control on the Web page loses its focus. When a keyboard
is used for navigation the users has to press the Tab key several times to return to their
original position of data entry. However, when smart navigation is enabled information about
the active control is maintained between post backs to the server.
2. Eliminate page flash caused by page post back
3. Prevents each post back from being saved in the browser history: Normally, every post
back to an ASP.NET page causes an entry to be created in the browser's history. This defeats
the purpose of the browser's back button because instead of going back to the previous page,
users are taken to the previous state of the current page. Smart navigation prevents this
from happening by saving only the latest state of the current page to be saved in the
browser's history.
To set this property of SmartNavigation in ASP.NET one has to set the smartNavigation
property of their ASPX page to True. It is also possible to set this property of
SmartNavigation to all their pages in the application by using the pages tag in the
Web.config file.


31) Web.config fileWeb.config file is to override the settings from the machine.config file. machine.config
file settings are applied to all the webapplications residing on the server while web.config
settings are application specific.


32)Difference between an abstract method & virtual method:
Virtual method has an implementation & provide the derived class with the option of
overriding it. Abstract method does not provide an implementation & forces the derived class
to override the method.


33)What is an Abstract class?
An abstract class only allows other classes to inherit from it and cannot be instantiated.
When we create an abstract class, it should have one or more completed methods but at least
one or more uncompleted methods and these must be preceded by the key word abstract. If all
the methods of an abstract class are uncompleted then it is the same as an interface, but
there is a restriction that it cannot make a class inherit from it, which means it can not
work as a base class.
34)What is an Interface?
An interface is defined by the key word interface. An interface has no implementation; it
only has the definition of the methods without the body. When we create an interface, we are
basically creating a set of methods without any implementation. A class implementing an
interface must provide the implementation of the interface members. All the methods and
properties defined in an interface are by default public and abstract.
35)Abstract Class vs. Interface
· An abstract class may contain complete or incomplete methods. Interfaces can contain only
the signature of a method but no body. Thus an abstract class can implement methods but an
interface can not implement methods.
· An abstract class can contain fields, constructors, or destructors and implement
properties. An interface can not contain fields, constructors, or destructors and it has
only the property's signature but no implementation.
· An abstract class cannot support multiple inheritance, but an interface can support
multiple inheritance. Thus a class may inherit several interfaces but only one abstract
class.
· A class implementing an interface has to implement all the methods of the interface, but
the same is not required in the case of an abstract Class.
· Various access modifiers such as abstract, protected, internal, public, virtual, etc. are
useful in abstract Classes but not in interfaces.
· Abstract classes are faster than interfaces.
36)Define Ploymorphism Through inheritance, a class can be used as more than one type; it can be used as its own
type, any base types, or any interface type if it implements interfaces. This is called
polymorphism.
In other words, the base class object reference variable can do different things(example
invoke different methods) depending on the child class object the reference variable is
pointing to;37)What are the Types of Ploymorphism Compile Time Polymorphism Compile time polymorphism is 1.method overloading. (functions names are same arguments are different) 2.operators overloading It is also called early binding. In method overloading method performs the different task at the different input parameters. Examples:Compile time polymorphismPractical example of Method Overloading (Compile Time Polymorphism) using System; namespace method_overloading { class Program { public class Print { public void display(string name) { Console.WriteLine("Your name is : " + name); } public void display(int age, float marks) { Console.WriteLine("Your age is : " + age); Console.WriteLine("Your marks are :" + marks); } } static void Main(string[] args) { Print obj = new Print(); obj.display("George"); obj.display(34, 76.50f); Console.ReadLine(); } } }
Runtime Time PolymorphismRuntime time polymorphism is done using inheritance and virtual functions. Method overriding
is called runtime polymorphism. It is also called late binding. When overriding a method, you change the behavior of the method for the derived class.
Overloading a method simply involves having another method with the same prototype.
Examples Runtime polymorphisamusing System;public class Customer{public virtual void CustomerType(){Console.WriteLine("I am a customer");}}public class CorporateCustomer : Customer{public override void CustomerType(){Console.WriteLine("I am a corporate customer");}}public class PersonalCustomer : Customer{public override void CustomerType(){Console.WriteLine("I am a personal customer");}}public class MainClass{public static void Main(){Customer[] C = new Customer[3];C[0] = new CorporateCustomer();C[1] = new PersonalCustomer();C[2] = new Customer();foreach (Customer CustomerObject in C){CustomerObject.CustomerType();}}}we are assigning a new CorporateCustomer object and new PersonalCustomer object to a
reference variable of type Customer. This is possible as the classes are related by
inheritance and we know a parent class reference variable can point to a child class object.C[0] = new CorporateCustomer(); C[1] = new PersonalCustomer(); C[2] = new Customer();Advantages:code reuse, maintainability, androbustness
38)When and why to use method overloading
Use method overloading in situation where you want a class to be able to do something, but
there is more than one possibility for what information is supplied to the method that
carries out the task. You should consider overloading a method when you for some reason need a couple of methods
that take different parameters, but conceptually do the same thing.
39)Define:Operator OverloadingAll unary and binary operators have pre-defined implementations, that are automatically
available in any expressions. In addition to this pre-defined implementations, user defined
implementations can also be introduced in C#. The mechanism of giving a special meaning to a
standard C# operator with respect to a user defined data type such as classes or structures
is known as operator overloading. Remember that it is not possible to overload all operators
in C#.

1.unary operator loading
class complex
{
private int x; private int y;
public complex()
{
}
public complex(int i, int j) { x = i; y = j;
}
public void show()
{
Console.WriteLine(x); Console.WriteLine(y);
}

public static complex operator -(complex c)
{
complex temp = new complex(); temp.x = -c.x; temp.y = -c.y; return temp; }
}
class MyClient

{
public static void Main(string[] args)
{
complex c1 = new complex(10, 20);
c1.show();
// displays 10 & 20
complex c2 = new complex();
c2.show(); // displays 0 & 0 c2 = -c1; c2.show();
// diapls -10 & -20
Console.ReadLine();
}
}
2.binary operator loading

public class binaryoperatoroverloading
{
int x; int y; public binaryoperatoroverloading()
{
}

public binaryoperatoroverloading(int i, int j) { x = i; y = j;
}
public void showinputs()
{
Console.WriteLine(x); Console.WriteLine(y);
}
public static binaryoperatoroverloading operator +(binaryoperatoroverloading c1,
binaryoperatoroverloading c2)

{
binaryoperatoroverloading objtemp = new binaryoperatoroverloading();
objtemp.x = c1.x + c2.x; objtemp.y = c1.y + c2.y; return objtemp;
}

} public class mainclass {
public static void Main()
{
binaryoperatoroverloading objbinaryoperatoroverloading = new
binaryoperatoroverloading(10, 20); objbinaryoperatoroverloading.showinputs(); binaryoperatoroverloading objbinaryoperatoroverloading1 = new
binaryoperatoroverloading(20, 30); objbinaryoperatoroverloading1.showinputs();
binaryoperatoroverloading objbinaryoperatoroverloading3 = new
binaryoperatoroverloading(20, 30); objbinaryoperatoroverloading3 = objbinaryoperatoroverloading +
objbinaryoperatoroverloading1; objbinaryoperatoroverloading3.showinputs(); Console.ReadLine(); }

}
output:10 2020303050





No comments:

Post a Comment

Your Ad Here
Your Ad Here