Tuesday, 11 December 2012








-->
DEFINE CONNECTED AND DISCONNECTED DATA ACCESS IN ADO.NET?
Connected data access through the DataReader objects of data provider. This object requires exclusive use of the connection object. It can provide fast and forward-only data access. It doesn't allow editing.  Disconnected data access is achieved through the DataAdapter object. This object establishes connection, executes the command, load data in the DataSet. The dataset works independent of database. It contains data in the memory and can edit the data. The changes in the data can be transmitted to the database using Update method of DataAdapter object. 
1. Connected environment needs a constantly connection of user to data source while performing any operation. Dissconnected environment does not need any connection. 2. Only one operation can be performed at a time in connected environment while in dissconnected multiple operations can be performed. 3. DataReader is used in connected environment. DataSet is used in dissconnected environment. 4. Connected environent is slower in speed. Disconnected environment has a good speed. 5. We get updated data in connected environment In disconnectes environment,thereis a problem of dirty read.
DIFFERENCE BETWEEN DATA GRID AND REPEATER
Difference between Datagrid and Repeater 1. Datagrid has paging while Datalist doesnt. 2. Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid. 3. A repeater is used when more intimate control over html generation is required. 4. When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radiobuttonlist are used as they involve fewer overheads than a Datagrid. The Repeater repeats a chunk of HTML you write, it has the least functionality of the three. DataList is the next step up from a Repeater; accept you have very little control over the HTML that the control renders. DataList is the first of the three controls that allow you Repeat-Columns horizontally or vertically. Finally, the DataGrid isthe motherload. However, instead of working on a row-by-row basis, you’re working on a column-by-column basis. DataGrid caters to sorting and has basic paging for your disposal. Again you have little contro, over the HTML. NOTE: DataList and DataGrid both render as HTML tables by default. Out of the 3 controls, I use the Repeater the most due to its flexibility w/ HTML. Creating a Pagination scheme isn't that hard, so I rarely if ever use a DataGrid. Occasionally I like using a DataList because it allows me to easily list out my records in rows of three for instance.
********************** Ajax **************************
CAN YOU NEST UPDATEPANEL WITHIN EACH OTHER?
Yes, you can do that. You would want to nest update panels to basically have more control over the Page Refresh.
CAN WE USE MULTIPLE SCRIPTMANAGER ON A PAGE?
No. You can use only one ScriptManager on a page.
WHAT IS THE ROLE OF A SCRIPTMANAGERPROXY?
A page can contain only one ScriptManager control. If you have a Master-Content page scenario in your application and the MasterPage contains a ScriptManager control, then you can use the ScriptManagerProxy control to add scripts to content pages.
Also, if you come across a scenario where only a few pages in your application need to register to a script or a web service, then its best to remove them from the ScriptManager control and add them to individual pages, by using the ScriptManagerProxy control. That is because if you added the scripts using the ScriptManager on the Master Page, then these items will be downloaded on each page that derives from the MasterPage, even if they are not needed, which would lead to a waste of resources.
WHAT IS ASP.NET AJAX?
ASP.NET AJAX’ is a terminology coined by Microsoft for ‘their’ implementation of AJAX, which is a set of extensions to ASP.NET. These components allow you to build rich AJAX enabled web applications, which consists of both server side and client side libraries.
HOW WILL YOU INVOKE A WEB METHOD IN AJAX?
Set EnablePageMethods property of ScriptManager to "true"  And inside Javascript we can directly use  window.PageMethods.METHODNAME()
WHAT IS BENIFIT OF AJAX OVER JAVA APPLETS?
The following are the benefits of AJAX over Java applet: AJAX applications are loaded in seconds, where as Applets takes longer time. The reason is, Applet applications are tend to load large libraries
WHAT IS THE DISADVANTAGE OF AJAX?
The disadvantages of AJAX are:
  •   Search engines would not be able to index an AJAX
    application.

  • The server information can not be accessed
    within AJAX.

  • AJAX is not well integrated with any browser.

  • ActiveX requests are enabled only in IE 5 and IE6

  • Data of all requests is URL-encoded, which increases the size of the
    request
********************** ADO.Net **************************
WHAT IS DATAVIEW MANAGER?
DataViewManager is used to manage view settings of the tables in a DataSet. A DataViewManager is best suited for views that consist of a combination of multiple tables. The properties like ApplyDefaultSort, Sort, RowFilter, and RowStateFilter are referenced using DataViewSetting
Data view manager is used for creation of data view between table and it provide schema type information about table and it show the all operation like insert,delete etc as alias type.
JSCRIPT
WHAT LOOPING STRUCTURES ARE THERE IN JAVASCRIPT?
for, while, do-while loops, but no foreach.
BASIC METHODS FOR OPENING POPUP WINDOW IN JAVASCRIPT?
There are two basic way to open new window 1) Using Window.Open() and  2) Using Window.showModalDialog()  The Syntax for using these methods are  . Window.Open(URL,WindowName,Window Features)  Example: window.open ("http://www.dotnetfunda.com","mywindow","status=1,toolbar=1");  . window.showModalDialog(URL,WindowName,ModalDialog Features) for example: window.showModalDialog("http://www.mindstick.com", "mywindow","dialogWidth:400px;dialogHeight:395px");
WHAT IS EVAL() IN JAVASCRIPT?
The eval() method is incredibly powerful allowing us to execute snippets of code during execution in JavaScript. Example: <script type="text/javascript"> var USA_Texas_Austin = "521,289"; document.write("Population is "+eval("USA_"+"Texas_"+"Austin")); </script> Output: Population is 521,289
NAME THE NUMERIC CONSTANTS REPRESENTING MAX, MIN VALUES?
Number.MAX_VALUE //it returns the max value Number.MIN_VALUE //it returns the min value
HOW CAN WE SEND MAIL USING JAVASCRIPT?
No. There is no way to send emails directly using JavaScript.  But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:  function functioname(form) { tdata=document.myform.tbox1.value; location="mailto:emailid@domain.com?subject=..."; return true; }
WHICH CLASS AND METHOD OF SYS.NET NAMESPACE DO WE USE TO MAKE AN ASYNCHRONOUS REQUEST IN JAVASCRIPT?
Sys.Net.WebRequest class  And invoke method
HOW TO CREATE A DATE OBJECT IN JAVASCRIPT?
We create  a data object in javascript as:  dateObjectName = new Date([parameters]) Create a direct instance of an object forexample: dateObjectName = new Date([parameters]) The syntax for accessing a property of an object is: dateObjectName.propertyname
HOW TO SET THE FOCUS IN AN ELEMENT USING JAVASCRIPT?
<script> function setFocus() { if(focusElement != null) { document.forms[0].elements["myelementname"].focus(); } } </script
HOW TO SETTING A COOKIE WITH THE CONTENTS OF A TEXTBOX ?
Values stored in cookies may not have semicolons, commas, or spaces. You should use the handy "escape()" function to encode the values, and "unescape()" to retrieve them. //Sets cookie of current value for myTextBox function TextBoxOnchange() { var myBox = window.document.getElementById(myTextBox"); document.cookie = "myTextBox="+ escape(myBox.value) + getExpirationString(); } //return a string like ";expires=Thu, 5 Jan 2006 16:07:52 UTC" function getExpirationString() { var exp = new Date(); var threemonths = exp.getTime()+(120*24*60*60*1000); exp.setTime(threemonths); return ";expires="+exp.toGMTString(); } This is called from the event handler in the HTML. <input name="myTextBox" type="text" id="myTextBox" onchange="javascript:TextBoxOnchange()" />
WHERE ARE COOKIES ACTUALLY STORED ON THE HARD DISK?
This depends on the user's browser and OS. In the case of Netscape with Windows OS,all the cookies are stored in a single file called cookies.txt  c:\Program Files\Netscape\Users\username\cookies.txt
HOW TO SUBMIT FORM WITHOUT SUBMIT BUTTON?
With this method, you can cause a form to be submitted when the user clicks on a regular link, which can be a text link or an image link. This requires two steps. First step, the form Give your form a name. This is done in the FORM tag itself: <form name="MyForm" method="POST" action="/cgi-bin/script.cgi"> Second step, the JavaScript Create a link containing the submit command <a href="javascript:document.MyForm.submit();"> Click to submit the form </a> Optional third step You can remove the submit button or, to be kind to the few non-JavaScript browsers that visit your site, put it between NOSCRIPT tags: <noscript> <input type="submit" name="Click here"> </noscript> The above will display the submit button only when non-JavaScript browsers visit the page.
HOW TO SET ALL CHECKBOXES TO TRUE USING JAVASCRIPT?
//select all input tags function SelectAll() { var checkboxes = document.getElementsByTagName("input");
for(i=0;i<checkboxes.length;i++) { if(checkboxes.item(i).attributes["type"].value == "checkbox") { checkboxes.item(i).checked = true; } } }
HOW TO RELOAD THE CURRENT PAGE?
we use following syntax: window.location.reload(true);
WHAT IS THE WAY TO APPEND A VALUE TO AN ARRAY?
way to append a value in array  for example: arrName[arrName.length]=value;
Functions  ---------- 1) can be used with Select statement 2) Not returning output parameter but returns Table variables 3) You can join UDF 4) Cannot be used to change server configuration 5) Cannot be used with XML FOR clause 6) Cannot have transaction within function Stored Procedure ----------------- 1) have to use EXEC or EXECUTE 2) return output parameter 3) can create table but won’t return Table Variables 4) you can not join SP 5) can be used to change server configuration 6) can be used with XML FOR Clause 7) can have transaction within SP Although both functions and sp's are prcomiled sql statements there exists some differences between them. 1. Functions must return a value(scalar,inline table or multi statement table) whereas stored proc may or may not retun a value. 2.Functions can return a table whereas stored procs can create a table but can't return table. 3. Stored procs can be called independently using exec keyword whereas function are called using select statements. 4. Stored procs can be used to change server configuration(in terms of security-i.e. setting granular permissions of user rights) whereas function can't be used for this 5. XML and output parameters can't be passed to functions whereas it can be with sp's. 6.transaction related statement can be handled in sp whereas it can't be in function. 7. stored procedures can call a funtion or another sstored proc similarly a function can call another function and a stored proc.The catch with function is that no user defined stored proc can be called.Only extended/system defined procs can be called.
<![if !supportLists]>1.  <![endif]>Functions are compiled and executed at run time. Stored procedures are stored in parsed and compiled format in the database. 2. Functions cannot affect the state of the database which means we cannot perform insert,delete,update and create operations on the database. Stored Procedures can affect the state of the database by using insert,delete,update and create operations. 3 Functions are basically used to compute values. We passes some parameters to functions as input and then it performs some operations on the parameter and return output. Stored procedures are basically used to process the task. 4.Function can not change server environment and our operating system environment. Stored procedures can change server environment and our operating system environment. 5.Functions can not be invoked from SQL Statements. Execute. SELECT operating system can be invoked from SQL Statements. Execute. SELECT 6.Functions can run an executable file from SQL SELECT or an action query. operating system use Execute or Exec to run  <![if !supportLineBreakNewLine]> <![endif]>
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered (Not like in white-box testing).[1]
Functional testing differs from system testing in that functional testing "verif[ies] a program by checking it against ... design document(s) or specification(s)", while system testing "validate[s] a program by checking it against the published user or system requirements"(Kaner, Falk, Nguyen 1999, p. 52).
Functional testing typically involves five steps[citation needed]:
<![if !supportLists]>1.    <![endif]>The identification of functions that the software is expected to perform
<![if !supportLists]>2.    <![endif]>The creation of input data based on the function's specifications
<![if !supportLists]>3.    <![endif]>The determination of output based on the function's specifications
<![if !supportLists]>4.    <![endif]>The execution of the test case
<![if !supportLists]>5.    <![endif]>The comparison of actual and expected outputs
-->

Delegates

Delegates are the ultimate function pointer. Developers familiar with C and C++ are very familiar with function pointers and their lack of instance-based knowledge. A delegate can be thought of as a call back mechanism, essentially saying, "Please invoke this method for me when the time is right."
Consider the following scenario: Your department has just hired a new employee. Human Resources needs to be notified when a new employee is hired so they can put them to sleep with endless paper work and boring drivel about company policies and practices. This type of interaction is a perfect example of a delegate. Basically, Human Resources is requesting a notification when a new employee is hired and provides a method to be invoked.
Listing 2.1.32 Using Delegates shows the basic use of delegates.
Listing 2.1.32 Using Delegates
 1: //File        :part02_31.cs
 2: //Author    :Richard L. Weeks
 3: //Purpose    :Demonstrate the use of delegates
 4:
 5: using System;
 6:
 7: //Define a person struct
 8: public struct Person {
 9:     public string FName;
10:     public string LName;
11: }
12:
13: //Define a delegate
14: public delegate void OnNewHire( Person person );
15:
16: //The HR Class
17: public class HR {
18:
19:     //Implement the delegate to be called when a new person is hired
20:     public void OnNewHire( Person person ) {
21:         Console.WriteLine( "HR is in the process of putting {0}  to sleep", 
graphics/ccc.gifperson.FName );
22:     }
23: }
24:
25: //Create a department
26: public class Department {
27:
28:     //Who to notify
29:     private OnNewHire    m_OnNewHireDelegate = null;
30:
31:     //set the OnNewHire delegate
32:     public void AddOnNewHireDelegate( OnNewHire onh ) {
33:         m_OnNewHireDelegate = onh;
34:     }
35:
36:
37:     public void HirePerson( Person p ) {
38:         //do we need to notify someone?
39:         if( m_OnNewHireDelegate != null )
40:             m_OnNewHireDelegate( p );
41:     }
42: }
43:
44:
45: public class DelegateTest {
46:
47:     public static void Main( ) {
48:
49:         HR hr = new HR( );
50:         Department dept = new Department( );
51:
52:         //Register the OnNewHire Delegate
53:         dept.AddOnNewHireDelegate( new OnNewHire( hr.OnNewHire ) );
54:
55:         //Create a person
56:         Person me; me.FName = "Richard"; me.LName = "Weeks";
57:
58:         //Hire ME!!!
59:         dept.HirePerson( me );
60:     }
61: }
Listing 2.1.32 implements the HR scenario and makes use of a delegate to notify HR when a new person has been hired. The delegate OnNewHire is defined on line 14. Notice the use of the delegate keyword to denote what is being declared. Remember that C# does not allow for global methods, so C# would issue an error without the delegate keyword.
The HR class provides a handler for the delegate. The method name does not have to be the same as the name of the delegate; this was done to make it easier to follow. The Department class provides a method AddOnNewHireDelegate to handle the "hooking-up" of the delegate with the intended handler. Notice the call on line 53 that actually adds the HR handler to the Department. A delegate is a type in C# and requires an instance, hence the use of the new keyword to create a new delegate.
I would encourage any developer to explore delegates in detail because their use in .NET is prolific, especially in Windows Forms development.

Sunday, 9 December 2012

Authentication IN .NET


Authentication
Authentication is the act of validating a client's identity. In a distributed application environment ability to identify someone that is claiming to be is very critical. It is the starting point of giving access to vital resources in site. Generally this is done by user providing some kind of evidence that known as credentials. Typically, credentials includes a username and a password that use for authentication. Both Internet Information Server (IIS) and ASP.NET provides several authentication schemas. ASP.NET supports four kind of authentication.
1. Windows Authentication
2. Passport Authentication
3. Form Authentication
4. None
When implementing a site, we can select from above four authentication mechanisms.
IIS provides the following authentication schemas
1. Anonymous
2. Basic
3. Digest
4. Integrated Windows authentication
5. Client Certificate Mapping
1. Windows Authentication

Every time when creating an ASP.NET Web application or Web services the default authentication model will be Windows Authentication. To make use of the Windows Authentication, the Web.config file needs to be configured as below:





The windows authentication provider relies upon Internet Information Server (IIS) to perform the required authentication for a user. Then after the user gets authenticated, IIS passes a security token to ASP.NET. There are several ways that you can use windows authentication, Basic Authentication, Digest Authentication, Integrated Windows Authentication (NTL/Kerberos) or X.509 Client Certificates. To use these authentication options the user need a valid account in windows domain or within Active Directory.
To use Windows Authentication, you need to configure the IIS to turn off the anonymous access. Allowing anonymous access is the default for authentication. It can be done as shown below.
Click Start > Run > type inetmgr. This will open the Internet Information Services window. Select the Default Web Sites and navigate to the virtual directory of interest. Select all the files by selecting the virtual directory or the particular file (.aspx, .asmx) and right click the directory or file. Select Properties > Directory Security (Figure 1).

Figure 1
Now under the Anonymous access and authentication control, click the Edit button. The Authentication Methods dialog box will display as shown in Figure 2

Figure 2
Using the Authentication Method dialog box configure how a user can access the virtual directory or files. To pass the users credentials via HTTP headers, you can use Basic authentication or Digest authentication.
Anonymous Authentication

Anonymous authentication is perfect for public sites that dose not required identifying the users. The user doesn't need to pass a username and a password to server to access the information. In this scenario all users have access for the site and there won't be any restrictions for the users. When anonymous authentications is used the application thread will run either
1. Anonymous internet account IUSR_MACHINENAME
2. A account configured at IIS for anonymous users
3. or IIS system account
This mechanism wont be suitable if user need to restrict from accessing recourse on base of there credentials.
To implement the Anonymous authentication select the Anonymous access in the Authentication methods window at IIS. (A sample of Authentication methods window is displayed in figure 2) At the same time configure the ASP.NET using Web.config file to use Windows authentication as shown below.





Basic Authentication

Basic authentication is an HTTP standard. The username and password that passes through the channel is clear text. This uses the base64 encoding. This is human readable and there are no secret keys being used for encoding. IIS will check the user name and password to an account on the web server and produce an access token.
This token will be used to do an ACL base security check. When user try to access a file or a directory that allows Basic authentication unauthorized, it will display an error message with 401 status codes indicating that authentication is required. Windows authentication works virtually with all browsers and it works well with firewalls.
The downside is using unencrypted channel for gain access for the server there is noting to prevent request from being intercepted. Because of this the credentials should be passes in a secure channel using SSL to make it less venerable for interception.
To implement the Basic authentication select the Basic Authentication in the Authentication methods window at IIS. At the same time users should have "log on locally" privilege on the web server. (A sample of Authentication methods window is displayed in figure 2). Configure the ASP.NET using Web.config file to use Windows authentication as shown below.





A Dialog box will display to enter credentials when user tries to access the protected site.

Figure 3
User will get access for the resources if he/she authenticated. Otherwise the following error message will be displayed.

Figure 4
Digest Authentication

This is bit similar to the Basic authentication. When user tries to access a file or a directory protected by Digest authentication a pop up dialog box will be displays asking for the user name and the password. Then the credentials that user enter will assign an identity to the request. The biggest different with Basic and Digest is the Digest doesn't transmit information in clear text. It transmits information in a cryptographically secure way. The advantage is you can use it over unencrypted channel.
When user enters the user name and password in the dialog box the user name will be transmit to the server with a hash or "digest" computed from the combined user name, password and nonce. Then the server will create its own hash on the user name, password and nonce and authenticate against each. The password that server use dose not coming from the user, it is what stored in the server side for that particular user name. If the both hashes are matched, the user will be authenticated and grant permission to requested resources from the server. It is also compatible with proxy servers and it works with firewalls.
To use Digest authentication user needs a browser with Internet Explorer V5.0 or higher. It doesn't support delegation on windows 2000 server. Because of these limitations it is not widely used for authentication purposes.
To implement the Digest authentication select the Digest Authentication for windows domain servers in the Authentication methods window at IIS. (A sample of Authentication methods window is displayed in figure 2). Configure the ASP.NET using Web.config file to use Windows authentication as shown below.





A Dialog box will display to enter credentials when user tries to access the protected site

Figure 5
User will get access for the resources if he/she authenticated. Otherwise an error message will be displayed as shown in Figure 4
Integrated Windows Authentication.

Integrated Windows Authentication will authenticate a user against Windows NT Domain or Active Directory account. This authentication mechanism is very secure because the encrypted password is not sent across the network like in Basic or Digest authentication. It uses either NT LAN Manager (NTLM) or Kerberos authentication.
This authentication is much more suitable for intranet environment that runs behind a fire wall. This schema is not suitable for internet because it only supports windows client. At the same time if user accounts details are stored in external database rather than in a Windows NT domain or Active directory database, this authentication mechanism should not be used for security reasons.
To implement the Integrated Windows authentication select the Integrated Windows Authentication in the Authentication methods window at IIS. (A sample of Authentication methods window is displayed in figure 2). Configure the ASP.NET using Web.config file to use Windows authentication as shown below.





Client Certificate Mapping

A certificate is a digital key in user's computer. When user access a resources from the server this key will be automatically pass in for authentication. User won't have to enter any username and password for authentication. This makes it more attractive option for automated business processes. The client certificates can be mapped to windows accounts or to Active Directory. At the same time developer can implement custom authentication in ASP.NET by using a unique field like email address contained within the certificate.
You need to physically deploy the client certificate to the client machine. At the same time issuing and managing client certificate can be expensive. These are the some of issues that stop using this authentication method widely.
Authenticating an individual user can be done by one-to-one mapping where a certificate is mapped to an individual account. There is no limit of one-to-one mapping if Active directory mapping is used. Many-to-many mapping can be used to authenticate all of the users from particular group or organization.
2. Passport Authentication
Passport authentication is a centralized authorization mechanism provided by Microsoft. It is using a cookie mechanism. This supports a single sign on approach across multiple domains and users will be able to access many passport authentication supported site by single sign on. Because of this the user won't have to input their credentials again and aging to access different passport supported sites. The developers won't be needed to create their own login pages and manage user names and passwords. They simply forward the users to Microsoft passport site for authentication if they haven't authenticated already. When the user get authenticated user will be assign a cookie. This cookie is pass to rest of the passport supported site to get access with out have to enter any credentials.
If you are not interested in maintaining your own user names and pass words database and your site will be used together with other passport supported sites, passport authentication will be perfect for your . Using SSL with Passport authentication can make it more secure.
To implement passport authentication you need to install the Passport SDK on your server and have to register with Microsoft Passport to access their service. At the same time configure web.config file as shown below.





3. Form Authentication
The user will have to pass username and password details directly to the application using HTTP. If the user gets authenticated he/she will be assign with a cookie that will grant access to protected recourse. If the user fails in authentication he/she will be redirected to the login page to enter their username and password. When authenticating the credentials they can be store in a number of ways. Ex: in configuration file, xml file or in a SQL database. The main advantage is it doesn't need a windows account for authentication. To make it more secure we can use SSL when passing the credentials.
To implement the Form authentication the developers will have to create their own login pages and have to manage usernames and passwords. IIS need to be configured allowing Anonymous Authentication. At the same time configure web.config file as shown below.








I won't be going for much details about Form Authentication because I am planning to publishing a article in near future about Form Authentication.
4. None (Custom Authentication)
This will allow to develop custom authentication mechanisms. For a example creating your own authentication schema. It offers the total control of the authentication process and provides great flexibility. But it requires extra work to implement custom authentication schemas.
To implement no authentication or to build your own authentication configure the Web.config file as shown below