From Visual Studio.net 2003 to 2010

I shall start the journey by using Visual Studio.net 2003 before looking at migrating to VS.net 2005, Vs.net 2008 and Vs.net 2010.

My environment is Windows Professional XP installed on a XP Virtual Machine on a Dell Inspiron 14R powered by Windows 7-64 bits.

Microsoft SQL Express 2008/R2 serves as the database server

Friday, February 10, 2012

What are ASP.Net Pages ?

ASP.Net pages can be identified by the file extension .aspx. Conceptually they work along the same lines as conventional ASP pages although the whole process is applied to the .Net Framework. In an ASP.Net page the code is separated from the document mark up; this simplifies the layout and understanding of the document. Place holders are used to determine where areas of active content should be inserted into the document by the web server. The code which has now been separated from the document mark up is then stored either at the top of the document within script bocks or preferably in a separate file called a Code Behind File. Separating the code into code behind files allows the code to be compiled into a single file stored on the web server ready to service any web requests.

The process for viewing an ASP.Net page is that the end user requests the web page (in this case the ASP.Net document) using a web browser. The request is sent by the web browser across the internet to the web server. The web server receives this request, identifies the document is an ASP.Net document and gathers any dynamic content from the precompiled file. Any instructions are processed in accordance with this file and the results rendered as HTML which is inserted back into the document where the placeholders indicate. This new document is passed back across the internet to the web browser. The web browser receives this file and displays the document content in accordance with the instructions contained within the HTML.
Web server Request Response
One of the great strengths of ASP.Net is that the platform it is capable of rendering different HTML code according to the version and type of browser that made the web request. So ASP.Net can generate different HTML code for different circumstances and this is completed without intervention by the programmer. In theory the programmer prepares the website content and instructs ASP.Net how it should be displayed and then the code generated should be correct for the users platform, whether a standard computer or a third generation mobile telephone device. In practise this is still in its infancy and a programmer needs to be aware of what code will be generated and for what platforms.

More at http://www.codefixer.com/asp-net/tutorials/what-is-asp-net.asp

Creating a web application using VS.net 2003

When using Visual Studio 2003 you first need to understand some of the terms and concepts involved.

Visual Studio 2003 primarily works using “Solutions” and each and every “Solution” can have one or more “Projects”. A “Solution” is basically a collection of “Projects” which work together in a unified logical fashion to fulfil some type of task or objective.

A “Project” can be for example a web project or some other type of project such as a web service or class that has some inbuilt functionality, but normally within the “Solution” each of the “Projects” will have some kind of common purpose.

For our purposes here we will have one “Solution” which will contain one “Project”. To create a new web application in Visual Studio 2003 complete the following:

1. Open Visual Studio 2003 by double clicking on the icon on your desktop.

2. By default Visual Studio will present you with the “Start Page” which will display a list of previous projects along with hyperlink buttons to either open an existing project or create a new project. If you have an existing project you can simply select it from the list of available projects on the start page. As we do not, we will create a new project by clicking on “New Project” at the bottom of the “Start Page” to open the “New Project” dialog box. If you don’t see the “Start Page” when you open Visual Studio you can open the “New Project” dialog box by selecting “File” then “New” and “Project” from the File Menu. This can be seen in Figure 6.
Visual Studio Project

Figure 6
3. You will notice that the “New Project” dialog box is very similar in layout to the “New File” dialog box of Web Matrix.

4. Under “Project Types” on the left side select “Visual Basic Project” and then under “Templates” on the right hand side select “ASP.Net Web Application”.

5. You will then need to provide a name for the “Web Application” by amending the name “WebApplication1” in the Location box. For my purposes I have replaced this with “rras”. Note also that in the Location box you can select a web server on which you wish to create this web application. This can be any web server to which you have access and appropriate user rights.

6. Once you are happy with the information that you have entered click on OK and Visual Studio will create your Web Application for you. Note you may be prompted for appropriate Username and Password details for the web server.

Once the project has been created you should see the Solution Explorer open at the side of Visual Studio and a new web form created ready for use. Note that the Solution Explorer can be docked so this can be located any where within the working environment and it may be dragged to the location which best suits your working practises. Within the Solution Explorer you will see listed your first Project and within that a number of newly created files useful for your web application.

Visual Studio 2003 has created a web application for you on the web server and also created a new folder within your “Solutions and Projects” area to store this new solution/project. If you wish to know where the “Solutions and Projects” are stored you can find out by opening the Visual Studio options by selecting “Tools” and then “Options” from the File menu. Open the “Environment” folder by selecting this on the left hand side and then view the Project locations under settings on the right hand side. You may choose to move this to a preferred location.

If you look at the base of WebForm1 which is open in the workspace, you are presented with two options.
· Design - a WYSWYG view of your web page
· HTML - a view of the HTML code within the page

Note also that if you do change to the HTML view by clicking on HTML at the base of the page some of the code has been prepared for you.

Change back to Design View, right click on the web page and then select Properties from the list of options and you will be presented with the “Document Properties” dialog box. There are a number of settings here but for now select the “Page Layout” property and change it from “Grid Layout” to “Flow Layout”. Select “OK” and Visual Studio will change the page mode to “Flow Layout”.

We won’t go into this here but “Flow Layout” is the normal layout used by most web developers when working with HTML (this has been changed in the coming release of Visual Studio 2005 where “Flow Layout” will be the default option).

Now type some text on the web page and then press return on your keyboard. To view this page within a web browser you can select “File” and then “View in Browser” from the file menu. Visual Studio will first save your open documents, and then compile any code which has been written before running the web page in your web browser.

Conclusion

In the first case we used the built in tools and wizards from the IIS Management Console to manually create a sub web within the Default Web Site. The IIS Management Console has a range of tools for both creation of web sites and managing them on an ongoing basis. A basic understanding of the options will be of use as at some stage it will certainly be necessary to resort to these tools to fix issues that may arise.

Finally, we used Visual Studio to create a new Solution which contained a single Project (our web site). Visual Studio created this for us along with the necessary files within a sub web of the Default Web Site of IIS. Visual Studio also created our first web page which could be viewed using a web browser across the web server.


More at :
http://www.codefixer.com/asp-net/tutorials/creating-a-web-application-using-visual-studio.asp

How to use Visual Studio.net 2003 in Windows Vista ?

This blog entry is intended to illustrate the steps necessary to set up a Windows Vista machine to use Visual Studio 2003 (.NET 1.1).  Most of the information was obtained from the following blogs:
More at http://keylimetie.com/blog/2008/1/17/using-vs7-in-vista/

See also http://msdn.microsoft.com/en-us/vstudio/bb188244.aspx

What is AssemblyInfo.cs ?

AssemblyInfo.cs file is created automatically when you create a windows application by VS in the same folder as Global.asax and web.config and "Properties" folder by VS 2005. It also get created, when you create any Web Application project. It does not create for Website project in Visual Studio.

It contains the version information that will go into your app or assembly - things like the company name, copyright notices etc., and the assembly version number, of course.

You can inspect those values in Windows Explorer by right-clicking on an .EXE or .DLL, go to "Properties", and then go to the "Version" tab - those pieces of info in there come from whatever you fill into "AssemblyInfo.cs" in your project.

Solution with Multiple Projects

Visual Studio creates an AssemblyInfo.cs file for each project in a solution in a 'Properties' folder. However, more often than not, I'm more interested in an application's version than the individual assembly's version, and the solution is the application. So I find that each time I create a solution with multiple projects (assemblies) I add a 'Common' project that has an AssemblyInfo.cs file to be used by all other projects. That way all assemblies have the same version information.

To do this delete the AssemblyInfo.cs file in each project and then 'Add Existing item' browse to the common AssemblyInfo.cs and add as link. This way all projects share the same

AssemblyInfo.cs file. Unfortunately Visual Studio does not allow adding any items to the 'Properties' folder.

See also

.Net Tips — use a shared AssemblyInfo.cs for your solution

Working with Global.asax

The Global.asax file, sometimes called the ASP.NET application file, provides a way to respond to application or module level events in one central location. You can use this file to implement application security, as well as other tasks. Let's take a closer look at how you may use it in your application development efforts. 
 
Overview
The Global.asax file is in the root application directory. While Visual Studio .NET automatically inserts it in all new ASP.NET projects, it's actually an optional file. It's okay to delete it—if you aren't using it. The .asax file extension signals that it's an application file rather than an ASP.NET file that uses aspx. 
 
The Global.asax file is configured so that any direct HTTP request (via URL) is rejected automatically, so users cannot download or view its contents. The ASP.NET page framework recognizes automatically any changes that are made to the Global.asax file. The framework reboots the application, which includes closing all browser sessions, flushes all state information, and restarts the application domain.
Programming 
 
The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assigns them to applications as needed. The Global.asax file contains the following events:

  • Application_Init: Fired when an application initializes or is first called. It's invoked for all HttpApplication object instances.
  • Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.
  • Application_Error: Fired when an unhandled exception is encountered within the application.
  • Application_Start: Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
  • Application_End: Fired when the last instance of an HttpApplication class is destroyed. It's fired only once during an application's lifetime.
  • Application_BeginRequest: Fired when an application request is received. It's the first event fired for a request, which is often a page request (URL) that a user enters.
  • Application_EndRequest: The last event fired for an application request.
  • Application_PreRequestHandlerExecute: Fired before the ASP.NET page framework begins executing an event handler like a page or Web service.
  • Application_PostRequestHandlerExecute: Fired when the ASP.NET page framework is finished executing an event handler.
  • Applcation_PreSendRequestHeaders: Fired before the ASP.NET page framework sends HTTP headers to a requesting client (browser).
  • Application_PreSendContent: Fired before the ASP.NET page framework sends content to a requesting client (browser).
  • Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.
  • Application_ReleaseRequestState: Fired when the ASP.NET page framework completes execution of all event handlers. This results in all state modules to save their current state data.
  • Application_ResolveRequestCache: Fired when the ASP.NET page framework completes an authorization request. It allows caching modules to serve the request from the cache, thus bypassing handler execution.
  • Application_UpdateRequestCache: Fired when the ASP.NET page framework completes handler execution to allow caching modules to store responses to be used to handle subsequent requests.
  • Application_AuthenticateRequest: Fired when the security module has established the current user's identity as valid. At this point, the user's credentials have been validated.
  • Application_AuthorizeRequest: Fired when the security module has verified that a user can access resources.
  • Session_Start: Fired when a new user visits the application Web site.
  • Session_End: Fired when a user's session times out, ends, or they leave the application Web site.
The event list may seem daunting, but it can be useful in various circumstances.
A key issue with taking advantage of the events is knowing the order in which they're triggered. The Application_Init and Application_Start events are fired once when the application is first started. Likewise, the Application_Disposed and Application_End are only fired once when the application terminates. In addition, the session-based events (Session_Start and Session_End) are only used when users enter and leave the site. The remaining events deal with application requests, and they're triggered in the following order:

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_AuthorizeRequest
  • Application_ResolveRequestCache
  • Application_AcquireRequestState
  • Application_PreRequestHandlerExecute
  • Application_PreSendRequestHeaders
  • Application_PreSendRequestContent
  • <<code is executed>>
  • Application_PostRequestHandlerExecute
  • Application_ReleaseRequestState
  • Application_UpdateRequestCache
  • Application_EndRequest
More at http://www.techrepublic.com/article/working-with-the-aspnet-globalasax-file/5771721

What is Global.asax ?

The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules. The Global.asax file resides in the root directory of an ASP.NET-based application. At run time, Global.asax is parsed and compiled into a dynamically generated .NET Framework class derived from the HttpApplication base class. The Global.asax file itself is configured so that any direct URL request for it is automatically rejected; external users cannot download or view the code written within it.


The ASP.NET Global.asax file can coexist with the ASP Global.asax file. You can create a Global.asax file either in a WYSIWYG designer, in Notepad, or as a compiled class that you deploy in your application's \Bin directory as an assembly. However, in the latter case, you still need a Global.asax file that refers to the assembly.

The Global.asax file is optional. If you do not define the file, the ASP.NET page framework assumes that you have not defined any application or session event handlers.

When you save changes to an active Global.asax file, the ASP.NET page framework detects that the file has been changed. It completes all current requests for the application, sends the Application_OnEnd event to any listeners, and restarts the application domain. In effect, this reboots the application, closing all browser sessions and flushing all state information. When the next incoming request from a browser arrives, the ASP.NET page framework reparses and recompiles the Global.asax file and raises the Application_OnStart event.

More at http://msdn.microsoft.com/en-us/library/1xaas8a2%28v=vs.71%29.aspx

Thursday, February 9, 2012

What is web.config ?

Web.config is the main settings and configuration file for an ASP.NET web application.

The file is an XML document that defines configuration information regarding the web application. The web.config file contains information that control module loading, security configuration, session state configuration, and application language and compilation settings. Web.config files can also contain application specific items such as database connection strings.

Configuration settings for any of your ASP.NET Web applications can be stored in a simple text file. Presented in an easily understandable XML format, this file, called Web.config, can contain application-wide data such as database connection strings, custom error messages, and culture settings.

Inheritance
Each web application in ASP.NET inherits their base web.config from the machine's web.config located in \System Root\Microsoft.NET\Framework\Version Number\machine.Config

Interesting Links

A Beginner's view : Web.config

ASP.NET Web.config File Demystified

How To Create the Web.config File for an ASP.NET Application

AppSettings In web.config 

http://www.codefixer.com/asp-net/tutorials/web.config.asp


WEB.CONFIG as auto-created by clicking New Project in VS.net 2003 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   
  <system.web>

    <!--  DYNAMIC DEBUG COMPILATION
          Set compilation debug="true" to enable ASPX debugging.  Otherwise, setting this value to
          false will improve runtime performance of this application.
          Set compilation debug="true" to insert debugging symbols (.pdb information)
          into the compiled page. Because this creates a larger file that executes
          more slowly, you should set this value to true only when debugging and to
          false at all other times. For more information, refer to the documentation about
          debugging ASP.NET files.
    -->
    <compilation
         defaultLanguage="c#"
         debug="true"
    />

    <!--  CUSTOM ERROR MESSAGES
          Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
          Add <error> tags for each of the errors you want to handle.

          "On" Always display custom (friendly) messages.
          "Off" Always display detailed ASP.NET error information.
          "RemoteOnly" Display custom (friendly) messages only to users not running
           on the local Web server. This setting is recommended for security purposes, so
           that you do not display application detail information to remote clients.
    -->
    <customErrors
    mode="RemoteOnly"
    />

    <!--  AUTHENTICATION
          This section sets the authentication policies of the application. Possible modes are "Windows",
          "Forms", "Passport" and "None"

          "None" No authentication is performed.
          "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
           its settings for the application. Anonymous access must be disabled in IIS.
          "Forms" You provide a custom form (Web page) for users to enter their credentials, and then
           you authenticate them in your application. A user credential token is stored in a cookie.
          "Passport" Authentication is performed via a centralized authentication service provided
           by Microsoft that offers a single logon and core profile services for member sites.
    -->
    <authentication mode="Windows" />

    <!--  AUTHORIZATION
          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
          (unauthenticated) users.
    -->

    <authorization>
        <allow users="*" /> <!-- Allow all users -->
            <!--  <allow     users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny      users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
            -->
    </authorization>

    <!--  APPLICATION-LEVEL TRACE LOGGING
          Application-level tracing enables trace log output for every page within an application.
          Set trace enabled="true" to enable application trace logging.  If pageOutput="true", the
          trace information will be displayed at the bottom of each page.  Otherwise, you can view the
          application trace log by browsing the "trace.axd" page from your web application
          root.
    -->
    <trace
        enabled="false"
        requestLimit="10"
        pageOutput="false"
        traceMode="SortByTime"
        localOnly="true"
    />

    <!--  SESSION STATE SETTINGS
          By default ASP.NET uses cookies to identify which requests belong to a particular session.
          If cookies are not available, a session can be tracked by adding a session identifier to the URL.
          To disable cookies, set sessionState cookieless="true".
    -->
    <sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false"
            timeout="20"
    />

    <!--  GLOBALIZATION
          This section sets the globalization settings of the application.
    -->
    <globalization
            requestEncoding="utf-8"
            responseEncoding="utf-8"
   />
  
 </system.web>

</configuration>