Sunday, 26 January 2014

ASP.NET Interview Questions

  ca-pub-9335363476709499

1) What is a view state?Can Dataset be stored in view state?Does datagrid has a view state?

ViewState is a mechanism to maintain state in ASP.net pages. HTTP is a stateless protocol. So we can maintain state either on server or client using sessions, cookies, hidden variables, URL, etc.
ViewState is a hidden field maintained by ASP.Net to contain page data.
Yes, Dataset can also be stored in ViewState but this is not recommended due to overhead of managing a bulk data in ViewState.

2) What is the difference between Session and Cookies.

As far as my knowledge is concerned, cookies are stored on client side where as sessions are server variables. The storage limitations are also there (like IE restricts the size of cookie to be not more than 4096 bytes). We can store only a string value in a cookie where as objects can be stored in session variables. The client will have to accept the cookies in order to use cookies, there is no need of user's approval or confirmation to use Session variables cos they are stored on server. The other aspect of this issue is cookies can be stored as long as we want(even for life time) if the user accepts them, but with session variables we can only store something in it as long as the session is not timed out or the browser window is not closed which ever occurs first.

3) Asp.net page life cycle
  •  Init() - when the page is instantiated
  • Load() - when the page is loaded into server memory
  • PreRender() - the brief moment before the page is displayed to the user as HTML
  • Unload() - when page finishes loading. 

4) Is there any difference between Form Post and PostBack.If yes What is the difference? 
When you POST a form you specify the location where the form data will be sent to be processed. It can be the same page or a different page. This is determined by the value of the ACTION attribute of the FORM tag. POSTBACK posts the data back to the same page and processed.

5) Is there any limit for query string? if means what is the maximum size?

255 bytes

6) What is the difference between web.config and machine.config ? 

Every ASP.NET application that you has a web.config file . The settings specified in this will imply only to that application.Whereas Your System will have a machine.config file in Microsoft.NETFrameworkv1.1.4322CONFIG Folder which contains specifications and settings at a system level.
Machine.config is a system level configuration i.e it is applied on all application in o/s that the configuration is set.
Web.config is applicable to only one application i.e each asp.net web application will contain at least one web.config file.

7) What is .net?

.net is language independent platform.or framework.provide assemblies ,tools to build dynamic application.
.NET is an Application development framework for internet application.

8) What is the maximum number of cookies that can be allowed to a web site?

Maximum number of cookies allowed is 300.

9) How does VB.NET/C# achieve polymorphism?

By using Abstract classes/functions.

10) Define state management?

A new instance of the Web page class is created each time the page is posted to the server. In traditional Web programming, this would typically mean that all information associated with the page and the controls on the page would be lost with each round trip. For example, if a user enters information into a text box, that information would be lost in the round trip from the browser or client device to the server.

To overcome this inherent limitation of traditional Web programming, ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows:
View state
Control state
Hidden fields
Cookies
Query strings
Application state
Session state
Profile Properties


Client-side state management

This maintains information on the client's machine using Cookies, View State, and Query Strings.

Cookies.

A cookie is a small text file on the client machine either in the client's file system or memory of client browser session. Cookies are not good for sensitive data. Moreover, Cookies can be disabled on the browser. Thus, you can't rely on cookies for state management.

View State

Each page and each control on the page has View State property. This property allows automatic retention of page and controls state between each trip to server. This means control value is maintained between page postbacks. Viewstate is implemented using _VIEWSTATE, a hidden form field which gets created automatically on each page. You can't transmit data to other page using view state. 

Querystring

Querystring can maintain limited state information. Data can be passed from one page to another with the URL but you can send limited size of data with the URL. Most browsers allow a limit of 255 characters on URL length.

Server-side state management

This kind of mechanism retains state in the server.

Application State

The data stored in an application object can be shared by all the sessions of the application. The application object stores data in the key value pair. 

Session State

Session state stores session-specific information and the information is visible within the session only. ASP.NET creates unique sessionId for each session of the application. SessionIDs are maintained either by an HTTP cookie or a modified URL, as set in the application's configuration settings. By default, SessionID values are stored in a cookie. 

Database

Database can be used to store large state information. Database support is used in combination with cookies or session state.


11) What base class do all Web Forms inherit from?

System.Web.UI.Page

12) What is the difference between boxing and unboxing ?
 
Boxing allows us to convert value types to reference types. Basically, the runtime creates a temporary reference-type box for the object on heap.
Eg: int i=20; object o=i;


13) What is the difference between an EXE and a DLL?

An EXE can run independently, whereas DLL will run within an EXE. DLL is an in-process file and EXE is an out-process file


14) What do you mean by authentication and authorization?
Authentication is the process of obtaining some sort of credentials from the users and using those credentials to verify the user's identity. Authorization is the process of allowing an authenticated user access to resources.
An ASP.net application has two separate authentication layers. That is because ASP.net is not a standalone product. Rather it is a layer on top of IIS. All requests flow through IIS before they are handed to ASP.net. As a result, IIS can decide to deny access without the ASP.net process even knowing that someone requested a particular page. Here is an overview of the steps in the joint IIS and ASP.net authentication process.
  1. IIS first checks to make sure the incoming request comes from an IP address that is allowed access to the domain. If not it denies the request.
  2. Next IIS performs its own user authentication if it configured to do so. By default IIS allows anonymous access, so requests are automatically authenticated, but you can change this default on a per - application basis with in IIS.
  3. If the request is passed to ASP.net with an authenticated user, ASP.net checks to see whether impersonation is enabled. If impersonation is enabled, ASP.net acts as though it were the authenticated user. If not ASP.net acts with its own configured account.
  4. Finally the identity from step 3 is used to request resources from the operating system. If ASP.net authentication can obtain all the necessary resources it grants the users request otherwise it is denied. Resources can include much more than just the ASP.net page itself you can also use .Net's code access security features to extend this authorization step to disk files, Registry keys and other resources.
As you can see several security authorities interact when the user requests and ASP.net page. If things are not behaving the way you think they should, it can be helpful to review this list and make sure you have considered all the factors involved

Authentication providers

Assuming IIS passes a request to ASP.net, what happens next? The answer depends on the configuration of ASP.net itself. The ASP.net architecture includes the concept of and authentication provider a piece of code whose job is to verify credentials and decide whether a particular request should be considered authenticated. Out of the box ASP.net gives you a choice of three different authentication providers.
  • The windows Authentication provider lets you authenticates users based on their windows accounts. This provider uses IIS to perform the authentication and then passes the authenticated identity to your code. This is the default provided for ASP.net.
  • The passport authentication provider uses Microsoft's passport service to authenticate users.
  • The forms authentication provider uses custom HTML forms to collect authentication information and lets you use your own logic to authenticate users. The user's credentials are stored in a cookie for use during the session.

15) ASP.NET application life cycle and events processing

A web application starts when a browser requests a page of the application first time. The request is received by the IIS which then starts ASP.NET worker process (aspnet_wp.exe). The worker process then allocates a process space to the assembly and loads it. An application_start event occurs followed by Session_start. The request is then processed by the ASP.NET engine and sends back response in the form of HTML. The user receives the response in the form of page.

The page submitting triggers postback event that causes the browser to send the page data, also called as view state to the server. When server receives view state, it creates new instance of the web form. The data is then restored from the view state to the control of the web form in Page_Init event.
The data in the control is then available in the Page_load event of the web form. The cached event is then handled and finally the event that caused the postback is processed. The web form is then destroyed. When the user stops using the application, Session_end event occurs and session ends. The default session time is 20 minutes. The application ends when no user accessing the application and this triggers Application_End event. Finally all the resources of the application are reclaimed by the Garbage collector. 


16) Explain the .Net Framework.

  The .Net framework allows infrastructural services to all the applications developed in .net compliant language. It is an engine that provides runtime services using its component like Common Runtime Language. It consists of two main components such as Common Language Runtime and Framework Class Library.
  

17) Describe the .Net Framework Architecture. 

 The .Net Framework has two main components:
.Net Framework Class Library: It provides common types such as data types and object types that can be shared by all .Net compliant language.
The Common language Runtime: It provides services like code execution, type safety, security, thread management, interoperability services.

18) Explain the role of assembly in the .Net Framework.

 .Net Framework keeps executable code or DLL in the form of assembly. .Net Framework maintains multiple versions of the application in the system through assembly. The assemblies have MSIL code and manifest that contains metadata. The metadata contains version information of the assembly. 

19) Describe the GAC in the .Net Framework. 

.Net Framework provides Global Assembly cache, a machine-wide cache. It stores shared assemblies that can be accessed by multiple languages.

20) Define Session, SessionId and Session State in ASP.NET.

A session is the duration of connectivity between a client and a server application.
SessionId is used to identify request from the browser. By default, value of SessionId is stored in a cookie. You can configure the application to store SessionId in the URL for a "cookieless" session. 

21)  What is Session Identifier?

Session Identifier is used to identify session. It has SessionID property. When a page is requested, browser sends a cookie with a session identifier. This identifier is used by the web server to determine if it belongs to an existing session. If not, a Session ID (120 - bit string) is generated by the web server and sent along with the response. 

22) Advantages and disadvantages of using Session State.

The advantages of using session state are as follows:

It is easy to implement.
It ensures data durability, since session state retains data even if ASP.NET work process restarts as data in Session State is stored in other process space.
It works in the multi-process configuration, thus ensures platform scalability.

The disadvantages of using session state are:

Since data in session state is stored in server memory, it is not advisable to use session state when working with large sum of data. Session state variable stays in memory until you destroy it, so too many variables in the memory effect performance.

23)  What are the Session State Modes? Define each Session State mode supported by ASP.NET.

ASP.NET supports three Session State modes.
  • InProc
  • State Server
  • SQL Server
InProc Mode
This mode stores the session data in the ASP.NET worker process.
This is the fastest among all of the storage modes.
This mode effects performance if the amount of data to be stored is large.
If ASP.NET worker process recycles or application domain restarts, the session state will be lost. 

State Server mode
In this mode, the session state is serialized and stored in memory in a separate process.
State Server can be maintained on a different system.
State Server mode involves overhead since it requires serialization and de-serialization of objects.
State Server mode is slower than InProc mode as this stores data in an external process.

SQL Server Mode
In this storage mode, the Session data is serialized and stored in a database table in the SQL Server database.
This is reliable and secures storage of a session state.
This mode can be used in the web farms.
It involves overhead in serialization and de-serialization of the objects.
SQL Server is more secure than the InProc or the State server mode.

24) Define Caching in ASP.NET.

Caching technique allows to store/cache page output or application data on the client. The cached information is used to serve subsequent requests that avoid the overhead of recreating the same information. This enhances performance when same information is requested many times by the user.  

25)Advantages of Caching

It increases performance of the application by serving user with cached output.
It decreases server round trips for fetching data from database by persisting data in the memory.
It greatly reduces overhead from server resources.

26) What are the types of Caching in ASP.NET?

Caching in ASP.NET can be of the following types
Page Output Caching
Page Fragment Caching
Data Caching

27) Explain in brief each kind of caching in ASP.NET.

Page Output Caching

This type of caching is implemented by placing OutputCache directive at the top of the .aspx page at design time.
For example:
<%@OutputCache Duration= "30" VaryByParam= "DepartmentId"%>

The duration parameter specifies for how long the page would be in cache and the VaryByParam parameter is used to cache different version of the page.
The VaryByParam parameter is useful when we require caching a page based on certain criteria.

Page Fragment Caching

This technique is used to store part of a Web form response in memory by caching a user control.

Data Caching

Data Caching is implemented by using Cache object to store and quick retrieval of application data.
Cache object is just like application object which can be access anywhere in the application.
The lifetime of the cache is equivalent to the lifetime of the application.



28)Define .Net Assembly.

It is a primary unit of deployment in a Microsoft .NET Framework application. It is called as building block of an application which provides all required execution information to common language runtime.

An assembly perform following functions:
 
It contains IL code that gets executed by common language runtime.
It forms a security boundary.
An assembly is the unit at which permissions are requested and granted.
It ensures type safety by establishing name scope for types at the runtime.
It contains version information.
It allows side-by-side execution of multiple versions of same assembly.

Assemblies can be static or dynamic. 
 
Static assemblies are created when the program is compiled using .Net compiler. It exists as PE file either in .exe or .dll. However, dynamic assemblies are created at runtime and run from the memory without getting saved on the disk.

29)What does an assembly contain?

An assembly contains following information:
Assembly manifest: Information about the assembly.
Type metadata: Information about the types.
IL Code
Resource files.
An assembly manifest contains the following information:
Identity of the assembly
Types and resources
Files
Security permissions 

30)Define private assembly and a shared assembly.

A private assembly is stored in the application’s directory and used by a single application. A share assembly can be used by multiple applications and is stored in the Global assembly cache, a repository of assemblies maintained by the .Net Framework.

31)What are Satellite Assemblies?

Satellite assemblies provide an application the multilingual support. Satellite assemblies contain alternate sets of resources to be used in the application for different cultures.

32)What do you understand by side-by-site execution of assembly?

This means multiple version of same assembly to run on the same computer. This feature enables to deploy multiple versions of the component.

33)How do you create a resource-only assembly?

Resources are nonexecutable data in an application and the data can be updated without recompiling application. Resource assemblies can be created as follows:
Add resource files to an empty project.
Built the project.
The resource will get compiled into assembly.

34)Explain how to retrieve resources using ResourceManager class.

ResourceManager class is used to retrieve resources at run time.
Create a ResourceManager with resource file name and the resource assembly as parameters.
After having created, you can use ResourceManager.GetString method to retrieve a string.
Use the ResourceManager.GetObject method to retrieve images and objects from a resource file.  

35)Define Strong Name. How do you apply a strong name to assembly?

A strong name means generating public key in order to provide unique name to the assembly.
The name is used to provide global name to the assembly and allows it to be shared amongst several different applications.
The key generated include assembly's name, the version number, the developer's identity, and a hash number.
The developer's identity identifies the author of the assembly.
The hash checks if the assembly is tempered since it is created.
The key pair that defines the strong name is created using the Strong Name utility, Sn.exe.
To sign an assembly with a strong name
Create Key pair using the Strong Name utility, Sn.exe.
Open the AssemblyInfo file of your project.
Use the AssemblyKeyFileAttribute to specify the path to the key file for your project.
Build your assembly. The strong name will be generated and signed to the assembly.

36)Define Global Assembly Cache. 

Global Assembly Cache is the place holder for shared assembly. If an assembly is installed to the Global Assembly Cache, the assembly can be accessed by multiple applications. In order to install an assembly to the GAC, the assembly must have to be signed with strong name.

37)How do you install assembly to the Global Assembly Cache?

Followings are the steps to install assembly to the GAC.
Sign assembly with a strong name using strong name utility, sn.exe.
Open the AssemblyInfo file for your project.
Use the AssemblyKeyFileAttribute to specify the path to the key file for your project.
Build your assembly. Install the assembly to GAC by using gacutil utility e.g. gacutil -i abc.dll


38)What is "Microsoft Intermediate Language" (MSIL)?
 
A .NET programming language (C#, VB.NET, J# etc.) does not compile into executable code; instead it compiles into an intermediate code called Microsoft Intermediate Language (MSIL). As a programmer one need not worry about the syntax of MSIL - since our source code in automatically converted to MSIL. The MSIL code is then send to the CLR (Common Language Runtime) that converts the code to machine language, which is, then run on the host machine. MSIL is similar to Java Byte code. MSIL is the CPU-independent instruction set into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing, and calling methods on objects. Combined with metadata and the common type system, MSIL allows for true cross- language integration Prior to execution, MSIL is converted to machine code. It is not interpreted.



39) Define namespace.

Namespaces are the way to organize programming code. It removes the chances of name conflict. It is quite possible to have one name for an item accidentally in large projects those results into conflict. By organizing your code into namespaces, you reduce the chance of these conflicts. You can create namespaces by enclosing a class in a Namespace...End Namespace block.

You can use namespaces outside your project by referring them using References dialog box. You can use Imports or using statement to the code file to access members of the namespaces in code.



40) What are the validation controls available in ASP.NET?


ASP.NET validation controls are:

RequiredFieldValidator: This validates controls if controls contain data.

CompareValidator: This allows checking if data of one control match with other control.

RangeValidator: This verifies if entered data is between two values.

RegularExpressionValidator: This checks if entered data matches a specific format.

CustomValidator: Validate the data entered using a client-side script or a server-side code.

ValidationSummary: This allows developer to display errors in one place.


41) What is delegate?


A delegate acts like a strongly type function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods. It is type safe since it holds reference of only those methods that match its signature. Unlike other classes, the delegate class has a signature. Delegates are used to implement event programming model in .NET application. Delegates enable the methods that listen for an event, to be abstract.


42) What is  Tracing.

Tracing is the way to maintain events in an application. It is useful while the application is in debugging or in the testing phase. The trace class in the code is used to diagnose problem. You can use trace messages to your project to monitor events in the released version of the application. The trace class is found in the System.Diagnostics namespace. ASP.NET introduces tracing that enables you to write debug statements in your code, which still remain in the code even after when it is deployed to production servers.


43) What is application domain?

It is the process space within which ASP.NET application runs. Every application has its own process space which isolates it from other application. If one of the application domains throws error it does not affect the other application domains.


44) What is the use of Web.config file?

Database connections
Error Page setting
Session States
Error Handling
Security
Trace setting
Culture specific setting

45) Can you explain how to sign out in forms authentication?

FormsAuthentication.SignOut()

46) What are namespaces provided by .NET for data management?

System.data
System.data.oledb
System.data.sqlclient
System.xml


47)Can you explain the importance of Web.config?

It applies settings to each web application.


48)Explain the difference between dataset and datareader.

-Datareader provides forward-only and read-only access to data
-Dataset object can hold more than one table from the same data sources as well as the relationships between them.
-Dataset is a disconnected architecture
-Dataset cab persist contents while datareader cannot persist contents


49 What are the ways of authentication technique in ASP.NET?

Windows authentication
Passport authentication
Forms authentication


50) How to format data inside DataGrid.

By using DataFormatString property


51) Tell me which method to customize columns in DataGrid.

Template column


52 ) How do we force validation control to run?

Page.Validate


53) Can we disable client side script in validation?

Yes, set EnableClient script to false


54) What are different IIS isolation levels?

LOW (IIS process)
Medium (Pooled)
High (Isolated)

55)How to assign page specific attributes.

By using @Page directive


56) Where is ViewState information stored?

HTML hidden fields

57) What are different types of JIT?

-Pre-JIT, Econo-JIT, Normal-JIT


58) How can we perform transactions in .NET?

-Open a database connection using open method of the connection object.
-Begin a transaction using the Begin Transaction method of the connection object.
-Execute the SQL commands using the command object.
-Commit or roll back the transaction using the commit or rollback method of the transaction object.
-Close the database connection.


59) What is reflection?

-Reflection is used to browse through the metadata information.
-Using reflection you can dynamically invoke methods using system.Type.Invokemember


60) Which class does the remote object has to inherit?

System.MarchalByRefObject


61) What are the different kinds of marshalling?

Marshal-by-value
Marshal-by-reference

62) Explain about Query String and its benefits and limitations.

It is information sent to the server appended to the end of a page URL.

Benefits of query string:

No server resources are required.
The query string containing in the HTTP requests for a specific URL.
All browsers support query strings.

Following are limitations of query string

Query string data is directly visible to user thus leading to security problems.-
Most browsers and client devices impose a 255-character limit on URL length.

63) What is .NET Remoting?

.NET remoting is replacement of DCOM.
You can make remote object calls, which are in different Application Domains.
The client uses a proxy to make remote object calls, which looks like a real object.
Client Channel communicates with Server Channel.
Server Channel uses as formatter to deserialize the message and sends to the remote object.
 

No comments:

Post a Comment