Tuesday, July 19, 2011

2010 .net features

http://www.codeproject.com/KB/aspnet/Whatis_New_ASP_Net_4.aspx

http://www.techrepublic.com/blog/programming-and-development/whats-new-in-visual-studio-2010-and-net-4/2475

new 2010 .net features

nice website for vb.net

http://www.startvbdotnet.com

vb.net multi threading

Multithreading

Multithreading gives programs the ability to do several things at a time. Each stream of execution is called a thread. Multithreading is used to divide lengthy tasks into different segments that would otherwise abort programs. Threads are mainly used to utilize the processor to a maximum extent by avoiding it's idle time. Threading lets a program seem as if it is executing several tasks at once. What actually happens is, the time gets divided by the computer into parts and when a new thread starts, that thread gets a portion of the divided time. Threads in VB .NET are based on the namespace System.Threading.
Creating Threads
To create threads lets work with an example. The following example is an extract from Steven Holzner's reference, Programming with Visual Basic.NET- Black Book. Open anew windows application and name it as Thread and add a class named count1 using the Projects->Add Class item. This class will count from 1 to a specified value in a data member named CountTo when you call the Count method. After the count has reached the value in CountTo, a FinishedCounting event will  occur. The code for the Count class looks like this:
Public Class Count1
Public CountTo as Integer
Public event FinishedCounting(By Val NumberOfMatches as Integer)
Sub Count()
Dim ind,tot as Integer
tot=0
For ind=1 to CountTo
tot+=1
Next ind
RaiseEvent FinishedCounting(tot)
'makes the FinishedCounting event to occur
End Sub
End Class

Let's use this class with a new thread.  Get back to the main form and create an object of this class, counter1, and a new thread, Thread1. The code looks like this:
Public Class Form1 Inherits System.Windows.Forms.Form
Dim counter1 as new Count1()
Dim Thread1 as New System.Threading.Thread(Address of counter.Count)

Drag a Button and two TextBoxes (TextBox1, TextBox2) onto the form. Enter a number in TextBox1. The reason for entering a number in textbox is to allow the code to read the value specified in TextBox1 and display that value in TextBox2, with threading. The code for that looks like this:
Public Class Form1 Inherits System.Windows.Forms.Form
Dim counter1 as new Count1()
Dim Thread1 as New System.Threading.Thread(Address of counter.Count)
Private Sub Button1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button1.Click
TextBox2.Text=" "
counter1.CountTo=TextBox1.Text
AddHandler counter1.FinishedCounting,AddressOfFinishedCountingEventHandler
'adding handler to handle FinishedCounting Event
Thread1.Start()
'starting the thread
End Sub
Sub FinishedCountingEventHandler(ByVal Count as Integer)
'FinishedCountingEventHandler
TextBox2.Text=Count
End Sub

The result of the above code displays the value entered in TextBox1, in TextBox2 with the difference being the Thread counting the value from 1 to the value entered in TextBox1.
Multithreading

Suspending a Thread
Threads can be suspended. Suspending a thread stops it temporarily. Working with the example in the previous section, add a new button Button2 to the main form. When this button is clicked the thread is suspended. The code for that looks like this:
Private Sub Button2_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button2.Click
Thread1.Suspend()
End Sub

Resuming a Thread
Threads can be resumed after they are suspended. With the example above, add a new button Button3 to the main form. When this button is clicked the thread is resumed from suspension. The code for that looks like this:
Private Sub Button3_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button3.Click
Thread1.Resume()
End Sub

Making a Thread Sleep
Threads can be made to sleep which means that they can be suspended over a specific period of time. Sleeping a thread is achieved by passing the time (in milliseconds,1/1000 of a second) to the thread's sleep method. With the example above, add a new button Button4 to the main form. When this button is clicked the thread is stopped. The code for that looks like this:

Private Sub Button4_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button4.Click
Thread1.Sleep(100/1000)
End Sub

Stopping a Thread
Threads can be stopped with it's abort method. With the example above, add a new button Button5 to the main form. When this button is clicked the thread is stopped. The code for that looks like this:
Private Sub Button5_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button5.Click
Thread1.Abort()
End Sub

Thread Priorities
Threads can also be assigned priority for execution. Thread priority can be set by the thread's Priority property and assigning a value from predefined Thread Priority enumeration.
Values for Thread Priority:
Above Normal -> Gives thread higher priority
Below Normal ->Gives thread lower priority
Normal -> Gives thread normal priority
Lowest -> Gives thread lowest priority
Highest -> Gives thread highest priority
Working with the above example, add a new button Button6 to the main form. When this button is clicked the thread is assigned Highest priority .The code for that looks like this:
Private Sub Button6_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)_
Handles Button6.Click
Thread1.Priority=System.Threading.ThreadPriority.Highest
'setting Highest priority for the thread
End Sub

For more information on Threads please refer to MSDN.

XML SAMPLE CODE

Extensible Markup Language (XML)
The markup language most widely used today is undoubtedly Hyper Text Markup Language (HTML), which is used to create Webpages. A Markup language describes thestructure of the document. HTML is based on Standard Generalized Markup Language (SGML), which is an application of SGML. Webpages designed using HTML are designed using HTML predefined tags. These days, as Internet is used widely as general form of communication and as transferring data over the Internet is becoming more intensive and handling that data more complex many Web Developers are turning to XML as their alternative to HTML. It's worth having a brief overview of this wonderful new Markup Language which is changing the way data is handled on the Internet.
What is XML?
XML is a meta-markup language which means that it lets us create our own markup language (our own tags).
XML is popular for the following reasons:

  • It Allows Easy Data Exchange
  • It Allows to Customize Markup languages
  • Makes the data in the document Self-Describing
  • Allows for Structured and Integrated data
The current version of XML is 1.0 and XML is case sensitive. Let's follow this meta-markup language with an example. Save the following code with a .xml extension.

    <?xml version="1.0" encoding="UTF-8"?>
    <DOCUMENT>
    <WELCOME>
    Welcome to XML
    </WELCOME>
    </DOCUMENT>>

    Breaking the above code for understanding:
    The document starts with the XML processing instruction <?xml version="1.0" encoding="UTF-8"?>All XML processing instructions should start and end with ?xml version="1.0" means the version of XML, which is currently 1.0
     UTF-8 is a 8-bit condensed version of Unicode
    The document starts with the <DOCUMENT> element which may or may not contain other elements within it and should always end with </DOCUMENT>. All other elements should be between <DOCUMENT> and </DOCUMENT> making <DOCUMENT> the root element for this XML page.
     The next element is <WELCOME> between the <DOCUMENT> and </DOCUMENT> and which contains a message, Welcome to XML.
    The above code when opened in a browser looks like the image below.


    To format the content of the elements created in the document we use a style sheet to tell the browser the way the document should be. Alternatively, programming languages like Java and JavaScript can be used. Lets take a look how the above example looks when formatted using style sheet.

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/css" href="style.css"?>
    <DOCUMENT>
    <WELCOME>
    Welcome to XML
    </WELCOME>
    </DOCUMENT>

    The above code includes a new line <?xml-stylesheet type="text/css" href="style.css"?> which means that the type of style sheet being used is CSS (Cascading Style Sheet, XSL can also be used) and it's name is style.css.
    The file style.css looks like this:  WELCOME{font-size:40pt;font-family:Arial; color:red}
    This file states that it's customizing the <WELCOME> element to display it's content in a 40 pt font with arial as it's font and it's color as red.
    You can customize different elements to display their content in different fonts and colors.
    Make sure that the file style.css is saved in the same directory where the xml file is saved. The output after adding the style sheet looks like the image below.


    XML is case sensitive, which means <WeLCOME> and </Welcome> are treated differently. <WELCOME> should be closed with a corresponding</WELCOME> tag.
    Well-Formed XML Documents
    If an XML document is not understood successfully by an XML processor then the processor cannot format the document. To handle that, XML documents are subject to two constraints: well formedness and validity, well formedness being the basic constraint.
    Well-Formed Document
    As set by the W3C, for an XML document to be well formed it should follow the document production containing three parts in the document.
    • prolog
    • root element
    • Optional miscellaneous part

    The prolog should include an XML declaration such as <?xml version="1.0"?>.  It can also contain a Document Type Definition (DTD).
    The root element of a document can hold other elements and the document should contain exactly one root element. All other elements should be enclosed within the root element.
    The optional miscellaneous part can be made up of XML comments, processing instructions and whitespaces.
    Also the XML document should follow the syntax rules specified in the XML 1.0 recommendation set by W3C.
    An example of a well formed document is listed below :

    <?xml version="1.0" encoding="UTF-8"?>
    <DOCUMENT>
    <CONSUMER>
    <NAME>
    <FIRST_NAME>
    BEN
    </FIRST_NAME>
    <LAST_NAME>
    HOLLIAKE
    </LAST_NAME>
    </NAME>
    <PURCHASE>
    <ORDER>
    <ITEM>
    DVD
    </ITEM>
    <QUANTITY>
    1
    </QUANTITY>
    <PRICE>
    200
    </PRICE>
    </ORDER>
    </PURCHASE>
    </CONSUMER>
    <CONSUMER>
    <NAME>
    <FIRST_NAME>
    ADAM
    </FIRST_NAME>
    <LAST_NAME>
    ANDERSON
    </LAST_NAME>
    </NAME>
    <PURCHASE>
    <ORDER>
    <ITEM>
    VCR
    </ITEM>
    <QUANTITY>
    1
    </QUANTITY>
    <PRICE>
    150
    </PRICE>
    </ORDER>
    </PURCHASE>
    </CONSUMER>
    </DOCUMENT>

    Understanding the above document for well-formedness:
    The document starts with a prolog, which is the xml declaration.
    The First element, which is the root element is the <DOCUMENT> element which contains all other elements.
    Next is the <CONSUMER> element inside the root element which is for two consumers.
    For each consumer, their name is stored in the <NAME> element which itself contains elements like <FIRST_NAME> and <LAST_NAME>.
    The details of the purchases which the consumer made is stored in the <ORDER> element in the <PURCHASE> element which in turn contains the elements <ITEM><QUANTITY><PRICE> which records the item purchased, quantity and price which the consumer purchased.
    The document ends with the closing </DOCUMENT> element.
    Data can be stored for as many consumers as wanted and handling such kind of data is not a problem for the XML processor.
    The following are the basic rules that should be kept on mind when creating a Well-Formed XML document.

    • The document should start with an XML declaration
    • The document should be included with one or more elements
    • For elements that are not empty include start and end tags
    • All elements of the document should be contained within the root element
    • Elements should be nested correctly

    Documents like the one above can be extended as long as we can. XML doesn't have any problem handling such kind of documents, as long as they are wellformed.

    Valid XML Documents
    An XML document is said to be valid if it has a Document Type Definition (DTD) or XML schema associated with it and if the document complies with it. DTD's are all about specifying the structure of the document and not the content of the document. And with a common DTD many XML applications can be shared. Such is the importance of a DTD.
    Let's take a look at the example which was created in the section Well-Formed XML documents.

    <?xml version="1.0" encoding="UTF-8"?>
    <DOCUMENT>
    <CONSUMER>
    <NAME>
    <FIRST_NAME>
    BEN
    </FIRST_NAME>
    <LAST_NAME>
    HOLLIAKE
    </LAST_NAME>
    </NAME>
    <PURCHASE>
    <ORDER>
    <ITEM>
    DVD
    </ITEM>
    <QUANTITY>
    1
    </QUANTITY>
    <PRICE>
    200
    </PRICE>
    </ORDER>
    </PURCHASE>
    </CONSUMER>
    <CONSUMER>
    <NAME>
    <FIRST_NAME>
    ADAM
    </FIRST_NAME>
    <LAST_NAME>
    ANDERSON
    </LAST_NAME>
    </NAME>
    <PURCHASE>
    <ORDER>
    <ITEM>
    VCR
    </ITEM>
    <QUANTITY>
    1
    </QUANTITY>
    <PRICE>
    150
    </PRICE>
    </ORDER>
    </PURCHASE>
    </CONSUMER>
    </DOCUMENT>

    Adding a DTD to the example above makes the code look like this:  


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE DOCUMENT[
    <!ELEMENT DOCUMENT (CONSUMER)*>
    <!ELEMENT CONSUMER (NAME,PURCHASE)>
    <!ELEMENT NAME (FIRST_NAME,LAST_NAME)>
    <!ELEMENT FIRST_NAME (#PCDATA)>
    <!ELEMENT LAST_NAME (#PCDATA)>
    <!ELEMENT PURCHASE (ORDER)*>
    <!ELEMENT ORDER (ITEM,QUANTITY,PRICE)>
    <!ELEMENT ITEM (#PCDATA)>
    <!ELEMENT QUANTITY (#PCDATA)>
    <!ELEMENT PRICE (#PCDATA)>
    ]> <?xml version="1.0" encoding="UTF-8"?>
    <DOCUMENT>
    <CONSUMER>
    <NAME>
    <FIRST_NAME>
    BEN
    </FIRST_NAME>
    <LAST_NAME>
    HOLLIAKE
    </LAST_NAME>
    </NAME>
    <PURCHASE>
    <ORDER>
    <ITEM>
    DVD
    </ITEM>
    <QUANTITY>
    1
    </QUANTITY>
    <PRICE>
    200
    </PRICE>
    </ORDER>
    </PURCHASE>
    </CONSUMER>
    <CONSUMER>
    <NAME>
    <FIRST_NAME>
    ADAM
    </FIRST_NAME>
    <LAST_NAME>
    ANDERSON
    </LAST_NAME>
    </NAME>
    <PURCHASE>
    <ORDER>
    <ITEM>
    VCR
    </ITEM>
    <QUANTITY>
    1
    </QUANTITY>
    <PRICE>
    150
    </PRICE>
    </ORDER>
    </PURCHASE>
    </CONSUMER>
    </DOCUMENT>

    Breaking the DTD for understanding:
    Note the first line of the DTD, <!DOCTYPE DOCUMENT[. That line is the document type declaration.<!DOCTYPE> is the syntax to declare a DTD and it should be followed by the root element, which in this example is the DOCUMENT element.
    Each element should be specified with the syntax <!ELEMENT>. Using that declaration we can specify whether each element is a parsed character data (#PCDATA, used for storing plain text) or can contain other elements in it.
    In the example above the CONSUMER element is written like this <!ELEMENT DOCUMENT(CONSUMER)*>.The asterik(*) here indicates that the CONSUMER element can have zero or more occurrences. In the example above, it has two occurrences.
    The next element in the CONSUMER element is the NAME element which in turn contains the elements FIRST_NAME and LAST_NAME within it.
    Both the FIRST_NAME and LAST_NAME elements are declared as #PCDATA which allows them to handle plain text.
    The next element in the DTD is the PURCHASE element with an asterik(*) which means that it has zero or more occurrences.
    The elements within the PURCHASE element is the ORDER element which in turn include the elements ITEM, QUANTITY and PRICE.
    The elements ITEM, QUANTITY and PRICE are declared as #PCDATA as they hold only plain text.
    That's how a basic DTD looks like. A DTD like the one above is said to be an internal DTD. We can also create external DTD's and it's these external DTD's which allows us to share a common XML document within different organizations.
    For more information about how to insert attributes, comments, etc in DTD's please refer to the W3C specification for XML DTD's. The image below shows how the above code when opened in an browser looks like.



    XML WEBSERVICES

    XML Web Services
    Web Service (XML Web Service) is a unit of code that can be activated using HTTP requests. Stated another way, a Web Service is an application component that can beremotely callable using standard Internet Protocols such as HTTP and XML. One more definition can be, a Web Service is a programmable URL. Web Services came into existence to deliver distributed computing over the Internet. A major advantage of the Web services architecture is, it allows programs written in different languages on different platforms to communicate with each other in a standards-based way. Simply said, a Web service is a software service exposed on the Web through SOAP, described with a WSDL file and registered in UDDI.
    Why XML Web Services?
    Today, available technologies like Component Object Model (COM), Remote Method Invocation (RMI), Common Object Request Broker Architecture (CORBA) and Internet Inter-ORB Protocol (IIOP) are used to package application logic into reusable components and are called remotely across multiple platforms. The Internet today consists of tremendous number of heterogeneous systems and a key limitation of all the above said technologies is they are not easily interoperable with these different systems and that limits their effectiveness as a standard method for programming the Web. This is because of the dependencies of these technologies on a particular language or a particular Operating System or Object-model specific protocols. Web Services on the other hand are very different when compared to the said technologies as they are built upon widely accepted standards that can interoperate easily on the Internet. A key to the success of Web Services is that they use a text-based messaging model to communicate which allows them to operate effectively on different platforms.
    Example of a Web Service
    There is already an example in the ".NET Defined" VB.NET section of this Web site. Here is another example similar to that. Consider a commerce site that allows consumers to shop online. After all the shopping has been done this site calculates all the charges and the shipping costs based on a variety of shipping options. This site will havealliances with different shipping companies to ship the products to it's consumers. This site might maintain a set of database tables that describe the shipping options and costs for each shipping company based on their location and services. With this approach, whenever there is a change in shipping options or costs of an existing shipping company change or if a new shipping company forms an alliance with this commerce site and provides it's services the Webmaster of the commerce site has to restructure the database and update them to fit the changes. This approach is not only time consuming but also requires the commerce site to invest extra IT costs to maintain it's database. Now, imagine this commerce site programmatically calling a Web Service on it's site provided by the shipping company. What happens with this approach is, the commerce site can calculate shipping costs based on the shipping option that a consumer specifies in his request and returns the costs in real time. This approach eliminates the need for the commerce site to maintain a separate database table for shipping companies and also all the shipping costs are calculated on the shipping company site and returned to the commerce site in real time.
    Some other applications of Web Services are:
    • Information sources like stock quotes, weather forecasts, sports scores etc that could easily incorporate into applications 
    • Services that provide commonly needed functionality for other services. Example, user authentication, usage billing etc 
    • Services that integrate a business system with other partners
    The image below shows Web Services Architecture.

    Web Services Architecture

    Foundational elements of Web Services
    The .NET Framework provides an excellent foundation for building and consuming Web Services. A key to the broad-reach capabilities of these Web Services is a foundation built on Internet Standards that does not rely on any platform, protocol or OS. This foundation provides the following capabilities to Web Services:
    • A standard method for describing data 
    • A standard message format for communicating request and response 
    • A standard method for describing the capabilities of Web Services 
    • A method to discover what Web Services are available at any site 
    • A method to describe what sites provide Web Services

    SIMPLE PROCEDURE TO SEND EMAILS FROM ASP.NET

    Sending Email with ASP.NET
    One of the common functionalities used in Web development is sending email from a Web page. A common use of sending email from a Web page is allowing site visitors to fill in comments via an HTML form and send them to the Webmaster. The .NET Framework makes the task of sending email from a Web page relatively simple. In order to send an email from an ASP.NET Web page you need to use the SmtpMail class found in the System.Web.Mail namespace, which contains a static method Send.
    Sending Email 
    The namespace that needs to be imported to send an email is the System.Web.Mail namespace. We use the SmtpMail and MailMessage classes of this namespace for this purpose. The MailMessage class provides properties and methods for constructing an email message. To start, open a Web Forms page, drag a Button control on to the form, switch to code view and paste the following code.
    Imports System.Web.Mail
    'namespace to be imported

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
    System.EventArgs) Handles Button1.Click
    Dim mailMessage As New MailMessage()
    'creating an instance of the MailMessage class
    mailMessage.From = "xyz@mydomain.com"
    'senders email address
    mailMessage.To = "abc@sendersemail.com"
    'recipient's email address
    mailMessage.Cc = "carboncopy@sendersemail.com"
    'email address of the Cc recipient
    mailMessage.Bcc = "blindcarboncopy@sendersemail.com"
    'email address of the Bcc recipient
    mailMessage.Subject = "Hello"
    'subject of the email message
    mailMessage.BodyFormat = MailFormat.Text
    'message text format. Can be text or html
    mailMessage.Body = "This tutorial is sending email with an ASP.NET app."
    'message body
    mailMessage.Priority = MailPriority.Normal
    'email priority. Can be low, normal or high
    SmtpMail.SmtpServer = "mail.yourserver.com"
    'mail server used to send this email. modify this line based on your mail server
    SmtpMail.Send(mailMessage)
    'using the static method "Send" of the SmtpMail class to send the mail
    Response.Write("Mail sent")
    'message stating the mail is sent
    End Sub

    The above code sends an email when the button is clicked. That's fine for the purpose of learning but when you have a feedback form on your Web site with textboxes, labels, etc, you need to slightly modify the above code. The following is the complete, functional code for an ASP.NET page that sends an email to the Webmaster of the site.
    To start, drag seven labels, six textboxes and two buttons on to the Web forms page designer. The user interface for this sample can be found at the bottom of this page. The modified code looks as follows:
    Imports System.Web.Mail

    Private Sub SendMail_Click(ByVal sender As System.Object, ByVal e As_
    System.EventArgs) Handles SendMail.Click
    Dim mailMessage As New MailMessage()
    mailMessage.From = TextBox1.Text
    mailMessage.To = "admin@startvbdotnet.com"
    'you also can set this to TextBox2.Text
    mailMessage.Cc = TextBox3.Text
    mailMessage.Bcc = TextBox4.Text
    mailMessage.Subject = TextBox5.Text
    mailMessage.BodyFormat = MailFormat.Text
    mailMessage.Body = TextBox6.Text
    'textbox6 TextMode property is set to MultiLine
    mailMessage.Priority = MailPriority.Normal
    SmtpMail.SmtpServer = "mail.yourserver.com"
    'mail server used to send this email. modify this line based on your mail server
    SmtpMail.Send(mailMessage)
    Label6.Text = "Your mail was sent"
    'message stating the mail is sent
    End Sub

    Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As_
    System.EventArgs) Handles Reset.Click
    TextBox1.Text = " "
    TextBox2.Text = " "
    TextBox3.Text = " "
    TextBox4.Text = " "
    TextBox5.Text = " "
    TextBox6.Text = " "
    'resetting all the value to default i.e null
    End Sub

    Live Code Demo

    Sending Email with ASP.NET
    Label6
    Do not enter any values and click the button. The TextBoxes and Button below are provided to give you an idea about the user interface for the sample mentioned above.
    From      
    To         
    Cc         
    Bcc        
    Subject   
    Message 
       

    asp.net deployment procedure with screen shots

    Deploying ASP.NET Applications
    After creating and testing your ASP.NET application, the next step is to deploy the application. Deployment is the process of distributing the finished application to beinstalled on other computer. We can use the built-in deployment feature that comes with Visual studio .NET to create a Windows Installer file - a .msi file for the purpose of deploying applications.
    Deploying Applications
    To start, open the Web Application project you want to deploy. Say, you have a project named "Deploy" with ten Web pages in it. Select File->Add Project->New Project from the main menu. From the Project Types pane select Setup and Deployment Projects and from the Templates pane select Web Setup Project. Type WebSetup1 for name and specify a location in the location box and click OK. The New project dialogue box looks like the image below.

    When you click OK on the above dialogue box, the project is added to the solution explorer window and also a File System Editor window appears as shown in the imagebelow.

    The File System Editor window has two panes. Select Web Application Folder in the left pane in this window. From the Action menu (on main menu), select Project Output to open the Add Project Output Group dialog box. It looks like the image below.

    Make sure that Deploy is selected in the Project drop-down list and select Primary Output from the list and click OK. You also can select other options depending upon the users of your application.
    Now, in the File System Editor window, select Web Application Folder and open it's Properties window. The Properties window for the Web Application Folder looks like the image below.

    In this window, set the VirtualDirectory property to any name, say FinishedApp. FinshedApp will be the folder on the target machine where you will install this application. The name you set for this VirtualDirectory property should not already exist on the target machine. If it does, the contents in the folder will be overwritten. Also, set theDefaultDocument property to any page in the application. The page you set in this property will be the default page for the Web Application. Once you are finished with the Properties window build the solution by selecting Build->Build WebSetup1 from the main menu. After the solution is built sucessfully, a WebSetup1.msi file is created in the Debug directory of the Web Setup project. The default path to the debug directory is as follows:
    C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\deploy\WebSetup1\Debug.
    Installing the Application
    You can copy the WebSetup1.msi file to the target machine and double-click to install the Web Application. When you double-click the setup file the dialog that opens looks like the image below.

    Click next and you will be taken to the next dialog which looks like the image below.

    You can use the default Virtual Directory specified by the installer or you can specify one. Click next to install the application.

    Deploying ASP.NET Applications
    Using the Copy Project Option
    Another option to deploy your ASP.NET application developed using Visual Studio .NET is to use the copy project option. This option is very helpful if you decide to host your ASP.NET application with a hosting provider. The hosting provider allocates some space for you on his Web server and you are required to deploy your application/Website. To host your ASP.NET application on a hosting provider's server you need to follow these steps.
    The first thing you need to do before deploying any ASP.NET Web application is to change the Active Solution Configuration from Debug to Release as shown below. This allows the compiler to optimize the code, remove debugging related symbols from code and makes the code run much faster. To open the Configuration Manager, right-click on the Web project in the Solution Explorer window and select Project->Properties. The properties dialog box looks like the image below.


    On this dialog, click on Configuration Properties towards the left and click the "Configuration Manager" button towards the right side. The Configuration Manager dialog looks like the image below.


    On this diaolg select Release from the drop-down list found at top-left.
    To copy your Web project onto the target server, select Project->Copy Project from the main menu. Selecting this option will display a dialog box as shown in the imagebelow.


    The Copy Project dialog provides the following options.
    Destination Project Folder
    Used to specify the location to which you want to copy the project. The location can be on the same machine or on a remote server.
    Web access method
    The Web access method option determines the access method that is used to copy the Web project to the destination folder. There two types of Web access methods:
    File share: Allows to directly access the project files on the Web server through a file share.
    FrontPage: Specifies that you want to use the HTTP-based FrontPage Server Extensions to transfer your project files to the server.
    Copy
    The Copy option provides three types which are as follows:

    Only files needed to run this application: Copies built output files (DLLs and references from the bin folder) and any content files (.aspx, .asmx). It is recommended to deploy the application using this default option.
    All project files: Copies built outputs (DLLs and references from the bin folder) and all files that are in the project. This includes the project file and source files.
    All Files in the source project folder: Copies all project files and any other files that are in the project folder (or subfolder) being transferred to the destination folder.
    To copy the Web Application, select your options based on the application type from the above dialog box and click OK. This will result in the ASP.NET Web application being deployed on the target server as shown in the image below.



    Some hosting providers require you to enable FrontPage Extensions on your account which can be done via the control panel.


    Configuring Websites in Windows .NET Server/IIS 6.0
    At times there might be situations where you need to host your ASP.NET applications from your corporate server or your own machine. A scenario where this might be needed is when you have large amounts of data on your Web site and you are concerned about the big bucks your hosting provider will charge you for disk space, bandwidth and database maintenance. Internet Information Services 6 (IIS 6) can be used for hosting your Web site. IIS 6 is a powerful platform for hosting Web sites. Creating and configuring Web sites and Virtual Directories using IIS are as easy as 1-2-3. In this section we will see how we can create a Website using IIS 6.0 and configure it.
    Creating a Website
    The first thing you need before creating a Web site using IIS 6.0 is a unique IP address that identifies your computer on the network. This address takes the form of a string of four numbers separated by periods (.). For your site to be up and running you also need a connection to the Internet. You need to lease a line from an Internet Service Provider (ISP) or a telephone company. When you open IIS Manager in Administrative Tools and select Web sites in the console tree, and right-click on default Web site and open it's properties you will find that the IP address for the default Web site is All Unassigned. This means any IP address not specifically assigned to another Web site on the machine opens the Default Web site instead. A typical use for the Default Web site is to display general information like a corporate logo and contact information.
    Let's assume that we will use the IP address 169.16.13.211 for creating Startvbdotnet.com and C:\Startvbdotnet is the folder where the homepage for this site is located. To create the Startvbdotnet Web site, right-click on the Web Sites node and select New->Web Site to start the Web Site Creation Wizard as shown in the images below.





    Click Next on the Web site creation wizard dialog and type a description for the site as shown in the image below.


    After typing the description click next to open the dialog where you need to specify the IP address and port  number for your Web site. As mentioned above, type 169.16.13.211 in the IP address textbox and 80 in the TCP port textbox. The dialog looks like the image below.


    Click Next and specify C:\Startvbdotnet as the home directory for the site. Notice the checkbox that says "Allow anonymous access to this Web site". By default, it ischecked, which means the Web site which we are creating is accessible by general public on the Internet. If you are creating an intranet site which will be used only by authenticated users then you need to uncheck this checkbox. The image below displays that.


    Click Next to get to the Web Site Access Permissions dialog. By default, the Read and Run scripts checkboxes are checked which means that your Web site will run scripts such as ASP and is only a read-only Web site where users can't make changes to it. If you want users to download content from your Web site, modify it and upload the modified content then you need to check the Write checkbox. The image below displays that.


    Click Next and then Finish to create the new Web site. The image below displays the new Web site which we created in IIS.





    Configuring Websites in Windows .NET Server/IIS 6.0
    Virtual Directories
    virtual directory is a friendly name, or alias, either for a physical directory on your server hard drive that does not reside in the home directory, or for the home directory onanother computer. Because an alias is usually shorter in length than the path of the physical directory, it is more convenient for users to type. The use of aliases is also secure because users do not know where your files are physically located on the server and therefore cannot use that information to modify your files. Aliases also make it easier for you to move directories in your site. Rather than changing the URL for the directory, you change the mapping between the alias and the physical location of the directory.
    You must create virtual directories if your Web site contains files that are located in a directory other than the home directory, or on other computer's hard drive. To use a directory on another computer, you must specify the directory's Universal Naming Convention (UNC) name, and provide a user name and password for access rights.
    Also, if you want to publish content from any directory not contained within your home directory, you must create a virtual directory.
    Creating a Virtual Directory
    Let's say Startvbdotnet keeps their contacts in a folder called C:\StartvbdotnetContacts on their web server and would like users to be able to use the URL http://169.16.13.211/contacts when they need to access contact information. To do this we need to create a virtual directory that associates the /contacts portion of the URL, the alias for the virtual directory, with the physical directory C:\StartvbdotnetContacts where these documents are actually located.
    To create a new virtual directory, right-click on Startvbdotnet Web site and select New->Virtual Directory to start the Virtual Directory Creation Wizard. The images below display that.




    Click Next and type the alias for the virtual directory, say, contacts as shown in the image below.


    Click Next and specify the physical folder on the local server to map to this alias. The physical folder on the server is C:\StartvbdotnetContacts. The image below shows that.


    Click Next and specify permissions for this Virtual Directory as shown in the image below.


    Click Next and finish the virtual directory creation wizard. The images below displays the result. You can
    see the new virtual directory, contacts, with a gear symbol in the IIS wizard.




    When users type http://169.16.13.211/contacts in their browser they will be shown a page with contact information for Startvbdotnet Web site. What actually happens is the content comes from a directory located outside the Web site directory but the address bar in the browser shows that the directory is part of the Web site.


    Configuring Websites in Windows .NET Server/IIS 6.0
    Controlling Access to Web Site
    Now that we created a Web site and a virtual directory we will look at some of the administrative tasks that are required to control the Web site. The settings in this article apply only to Startvbdotnet Web site which we created in IIS and not to all Web sites under IIS. The procedure is same if you want to set the properties for all Web sites. If you want to set the following properties for all Web sites under IIS then you need to right-click on Web Sites in IIS and select properties from the menu and follow the steps which are mentioned in this article.
    When you right-click on the Startvbdotnet Web site in IIS and select properties, the properties window that is displayed looks like the image below.


    As you might notice from the above image the dialog box displays information as tabs, all of which are discussed below.
    Web Site Information (Web Site Tab)
    By defaut, the Web site tab is displayed when you right-click and select properties for any of the Web sites in IIS. The information under Web site tab is discussed below.
    Web site identification
    The Web site identification part displays general information like the description of the Website, IP address and the port number it is using.
    Connections
    Connection timeout
    Connection timeouts are used to reduce the amount of memory resources that are consumed by idle connections. Time-out settings also allow you to specify how long server resources are allocated to specific tasks or clients. The default connection timeout setting set by IIS is 120 seconds which means that when a visitor accesses your site and has no activity on your site for 2 mins his connection will be timed out.
    Enable HTTP Keep-Alives
    Most Web browsers request that the server keep the client connection open while the server sends multiple  elements like .htm files and .gif or .jpeg files to the client. Keeping the client connection open in this way is referred to as an HTTP Keep-Alive. Keep-Alive is an HTTP specification that improves server performance. HTTP Keep-Alives are enabled by default in IIS.
    Enable Logging
    The logging feature allows you to collect information about user activity on your site. Information such as who has visited your site, what the visitor viewed, and when the information was last viewed, etc, can be collected with this feature. The default logging format is the W3C Extended Log File Format. You can also change the logging format based on your preferences. To change the logging format you need to make a selection from the active log format drop-down list.
    To set how often you want your new log file to be created click the properties button to open the Logging Properties dialog as shown in the image below.


    The Logging Properties dialog shown in the image above allows you to record log information on an hourly basis or daily or weekly or monthly basis or based on file size. If you select the Weekly option then a log file is created once every week. You can also change the location of the log file on your server in the Logging Properties dialog.
    Performance (Performance Tab)
    The Performance tab let's you control the performance of your Web site, like, setting the amount of bandwidth per second and allowing the number of simultaneous connections accessing the Web site at a given time. The dialog looks like the image below.


    Bandwidth throttling
    If the network or Internet connection used by our Web server is also used by other services such as e-mail, then we might want to limit the bandwidth used by our Web server so that it is available for those other services. If our Web server hosts more than one Web site, you can individually throttle the bandwidth used by each site. By default, bandwidth throttling is disabled. If you want to enable it, check the checkbox and enter the bandwidth you want in kbps.
    Web site connections
    Connection limits restrict the number of simultaneous client connections to our Web site. Limiting connections not only conserves memory but also protects against malicious attacks designed to overload our Web server with thousands of client requests. By default, unlimited connections are allowed. If you want to limit the number of connections then you need to select the "Connections limited toradio button and enter the number of connections you want to access your site at a given time.
    Home Directory
    The Home Directory tab in the properties dialog for the Web site is displayed below.


    As you can see from the image above, the content for this Web site comes from the local path on the server. If you want the content for this Web site to come from another computer located on a network you need to select the radio button which says "A share located on another computer" and enter the computer on the network.
    Redirecting
    Sometimes when your site is experiencing technical difficulties or if you are doing maintenance you need to redirect visitors to another site or to another page informing what is going on. IIS lets you  redirect a Web site to a different file or folder on the same machine or to an URL on the Internet. To configure redirection you need to select the "A redirection to a URL" radio button under the home directory and choose the redirection option you want to use and specify the path as shown in the image below.






    Configuring Websites in Windows .NET Server/IIS 6.0
    Controlling Access to Web Site
    Custom Errors
    You can configure Internet Information Services (IIS) to send default HTTP 1.1 error messages or custom error messages. Custom error messages can be mapped to a file name or to a URL. The image below displays Custom Errors dialog.


    You can also configure your own custom error messages. To do that, click the HTTP error that you want to change, and then click Edit to open the Edit Custom Error Properties dialog as shown in the image below.


    To configure your own custom error, in the Message Type list box, click either File to return a custom error file or URL to direct the request to a custom error URL on the local machine.
    Note that you cannot customize the following errors: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.
    Documents (Documents Tab)
    The Documents dialog is displayed in the image below.


    Enable default content page
    The enable default content page lets you designate the default page for your Web site. You can specify names such as index.aspx, default.aspx, login.aspx, etc. To add a new type you need to click the Add button and add the file which you want to be displayed to your users when they first enter your site.
    Enable document footer
    The enable document footer option lets you add a HTML formatted footer to each and every document on your site. By default, it is disabled.
    HTTP Headers (HTTP Headers Tab)
    The HTTP Headers dialog looks like the image below.


    Enable content expiration
    By default, this is disabled. If you enable content expiration and set a date then the content on your site expires after the set date. If you notice from the above image, the content for Startvbdotnet is set to expire on Tuesday, Februrary 23, 2010 at 12 AM.
    Content rating
    Content rating allows to classify your site from four predefined values which are Violence, Sex, Nudity and Language. By default, content rating is disabled. To enable content rating, click the edit Ratings button to open the Content Ratings dialog as shown in the image below.


    In the Content Ratings dialog, enable the checkbox which says Enable ratings for this content and select a category under which your site falls and drag the track bar to indicate the level of the rating. You can also include an email address for contact and set an expiration date for this content as shown in the image above.
    Directory Security (Directory Security Tab)
    The Directory Security dialog looks like the image below.

    Authentication and access control
    Authentication and access control allows us to setup access to our site using Authentication Methods. If you click the Edit button the Authentication Methods dialog that is displayed looks like the image below.


    By default, the enable anonymous access checkbox is checked which means that your site will be accessed by everyone using the IUSR_COMPUTERNAME (default IIS account). If you want to enforce restrictions and want users to be authenticated before they access your site you need to set it in this dialog.
    IP address and domain name restrictions
    The IP address and domain name restrictions allows us to grant or deny access to users based on their IP address. If you click the Edit button the IP Address and Domain Name Restrictions dialog that is displayed looks like the image below.


    By default, all computers will be granted access. If you want to deny/block a particular user or a group of computers then you need to select the Denied access radio buttonand click the Add button to open the Grant Access dialog as shown in the image below.



    If you want to block a single computer enter the IP address of the machine and click OK. If you want to deny a group of computers then select the Group of computers radio button and enter the network address and Subnet mask number to deny that group. If you want to deny users based on a domain name the select the Domain name option and enter the domain name.
    Starting and Stopping Web site
    You can start and stop a Web site in IIS manager. To start a Web site, select the Web site, right-click on it and from the menu select start/stop as shown below.