जगदीश खोलिया: Asp.Net Basics

Wednesday, June 15, 2011

Asp.Net Basics

1. Explain the life cycle of an ASP .NET page.?

Following are the events occur during ASP.NET Page Life Cycle:



1)Page_PreInit

2)Page_Init

3)Page_InitComplete

4)Page_PreLoad

5)Page_Load

6)Control Events

7)Page_LoadComplete

8)Page_PreRender

9)SaveViewState

10)Page_Render

11)Page_Unload



Among above events Page_Render is the only event which is raised by page. So we can't write code for this event.



2. how does the cookies work in asp.net?

we know Http is an state-less protocol which is required for interaction between clinet and server .



so there is an need to remeber state of request raised by an web browser so that 

web server can recognize you have already previously visited or not.



There are two types of state management techniques:

a) Client side state management

b) Server - side statemanagement



Using cookies comes under clinet side statemanagement .In HttpResponse we write 

Cookie containing sessionId and other information within it.



when a browser made a request to the web server the same cookie is sent
to the server where server recognize the session id and get other
information stored to it previously.



3. What is Ispostback method in ASP.Net? Why do we use that??


Basically Post back is an action performed by a interactive Webpage.
When it goes to the server side for a non-client Operation Server again
posts it back to the client and hence the name.

Ex:



if(!IsPostBack)



will not allow the page to post back again n again bcoz it reduces the performance.



4. Can User Control be stored in library?.

I will say "NO"



there are 3 types of controls:

1) User Control

2) Custom Control

3) Web parts



you can reuse User control in the current project in which you have
built it, but you can't move it to other project as unless you just copy
paste the same file there and make the changes for that project ( which
violets the concept of library).



but custom control can be shared between projects. and you can
precompile them even as a dll, so this means you can use them in library
of any type.



5. what is the difference between application state and caching?

Application Object and Cached Object both falls under Server side State Management.



Application object resides in InProc i.e. on the same server where we hosted our application.

Cache Object resides on server side/ DownStream/Client Side.



Application Object will be disposed once application will stop.

Cache Object can be disposed using Time based cache dependency.



Only one user can access Application Object at a time hence we have to lock it every time we modify it.



6. what is boxing and unboxing?

Boxing is what happens when a value-type object is assigned to a reference-type variable.

Unboxing is what happens when a reference-type variable is assigned to a value-type variable.






7. What are the uses of Reflection??

Reflection is a concept using which we can 



1) Load assemblies dynamically

2) Invoke methods at runtime

3) Retriving type information at runtime.



8. What is the use of AutoWireup in asp.net?

AutoEventWireup attribute is used to set whether the events needs to be automatically generated or not.

In the case where AutoEventWireup attribute is set to false (by default)
event handlers are automatically required for Page_Load or Page_Init.
However when we set the value of the AutoEventWireup attribute to true
the ASP.NET runtime does not require events to specify event handlers
like Page_Load or Page_Init.



9. what events will occur when a page is loaded?

Below are the events occures during page load.



1) Page_PreInit

2) Page_Init

3) Page_InitComplete

4) Page_PreLoad



10. Where is the View state Data stored?

ViewState data is stored in the hidden field. When the page is submitted
to the server the data is sent to the server in the form of hidden
fields for each control. If th viewstate of the control is enable true
the value is retained on the post back to the client when the page is
post backed.



11. What is the difference between custom web user control and a custom web server control?

Web User Control:

1) Easy to Create.

2) It Can be used inside the same Application.(To use it in other application we need to add it to that project.)

3) It Can take advantage of Caching Technique.



Web Server Control:

1) Bit tuff to create as compare to User Control.

2) Easy to use.

3) Can be added to ToolBox.



12. Where do the Cookie State and Session State information be stored?

Cookie Information will be stored in a txt file on client system under a 

folder named Cookies. Search for it in your system you will find it.


Coming to Session State

As we know for every process some default space will be allocated by OS.


In case of InProc Session Info will be stored inside the process where our 

application is running.

In case of StateServer Session Info will be stored using ASP.NET State Service.

In case of SQLServer Session info will be stored inside Database. Default DB 

which will be created after running InstallSQLState Script is ASPState.


13. What is the difference between adding reference in solution Explorer and adding references by USING
?


Adding reference in solution explorer is
used to add the DLL for that project for reference only. If you want to
utilize that DLL methods/functions in our aspx.cs/.cs file etc you must
write using that nameclass library name in file.




14. What are the different types of sessions in ASP.Net? Name them.?

Session Management can be achieved in two ways



1)InProc

2)OutProc



OutProc is again two types

1)State Server

2)SQL Server



InProc

Adv.:

1) Faster as session resides in the same process as the application

2) No need to serialize the data


DisAdv.:

1) Will degrade the performance of the application if large chunk of data is stored

2) On restart of IIS all the Session info will be lost


State Server

Adv.:

1) Faster then SQL Server session management 

2) Safer then InProc. As IIS restart 

won't effect the session data


DisAdv.:

1) Data need to be serialized

2) On restart of ASP.NET State Service session info will be lost

3)Slower as compared to InProc


SQL Server

Adv.:

1) Reliable and Durable

2) IIS and ASP.NET State Service 

restart won't effect the session data

3) Good place for storing large chunk of data


DisAdv.:

1) Data need to be serialized

2) Slower as compare to InProc and State Server

3)Need to purchase Licensed 

version of SQL Serve


15. How do you design a website with multilingual support in ASP.NET?

Multilingual website can be created using Globalization and Localization.


Using Globalization we change the Currency Date Numbers etc to Language Specific Format.


To change the string which is there in the label button etc to language specific string we use Localization.


In Localization we have to create different Resource files for different languages.

During this process we use some classes present in System.Resources System.Globalization System.Threading namespaces.

16. What is caching? What are different ways of caching in ASP.NET?

Caching is a technique of persisting the data in memory for immediate
access to requesting program calls. This is considered as the best way
to enhance the performance of the application.



Caching is of 3 types:


Output Caching - Caches the whole page.

Fragment Caching - Caches a part of the page

Data Caching - Caches the data



17. What is meant by 3-tier architecture.

We generally split our application into 3-Layers

1)Presentation Layer ( Where we keep all web forms Master Pages and User Controls).

2)Business Layer (Where we keep business logic). e.g
Code related to manipulating data Custom Exception classes Custom
Control classes Login related code if any etc. etc.

3)Data Access Layer (Where we keep code used to
interact with DB). e.g. We can have the methods which are using SQL
Helper (Application Block).


18. Explain the basic functionality of garbage collector?

Garbage Collector in .Net Framework is used for Automatic Memory
Management i.e. it is collect all unused memory area and give to
application. system.gc.collect() is a method for release the memory. But
remember one think it is only an request i.e. we can't explicitly
release the memory by using system.gc.collect().


19. What is the difference between mechine.config and web.config?

machine.config is a system level configuration i.e it is applied on
all application in o/s that the configuration is set where as in
web.config it is applicable to only one application i.e each asp.net
webapplication will contain atleast on web.config file.


20. How can exception be handled with out the use of try catch?

using Exception Management application block


or

Page_error

Application_error objects


21. What is the difference between Response.Redirect and Server.Transfer.

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 toredirect the
user's browser to another page or site. This performs 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.


22. Where the assembly is stored in asp.net?.

private are stored in application / bin directory and public are stored in GAC.


23. How we implement Web farm and Web Garden concept in ASP.NET?.

A web farm is a multi-server scenario. So we may have a server
in each state of US. If the load on one server is in excess then the
other servers step in to bear the brunt.

How they bear it is based on various models.

1. RoundRobin. (All servers share load equally)

2. NLB (economical)

3. HLB (expensive but can scale up to 8192 servers)

4. Hybrid (of 2 and 3).

5. CLB (Component load balancer).

A web garden is a multi-processor setup. i.e. a single server (not like the multi server above).

How to implement webfarms in .Net:

Go to web.config and

Here for mode you have 4 options.

a) Say mode inproc (non web farm but fast when you have very few customers).

b) Say mode StateServer (for webfarm)

c) Say mode SqlServer (for webfarm)

Whether to use option b or c depends on situation. StateServer
is faster but SqlServer is more reliable and used for mission critical
applications.

How to use webgardens in .Net:

Go to web.config and

Change the false to true. You have one more attribute that is related to webgarden in the same tag called cpuMask.


24. Is there any limit for query string? means what is the maximum size?..

Servers should be cautious about depending on URI lengths above 255
bytes because some older client or proxy implementations may not
properly support these lengths.


Query string length depends on browser compatability 



IE supports upto 255

Firefox supports upto 4000


25. What is the exact purpose of http handlers?

ASP.NET maps HTTP requests to HttpHandlers. Each HttpHandler
enables processing of individual HTTP URLs or groups of URL extensions
within an application. HttpHandlers have the same functionality as ISAPI
extensions with a much simpler programming model


Ex

1.Default HttpHandler for all ASP.NET pages ->ASP.NET Page Handler (*.aspx)

2.Default HttpHandler for all ASP.NET service pages->ASP.NET Service Handler (*.asmx)


An HttpHandler can be either synchronous or asynchronous. A
synchronous handler does not return until it finishes processing the
HTTP request for which it is called. An asynchronous handler usually
launches a process that can be lengthy and returns before that process
finishes

After writing and compiling the code to implement an
HttpHandler you must register the handler using your application's
Web.config file.

No comments: