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 ;
    }