Advertuse

Search This Blog

Your Ad Here

Sunday, 15 May 2011

Difference b/w ASP.NET Webform and ASP.NET MVC

ASP.NET webfrom and ASP.NET MVC are two flavor of ASP.NET application development methodology provided by Microsoft. There are few similarity in both due to same platform but has many dissimilarity which one needs to understand to adopt ASP.NET MVC who previously worked with ASP.NET Webform technology.


ASP.NET WebForms
ASP.NET MVC
Uses the ‘Page Controller’ pattern. Each page has a code-behind class that acts as a controller and is responsible for rendering the layout.
Uses the ‘Front Controller’ pattern. There is a single central controller for all pages to process web application requests and facilitates a rich routing architecture
Uses an architecture that combines the Controller (code behind) and the View (.aspx). Thus the Controller has a dependency on the View. Due to this, testing and maintainability becomes an issue.
ASP.NET MVC enforces a "separation of concerns". The Model does not know anything about the View. The View does not know there’s a Controller. This makes MVC applications easier to test and maintain
The View is called before the Controller.
Controller renders View based on actions as a result of the User Interactions on the UI.
At its core, you ‘cannot’ test your controller without instantiating a View. There are ways to get around it using tools.
At its core, ASP.NET MVC was designed to make test-driven development easier. You ‘can’ test your Controller without instantiating a View and carry out unit-tests without having to run the controllers in an ASP.NET process.
WebForms manage state by using view state and server-based controls.
ASP.NET MVC does not maintain state information by using view state
WebForms supports an event-driven programming style that is like Windows applications and is abstracted from the user. The State management is made transparent by using sessions, viewstate etc. In the process, the HTML output is not clean making it difficult to manage later. The ViewState also increases your page size.
In ASP.NET MVC, the output is clean and you have full control over the rendered HTML. The orientation is towards building standard compliant pages and provides full control over the behavior of an application.
Deep understanding of HTML, CSS and JavaScript is not required to a large extent since the WebForm model abstracts a lot of these details and provides automatic plumbing. While abstracting details to provide ease of use, sometimes a solution is overcomplicated, than it needs to be.
A thorough understanding of how HTML, CSS and JavaScript work together is required. The advantage is you can do a lot of jQuery and AJAX stuff in an efficient and simple manner than you would do in an ASP.NET application.
WebForms can drastically reduce time while building up intranet and internet applications that use a lot of controls (drag and drop model). Although this is true for development, a lot of time is spent later to code around limitations.
You lose the 'drag and drop' quick model of building your web applications. The focus is on control over the application behavior and test-driven development. The model is extensible and you do not have to spend time working around limitations.
Relatively simple to learn and pickup. Works very well for developers who initially have trouble with the HTTP/HTML model and are coming from a similar WinForms oriented event model.
There is a learning curve to understand the why, when and how of ASP.NET MVC.
Lesser amount of code is required to build webapps since a lot of components are integrated and provided out of the box. You can also use a lot of data controls provided out of the box that rely on ViewState.
Since the application tasks are separated into different components, amount of code required is more. Since ASP.NET MVC does not use ViewState, you cannot use Data controls like GridView, Repeater.
Works very well for small teams where focus is on rapid application development
Works well for large projects where focus in on testability and maintainability

Monday, 9 May 2011

General Page Life-cycle Stages of ASP.NET

Stage

Description

Page request

The page request occurs before the page life cycle begins. When the page is requested by a

user, ASP.NET determines whether the page needs to be parsed and compiled or whether a

cached version of the page can be sent in response without running the page.

Start

In the start step, page properties such as Request and Response are set. At this stage, the page

also determines whether the request is a postback or a new request and sets the IsPostBack

property. Additionally, during the start step, the page's UICulture property is set.

Page

initialization

During page initialization, controls on the page are available and each control's UniqueID

property is set. Any themes are also applied to the page. If the current request is a postback,

the postback data has not yet been loaded and control property values have not been restored

to the values from view state.

Load

During load, if the current request is a postback, control properties are loaded with information

recovered from view state and control state.

Validation

During validation, the Validate method of all validator controls is called, which sets the IsValid

property of individual validator controls and of the page.

Postback event

handling

If the request is a postback, any event handlers are called.

Rendering

Before rendering, view state is saved for the page and all controls. During the rendering phase,

the page calls the Render method for each control, providing a text writer that writes its output

to the OutputStream of the page's Response property.

Unload

Unload is called after the page has been fully rendered, sent to the client, and is ready to be

discarded. At this point, page properties such as Response and Request are unloaded and any

ASP.NET caching (કેશીંગ)

તેમા ત્રણ પ્રકારના caching હોય છે.
Output caching (આઉટપુટ કેશિંગ)
Fragment caching(ફ્રેગમેન્ટ કેશિંગ)
Data caching(ડેટા કેશિંગ)

Output caching (આઉટપુટ કેશિંગ)
ડાયનેમિક રીતે બનેલા HTTP રીસ્પોંસનુ કેશીંગ
Fragment caching(ફ્રેગમેન્ટ કેશિંગ)
ડાયનેમિક રીતે બનેલા HTTP રીસ્પોંસનુ કોઈ ચોક્કસ ભાગનુ કેશિંગ
Data caching(ડેટા કેશિંગ)
સર્વરને મળતી HTTP રીક્વેસ્ટ મા પ્રોગામેટીકલી કોઈ ચોક્કસ ડેટાનુ કેશિંગ

Friday, 8 May 2009

immutable types in C# (અવિકારી ટાઇપ in C#)

string s1 = "hello";
string s2 = s1;
Then s2 does at this point reference the same string object as s1. However, when the value of s1 is changed, for instance with

(અહી s2 વેરિએબલ અને s1 વેરિએબલ એક મેમરી એડ્રેસ ને રીફેર કરશે હવે ધારોકે s1 વેરિએબલ ચેન્જ કરવામાં આવે તો )

s1 = "goodbye";
what happens is that a new string object is created for s1 to point to. Hence, following this piece of code, s1 equals "goodbye", whereas s2 still equals "hello".

( એક નવો સ્ટ્રીંગ object મેમરી માં બને જેમાં " goodbye " સ્ટોર કર્યું હોય અને s1 વેરિએબલ તે ને રેફેર કરે જેથી કરીને ને s1 =" goodbye " થાય પણ, s2 હજી પણ " hello " ને રીફેર કરશે)

Basically, an object is immutable if its state doesn’t change once the object has been created. Consequently, a class is immutable if its instances are immutable.

(આવું થવાનું કારણ છે કે સ્ટ્રીંગ અવિકારી ટાઇપ છે . માટે અવિકારી ટાઇપ ને વ્યાખ્યા નીચે મુજબ થાય

"જે OBJECT એક વાર મેમરી માં ક્રીઅટે કરાયા પછી તેનું STATE બદલી શકાતું નથી તેને અવિકારી ટાઇપ કહે છે .")

Monday, 13 April 2009

.net interview question answer

Explain CLR in brief.

Answer

CLR stands for Common Language Runtime.

The CLR is a development platform. It provides a runtime, defines functionality in some libraries, and supports a set of programming languages. The CLR provides a runtime so that the softwares can utilize its services. The CLR Base Class Library allows interaction with the runtime. The CLR supports various programming languages, several standards and is itself been submitted as an open standard.

Describe how a .Net application is compiled and executed.

Answer
From the source code, the compiler generates Microsoft Intermediate Language (MSIL) which is further used for the creation of an EXE or DLL. The CLR processes these at runtime. Thus, compiling is the process of generating this MSIL.

The way you do it in .Net is as follows:

Right-click and select Build / Ctrl-Shift-B / Build menu, Build command
F5 - compile and run the application.
Ctrl+F5 - compile and run the application without debugging.

Compilation can be done with Debug or Release configuration. The difference between these two is that in the debug configuration, only an assembly is generated without optimization. However, in release complete optimization is performed without debug symbols.

Describe the parts of assembly.

Answer
An assembly is a partially compiled code library. In .NET, an assembly is a portable executable and can be an EXE (process assembly) or a DLL (library assembly). An assembly can consist of one or more files or modules in various languages. It is used in deployment, versioning and security.

Explain the .Net Framework.

Answer - 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.

Describe the .Net Framework Architecture.

Answer - 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.

What are the components of the .Net Framework?

Answer - Class Loader, Compiler, Garbage Collection, Type checker, Debug engine, Exception Manager, Security engine, Thread manager, COM Marshallar, Class Library.

Explain the role of assembly in the .Net Framework.

Answer - .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.

Describe the GAC in the .Net Framework.

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

Define .Net Assembly.

Answer - 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.

What does an assembly contain?

Answer - 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

Define private assembly and a shared assembly.

Answer - 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.

What are Satellite Assemblies?

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

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

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

How do you create a resource-only assembly?

Answer - 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.

Explain how to retrieve resources using ResourceManager class.

Answer - 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.

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

Answer - 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.

Define Global Assembly Cache.

Answer - 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.

How do you install assembly to the Global Assembly Cache?

Answer - 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

What is code security? What are the types?

Answer - .Framework provides the security features to secure code from unauthorized users and unauthorized uses.
There are two types of code security:
Role based security: This authorizes user.
Code access security: This protects system resources from unauthorized calls.

Define Principal object.

Answer - The Principal object represents authenticated users. It contains information about user’s identity and role. You have PrincipalPermission object in .Framework that specifies user and its role. It has Demand method that checks the current user or Principal against the name and role specified in the PrincipalPermission.

Define declarative and imperative security.

Answer - Security checks can be applied imperatively or declaratively. Declarative security is applied by associating attribute declarations that specify a security action with classes or methods. Imperative security is applied by calling the appropriate methods of a Permission object that represents the Principal (for role-based security) or system resource (for code access security).

Define role-based security.

Answer - Role-based security is to verify the role and/or identity of the current Principal object.

Explain code access security.

Answer - Code access security protects code from unauthorized calls. You can prevent access to the system resources using Permission object. The permission object specifies user and its role. The demand method of permission object checks if specified user and role matches with the current user.

What is Code group?

Answer - Code groups represent collections of code and each code group has an associated set of permissions.

Define the use of Caspol.exe.

Answer - It is DOS command to view and alter code access security policy.

Describe how exceptions are handled by the CLR?

Answer
Usually the exceptions that occur in the try are caught in the catch block. The finally is used to do all the cleaning up work. But exceptions can occur even in the finally block. By using CLR, the exception are caught even in the finally block. Also when an exception is thrown, the CLR looks for an appropriate catch filter that can handle the exception and then it executes the finally block before terminating the execution on the catch filter.

How to throw a custom exception?

Answer
The usual try - catch - finally - ent try format has to be followed. However, in this case, instead of using the preset exceptions from the System.Exception, you define your OwnException class and inherit Exception or ApplicationException class.

You need to define three constructors in your OwnException Class: One without parameters, other with String parameter for error message and the last one has to have one parameter as a String and other as an Inner exception object.

Example:
class OwnException : ApplicationException
{
public OwnException() : base() {}
public OwnException(string s) : base(s) {}
public OwnException(string s, Exception ae) : base(s, ae) {}
}

Explain Form level validation and Field level Validation.

Field-level validation provides immediate validation of the input given by the user. The events associated with field-level validation are KeyDown, KeyPress, textchange, etc.

In form-level validation the validation step is done after the filling up of the form is done. It’s usually when the user submits the forms.

.NET garbage collection - August 25, 2008 at 18:00 PM by Amit Satpute

What is garbage collection?

Answer
The applications created acquire memory. Memory management includes deallocating this acquired resources and acquiring them. This is done by garbage collector and this concept of automatically reclaiming the memory is called Garbage Collection.

Is it possible to force garbage collection to run?

Answer
Yes, it is possible to force Garbage Colletcion . The way to do it is by using GC.Collect().

However, it is also necessary to run the finalizers of the objects that need to be deallocated. So, it is necessary to use GC.WaitForPendingFinalizers() along with GC.Collect() so that the finalizers threads are not executed separately.

Define Dispose().

Answer
It is a method for releasing resources that an object acquires. The Dispose method is called by the destructor.

Explain how garbage collection manages reclamation of unused memory in .NET.

CLR performs garbage collection on small objects and large objects separately. It maintains separate heaps for these two types of objects. Large Objects are maintained in LO

Heap and small objects are kept in multiple heaps which are compacted regularly.

It uses the JIT compiler which provides it the references of live objects indicating that they are alive. The rest of the objects are then subject to garbage collection.

Then the free memory is merged and the occupied memory is compacted so that the live objects are contiguous.

Explain how garbage collection deals with circular references.

Circular referencing issue happens when two objects refer to each other. Usually in a parent-child relationship, situations occur where a child interacts with the parent object and has a reference held to the parent object.

The .NET, the objects that are reachable from the root can be cleaned up easily. Thus, this can even be applied to circular reference and have the objects holding the resources cleaned up.

What is user-defined data type?

Answer
A user-defined type is a named data type created by the user. It can be a distinct type sharing a common representation with some built-in data type or it can be a structured type which has a sequence of named attributes that each has a type. Thus based on this it can be categorized as:

-Distinct type
-Structured type
-Reference type

Classes vs. Structures

Answer
The class is an extension of a structure.

Structure members have public access by default
Class member variables are private by default

The keyword for class is class
The keyword for structures is struct


Saturday, 14 March 2009

Index in SQL server (ઈન્ડેક્ષ્ ઈન SQL સર્વર)

ઈન્ડેક્ષ એટલે અનુક્રમ, ડેટાબેઝનો ડેટા ઝડપથી મેળવી શકાય તેના માટે ડેટાબેઝના ડેટાની ગોઠવણને ઈન્ડેક્ષ કહે છે. SQL ડાટાબેઝમા મુખ્યત્વે બે જાતના ઈન્ડેક્ષ એટલે અનુક્રમ હોય છે.  
૧) Clustered Index (વૃંદ અનુક્રમ)  
૨) Non Clustered Index (અવૃંદ અનુક્રમ
Clustered Index માં ડેટાબેઝમા ડેટાના વાસ્તવિક ગોઠવણ(physical arrangement) ના અનુક્રમ(index)ને વૃંદ અનુક્રમ(Clustered Index) કહે છે. જ્યારે ડેટાબેઝમા ડેટાના તાર્કીક ગોઠવણ(logical arrangement) ના અનુક્રમ(index)ને અવૃંદ અનુક્રમ(non-Clustered Index) કહે છે. તેથી ડેટાબેઝમા વૃંદ અનુક્રમ(Clustered Index) એક જ હોય છે કારણકે વાસ્તવિક ગોઠવણ(physical arrangement) માત્ર એક જ રીતે શક્ય છે. જ્યારે અવૃંદ અનુક્રમ(non-Clustered Index) એક કરતા વધારે હોય શકે છે. કારણકે તાર્કીક ગોઠવણ(logical arrangement) એક કરતા વધારે શક્ય હોય છે.

antivirus list(ઍન્ટી વાયરસ)

BitDefender
Kaspersky
ESET Nod32
AVG Anti-Virus
F-Secure
Anti-Virus
Trend
Micro Antivirus
McAfee
VirusScan
Norton
AntiVirus

CA
Antivirus
Norman Antivirus and Antispyware
G DATA Antivirus
Panda Antivirus
AVAST!

F-Prot
PC
Tools AntiVirus
Webroot
Antivirus
ViRobot

CyberScrub
AntiVirus
The
Shield Antivirus
WinAntiVirus

Windows Live OneCare