Thursday, December 27, 2007

Why do we need to call CG.SupressFinalize?

public static void SuppressFinalize(object obj);

This method removes obj from the set of objects that require finalization.
Objects that implement the IDisposable interface can call this method from the IDisposable.Dispose method to prevent the garbage collector from calling Object.Finalize on an object that does not require it.

What are the types of Authentication?

There are 3 types of Authentication. Windows, Forms and Passport Authentication.

1. Windows authentication uses the security features integrated into the Windows NT and Windows XP operating systems to authenticate and authorize Web application users.
2. Forms authentication allows you to create your own list/database of users and validate the identity of those users when they visit your Web site.
3. Passport authentication uses the Microsoft centralized authentication provider to identify users. Passport provides a way to for users to use a single identity across multiple Web applications.

Difference between an ADO.NET Dataset and an ADO Recordset

* A DataSet can represent an entire relational database in memory with tables, relations, and views.Recordset can not.
* A DataSet is designed to work without any connection to the original data source. Recordset maintains the continuous connection with the original data source.
* No concept of cursor types in a DataSet. They are bulk loaded while Recordset work with cursors and they are loaded on demand.
* DataSets have no current record pointer, you can use For Each loops to move through the data. Recordsets have pointers to move through them.
* You can store many edits in a DataSet, and write them to the original data source in a single operation. Recordset can have a single edit at a time.
* Dataset can fetch source data from many tables at a time whereas Recordset you can achieve the same only using the SQL joins.

Difference between Classic ASP and ASP.Net?

ASP:
ASP is Interpreted language based on scripting languages like Jscript or VBScript.
ASP has Mixed HTML and coding logic.
Limited development and debugging tools available.
Limited OOPS support.
Limited session and application state management.
Poor Error handling system.
No in-built support for XML.
No fully distributed data source support.
*************************************************
ASP.Net separate code and design logic possible.
Completely Object Oriented.
Complete session and application state management.
Error handling possible.
Full XML Support for easy data exchange.
Fully distributed data source support.

Sunday, December 16, 2007

ViewState

Viewstate persists the state of object across postbacks.
When the page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field. When the page is posted back to the server, the page parses the view state at page initialization and restores property information in the page.

By default viewState is enabled . If you view a web form page in your browser you will see a line in your rendered HTML:

value="abJHnm76hdjsdGFYDFDHDHFbcdy6767ffvfHxdHbf6879gHJge2" />

Page level state is maintained automatically by ASP.NET but you can disable it by setting the EnableViewState property to false for either the controls and page as a whole.
Where to use ViewState and where not..
  1. Amount of data: ViewState increases the size of both the HTML page sent to the browser and the size of form posted back. Use Viewstate where you want to store small amount of data.
  2. Security: ViewState data is encoded and encrypted but getting displayed it to the client is not at all safe in case of sensitive data .

Saturday, December 15, 2007

Tracing

In Active server pages to debug we need to use Response.Write statements to display any information to the screen.
With the help of Visual Studio.net any diagnostic information can be displayed using Tracing.
Tracing can be enabled for Page Level or application level.
  • Page Level Tracing


  • <%@ Page Language="vb" AutoEventWireup="false" Trace="true" Codebehind="Practise.aspx.vb" Inherits="Example.Practise"%>

    Or in the code-behind using the Trace object:

    Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) _
    Handles MyBase.Load
    Trace.IsEnabled = True
    End Sub

  • Application-Level Activation


  • In web.config change the code as



    Other way is using Global.asax in Application_BeginRequest method:

    If (Context.Request.QueryString("trace") = "true") Then
    Context.Trace.IsEnabled = True
    End If

    The trace can contains up to 10 sections, many of which only appear if they contain data.
    The sections are: Request Details, Trace Information, Control Tree, Session State, Application State,
    Cookies Collection, Headers Collection, Form Collection, QueryString Collection, and Server Variables.

    Global.asax file

    The Global.asax file is an optional file that is located in the application's root directory.The Global.asax file is parsed and dynamically compiled by ASP.NET into a .NET Framework class the first time any resource or URL within its application namespace is activated or requested. This file exposes event handlers with application-wide or session-wide scope in the Global.asax file such as Application_Start, Application_End, Session_Start, Session_End, etc.. Also exposes objects with application-wide or session-wide scope in it.


    Events in Global.asax

    1. Application_Init

    2. Application_Start

    3. Session_Start

    4. Application_BeginRequest

    5. Application_EndRequest

    6. Application_AuthenticateRequest

    7. Application_Error

    8. Session_End

    9. Application_End


    There can be only one Global.asax file per application and it should be located in the application's root directory only.

    Enhance Dotnet performance

    1. Avoid excessive round trips to the server.

    2. Use Page.IsPostback.

    3. Enable or disable viewstate accordingly.

    4. Use Response.Write for String concatenation.

    5. Never use exceptions as a way to control normal program flow.

    6. Use stored procedures.

    7. Cache data and output wherever possible.

    8. Disable Session State when not in use.

    9. Use SqlDataReader for a fast-forward, read-only data cursor.

    EnableViewState

    Automatic state management is a feature of ASP.Net that enables server controls to re-populate their values on a round trip.
    The state of a control is passed to and from the server in a hidden form field.
    ViewState is enabled for all server controls by default.To disable set the EnableViewState property of the control to false.
    For eg.

    When you do not post back from a page then to achieve better performance you can turn off ViewState at the page level.

    <%@ Page EnableViewState="false" %>

    Friday, December 7, 2007

    Client side code to accept only numbers in textbox.

    For the textbox add this handler:
    TextBox1.Attributes.Add("onkeydown", "JavaScript:return CheckifNumeric();");

    Add this script:
    function CheckifNumeric()
    {
    var retValue = false;
    var mykey= (window.event.which) ? window.event.which : window.event.keyCode;

    if ( ((mykey>= 48) && (mykey<= 57)) || (mykey== 8) || (mykey== 13) )

    retValue = true;

    if ( window.event.returnValue )

    window.event.returnValue = retValue ;

    return retValue ;
    }


    Thursday, November 29, 2007

    Try Visual Studio 2008

    Microsoft Visual Studio 2008 provides an industry-leading developer experience for Windows Vista, the 2007 Microsoft Office system, and the Web. In addition, it continues in the Microsoft tradition of development language innovation. To enable evaluation of Visual Studio 2008, this page provides links to trial versions of Visual Studio 2008.
    http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx

    The Wait for Visual Studio 2008 is Over!

    On Monday, Nov. 19, Microsoft announced that Visual Studio 2008 and the .NET Framework 3.5 were released to manufacturing (RTM). With more than 250 new features,Visual Studio 2008 includes significant enhancements in every edition, including Visual Studio Express and Visual Studio Team System
    http://msdn2.microsoft.com/en-us/vstudio/default.aspx

    Wednesday, October 31, 2007

    What is the difference between private and shared assembly?

    Assembly which is used by a single application is called as private assembly.It must be placed in the same folder as the application or in the subfolder.
    Shared Assemblies are the assemblies that are accessible globally/shared across the machine to all the applications. For using the shared assemblies you need to register the assembly with a strong name in the global assembly cache(GAC).

    What is reference type and value type?

    Reference types inherit directly from System.Object and are stored in heap.They are directly controled by Garbage collector.Eg. Class, Delegate, Interface etc
    Value type inherit from System.ValueType which inturn inherits from System.Object.They are stored in stack.Eg. Structs, integer,bool etc

    What is boxing and unboxing?

    Boxing and unboxing enables value type to be treated as object.Boxing allows a value type to stored in heap.Unboxing converts the object to value type.
    Eg.
    int
    i = 123;
    object o = (object)i; // boxing
    o = 123;
    i = (int)o; // unboxing

    What is Base Class Library?

    Its a library which is available to all the languages using .Net Framework. It encapsulates large number of common functions, such as file reading and writing, database interaction and xml manipulation etc.

    How many classes can a single .NET DLL contain?

    Infinite classes

    What is the base class of .net?

    System.Object

    What is menifest?

    An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE (Portable Executable) file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE (Portable Executable) file that contains only assembly manifest information.
    It contains:
    Assembly name: A text string specifying the assembly's name.
    Version number: A major and minor version number, and a revision and build number. The common language runtime uses these numbers to enforce version policy.
    Culture: Information on the culture or language the assembly supports. This information should be used only to designate an assembly as a satellite assembly containing culture- or language-specific information. (An assembly with culture information is automatically assumed to be a satellite assembly.)
    Strong name information: The public key from the publisher if the assembly has been given a strong name.
    List of all files in the assembly: A hash of each file contained in the assembly and a file name. Note that all files that make up the assembly must be in the same directory as the file containing the assembly manifest.
    Type reference information: Information used by the runtime to map a type reference to the file that contains its declaration and implementation. This is used for types that are exported from the assembly.
    Information on referenced assemblies: A list of other assemblies that are statically referenced by the assembly. Each reference includes the dependent assembly's name, assembly metadata (version, culture, operating system, and so on), and public key, if the assembly is strong named.

    What is the difference between a namespace and assembly name?

    Namespace is a logical boundary for a group of classes. It basically solves the naming problem.
    An assembly is the building block of a .NET application. It is a self describing collection of code, resources, and metadata (data about data, example, name, size, version of a file is metadata about that file).
    One assembly can contain many namespaces.

    What is managed code and managed data?

    The .Net Framework provides a run time environment called Common Language Runtime which manages the execution of code and provides services that make the development process easier.Code that you write with a language compiler that targets the runtime is called managed code.It benefits from features like cross language integration,cross language exceptional handling, security and deployment support etc.
    Data whoes memory allocation and deallocation is managed by Garbage collector is called as managed data.

    What is Common Language Specification (CLS)?

    Common Language Specification is a set of rules that all Dotnet Languages must follow to achieve Cross Language interoperability.
    Its a subset of Common Type System.

    What is "Common Type System" (CTS)?

    CTS( common type system) brings all .net languages data types on a common platform. It defines types like System.Int16, System.Int32 etc. A language may map 'int' to System.Int16 while another may map its 'int' data type to System.Int32.

    Because all data types from all languages are mapped to common .net datatypes we can integrate code written in different .net languages into one assembly.

    What is "Microsoft Intermediate Language" (MSIL)?

    All .NET programming language first gets compiled into intermediate language(MSIL) and then CLR compiles IL code into natice 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.

    What is CLR?

    Common Language Runtime (CLR) manages the execution of code and provides different services like Garbage collection and support for Base Class Libraries etc. The main constituents of CLR are:

    The common Language Runtime (CLR) a rich set of features for cross-language development and deployment. CLR supports both Object Oriented Languages as well as procedural languages. CLR provides security, garbage collection, cross language exception handling, cross language inheritance and so on.

    The Common Type System, support both Object Oriented Programming languages as well as procedural languages. Basically CTS provides rich type system that is intended to support wide range of languages.

    CLS (Common Language Specification) defines a subset of Common Type System, which all language compilers targeting CLR must adhere to. CLS is a subset of CTS.

    All compilers under .NET will generate Intermediate Language no matter what language is used to develop an application. In fact, CLR will not be aware of the language used to develop an application. All language compilers will generate a uniform, common language called Intermediate Language.Because of which we can have language inteoperability feature in .net.