Thursday, December 27, 2007
Why do we need to call CG.SupressFinalize?
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?
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 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 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
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..
- 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.
- 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
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 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
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
Events in Global.asax
- Application_Init
- Application_Start
- Session_Start
- Application_BeginRequest
- Application_EndRequest
- Application_AuthenticateRequest
- Application_Error
- Session_End
- 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
- Avoid excessive round trips to the server.
- Use Page.IsPostback.
- Enable or disable viewstate accordingly.
- Use Response.Write for String concatenation.
- Never use exceptions as a way to control normal program flow.
- Use stored procedures.
- Cache data and output wherever possible.
- Disable Session State when not in use.
- Use SqlDataReader for a fast-forward, read-only data cursor.
EnableViewState
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
http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx
The Wait for Visual Studio 2008 is Over!
http://msdn2.microsoft.com/en-us/vstudio/default.aspx
Wednesday, October 31, 2007
What is the difference between private and shared assembly?
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?
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?
Eg.
int i = 123;
object o = (object)i; // boxing
o = 123;
i = (int)o; // unboxing
What is Base Class Library?
What is menifest?
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?
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?
Data whoes memory allocation and deallocation is managed by Garbage collector is called as managed data.
What is Common Language Specification (CLS)?
Its a subset of Common Type System.
What is "Common Type System" (CTS)?
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.