ASP.NET 4.0 Roadmap

Take a walk through the 4.0 landscape from ASP.NET and learn how you can get involved in shaping ASP.NET future. This talk focuses on the next release of ASP.NET including Web Forms and MVC. Do you love web forms? See how you can taking control of your control IDs, learn about better ViewState managment in GridView and ListView, and get more control over the CSS markup of ASP.NET server controls. See how Dynamic Data makes building you data-driven apps easy. If you’re interested in AJAX, we show you further advancements in client rendering and binding. If you’re considering MVC, we look at the feature set and understand how to create applications with this technology.

 

Via Dot Net TV

Professional ASP.NET 2.0 XML

Product Description

  • The foundation for most Web services, XML can also be used with ASP.NET to display data from an infinite variety of sources in a Web site
  • After covering the basics, the book explores the many ways that XML documents can be created, transformed, and transmitted to other systems using ASP.NET 2.0
  • Two major case studies address issues such as reading and writing XML data, XML data validation, transforming XML Data with XSLT, SQL Server XML integration, XML support in ADO.NET, and XML Web Services

 

An Overview of HTTP Handlers

An HTTP handler is a process that runs on server to response to a particular type of request. HTTP handlers can be referred to as endpoint also. A typical example of HTTP handlers is when ASP.net page handler which is used by asp.net engine to process the request that come for .aspx files.

Built In HTTP Handlers in ASP.net

Handler Description
ASP.net Page Handler (*.aspx) A default page handler for all ASP.net pages.
Web Service handler(*.mspx) The default HTTP handler for Web service pages created as .asmx files in ASP.NET.

Generic Web handler (*.ashx)

The default HTTP handler for all Web handlers that do not have a UI and that include the @ WebHandler directive.

Trace handler (trace.axd)

A handler that displays current page trace information. For details, see How to: View ASP.NET Trace Information with the Trace Viewer.

 

How to Create A Custom HTTP Handler

To create a custom HTTP Handler you need to implement either IHttpHandler or IHttpAsyncHandler for synchronous and asynchronous handlers. Both these interfaces expose two methods called IsReusable and ProcessRequest. ProcessRequest method is the place where you write code for handling request of your custom handler. The IsReusable property specifies whether the IHttpHandlerFactory object (the object that actually calls the appropriate handler) can put the handler in a pool and reuse it to increase performance. If the handler cannot be pooled, the factory must create a new instance of the handler every time that the handler is needed.

Public Class CustomHand
    Implements IHttpHandler


    Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
        Get

        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest

    End Sub
End Class

Mapping File Extension in IIS

By Default IIS is going to respond to file extension that is for custom handler. If you created a new file extension for HTTP Handler then you have to explicitly register the file extension in IIS and have to add a mapping entry in web.config file for your custom handler.

ASP.Net Exception Handling-Part I

.Net languages support structured exception handling means when ever an exception occurs .Net framework creates an exception object, this exception object represents complete information about the exception. You can catch this exception object using the try catch block code if your application failed to catch the exception then you see a error page like this

Exception Handling

Structured Exception Handling Features

  • Exceptions are objects means each exception wrapped with significant amount of useful information about exception instead of just plain text explaining the exception message or cause of exception. These exception objects also support an InnerException property that allows you to wrap a generic error over the more specific error that caused it. You can even create and throw your own exception objects.
  • Exception can be caught based on their type means you can catch specific type of exception following code show an example of this
Try
    IO.File.Open("F:\testfile.text", IO.FileMode.Open)

Catch ex As IO.FileNotFoundException
    Console.WriteLine("File Not found")
Catch ex As IO.PathTooLongException
    Console.WriteLine("File Path is to long")
End Try

  • Exception handlers can also be used in layered manner means you can always create exception handlers on top of other exception handlers for different section of code to handle their exception separately.
  • Exceptions are generic part of .Net framework.

 

Exception Class Overview

Exception class is base class for all exception classes. Exception class defines two type of exceptions

  • SystemException: This class provides a means to differentiate exception caused by system or application. SystemException does not provide information about the cause of exception and try to avoid throwing instance of this class , if there are cases when you want to throw or created object of this class , a human readable message describing the error should be passed to the constructor.
  • ApplicationException: The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system. If you are creating your own exception class then it is always advised to derive custom exception class from Exception class. Deriving custom exception class from ApplicationException class does not add any significant value to derived class.

Exception Class Properties

Exception includes a number of properties that help identify the code location, the type, the help file, and the reason for the exception: StackTrace, InnerException, Message, HelpLink, HResult, Source, TargetSite, and Data.

In Next article we will discuss more about exception class members and how to write a exception handling block.

ASP.NET State Management Overview

As HTTP is stateless, meaning the connection to the server does not remain open. When ever page is post back to server a new instance of the class is created this means there is a overhead of loading all the values associated with controls that are present on the page because http is a stateless protocol and each round trip to the server causes controls to loose their values. To overcome the inherent limitation of http protocol ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows:

View state

View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings. This information is then put into the view-state hidden field or fields.

Control state

Control state is used to store the state information specific to control. This property is very useful when you are creating custom control and want to know the current state of control.  AS compare to view state property which can be turned off by developer at page level and that can cause your control to break, in case of control state property that can not be turned off like view state.

Hidden fields

Hidden fields are controls that provide a way to store information and at the same time they are not visible to the user. When a page is submitted to the server, the content of a hidden field is sent in the HTTP form collection along with the values of other controls. A hidden field acts as a repository for any page-specific information that you want to store directly in the page. It is easy to see and modify the hidden field value so it is always recommend that never store sensitive information in Hidden field.

Cookies

Cookies are basically small text files that are used to store small amount of data on client file system. Cookies can also be stored in clients main memory. Cookies can be temporary (with specific expiration times and dates) or persistent. Generally cookies are used to store information about a particular client, session or application. When a client send a request to the server, browser also sent the cookie to the server, Server then extracts value from the cookie. Typically cookies are encrypted and used for storing user authentication information and user profile preferences.

Response.Cookies("destination").Value = "CA"
Response.Cookies("destination").Expires = DateTime.Now.AddDays(1)

Query strings

Query String is a key value pair that is appended at the end of url with a question mark (?). Query string is a very simple way to send information to the server but it is highly browser dependant. Different browsers have different length for query string. Information passed through query string is easily viewed by the client so query string is not a good option for sending sensitive information to the server.

View state, control state, hidden fields, cookies, and query strings all involve storing data on the client in various ways.

Application state

Application state is a data repository available to all classes in an ASP.NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Unlike session state, which is specific to a single user session, application state applies to all users and sessions. Therefore, application state is a useful place to store small amounts of often-used data that does not change from one user to another. Application state is stored in an instance of the HttpApplicationState class. This class exposes a key-value dictionary of objects. The HttpApplicationState instance is created the first time a user accesses any URL resource in an application. The HttpApplicationState class is most often accessed through the Application property of the HttpContext class.

Application("WelcomeMessage") = "Welcome to the Contoso site."

Session state

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session. By default, ASP.NET session state is enabled for all ASP.NET applications.

Session("FirstName") = FirstNameTextBox.Text
Session("LastName") = LastNameTextBox.Text

Profile Properties

Profile property is a new feature in ASP.ne that allow you to store user specific data this some thing like session but profile information is not lost when a user session is expire. The profile-properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database. In addition, the profile makes the user information available using a strongly typed API that you can access from anywhere in your application. You can store objects of any type in the profile. The ASP.NET profile feature provides a generic storage system that allows you to define and maintain almost any kind of data while still making the data available in a type-safe manner.

Profile.PostalCode = txtPostalCode.Text

You must define the PostalCode property in the Web.config file by using the following markup:

<profile>
    <properties>
      <add name="PostalCode" />
    </properties>
  </profile>

Application state, Session state, and profile properties all store data in memory on the server.

We will discuss each of the state management feature in more detail in upcoming articles. some of the definitions are taken from MSDN

ASP.NET State Management

As we all know that HTTP is a stateless protocol means when after each request client is disconnected from server and ASP.net discards objects that were created for the page. Drawback of this architecture is that you have to store the information between the server request while on the other side this architecture enable web applications to scale up and servers can responds to thousands of simultaneous requests without running out of server
memory.

ASP.net includes a variety of state management options. A developer can choose right option for state management option depending upon data you need to store, duration for which data has to be stored, data scope and security and performance considerations.

There are three options available for state management in ASP.net

  • View State
  • Query String
  • Custom Cookies
  • Caching
  • Profiles

In addition to this you can also write a custom state management module for your application and use database or file system for storing state information but this will bring some performance issues to your application because for retrieving and storing state information you need to establish database connections. 

we will discuss asp.net management options in more details in upcoming posts.

Overview of Language Integrated Query

Language Integrated Query is one of the feature that ship with .Net Framework 3.5. LINQ is a set of language extension that allows developers to write queries using full power programming that they are using, programming language might be C#, VB or any of the .Net supported language.  In a simplest form LINQ defines keywords that a developer can use to build queries. LINQ expressions allows developers to select, sort,filter, group and transform data.

Same LINQ expression can be used with different type of data sources. For example, LINQ to Objects, the simplest form of LINQ, allows you to query collections of in-memory objects. LINQ to DataSet performs the same feat with the in-memory DataSet. Even more interesting are the two LINQ flavors that let you access external data: LINQ to SQL, which allows you to query a SQL Server database without writing data access code, and LINQ to XML, which allows you to read an XML file without using .NET’s specialized XML classes.

Let’s start with how LINQ work with in memory collections. This is called LINQ to objects or simple LINQ. LINQ to objects allows developers to eliminate logic of for each loop.

For example, imagine you want to get a list of all website that have a word .net

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        ' Get the full collection of website from a helper method.
        Dim websitelist As List(Of Website) = Website.getWebsite
        'find a mathching website
        Dim matches As List(Of Website) = New List(Of Website)
        For Each websitename As Website In websitelist
            If websitename.websitename.Contains(".net") Then
                matches.Add(websitename)
            End If
        Next
    End Sub

Now perform the same task using LINQ

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
    Dim websites As New List(Of Website)
    Dim matches As IEnumerable(Of Website)
    matches = From websitename In websites Where websitename.websitename.Contains(".net") Select websitename

End Sub

Website Class Code

Public Class Website
    Public websitename As String
    Public websiteurl As String

    Public Sub New(ByVal websitename As String, ByVal websiteurl As String)
        Me.websitename = websitename
        Me.websiteurl = websiteurl

    End Sub
    Public Shared Function getWebsite() As List(Of Website)
        Dim weblist As New List(Of Website)
        Dim web1 As New Website("Microsoft", "http://microsoft.com")
        weblist.Add(web1)
        Dim web2 As New Website("MSDN", "http://msdn.microsoft.com")
        weblist.Add(web2)
        Dim web3 As New Website("All About ASP.Net", "http://allaboutasp.net")
        weblist.Add(web3)
        Dim web4 As New Website("ReadersZone", "http://readerszone.com")
        weblist.Add(web4)
        Dim web5 As New Website("ASP.net", "http://asp.net")
        weblist.Add(web5)
        Dim web6 As New Website("Silverlight", "http://silverlight.net")
        weblist.Add(web6)
        Return (weblist)

    End Function

End Class

Public Class Website
    Public websitename As String
    Public websiteurl As String

    Public Sub New(ByVal websitename As String, ByVal websiteurl As String)
        Me.websitename = websitename
        Me.websiteurl = websiteurl

    End Sub
    Public Shared Function getWebsite() As List(Of Website)
        Dim weblist As New List(Of Website)
        Dim web1 As New Website("Microsoft", "http://microsoft.com")
        weblist.Add(web1)
        Dim web2 As New Website("MSDN", "http://msdn.microsoft.com")
        weblist.Add(web2)
        Dim web3 As New Website("All About ASP.Net", "http://allaboutasp.net")
        weblist.Add(web3)
        Dim web4 As New Website("ReadersZone", "http://readerszone.com")
        weblist.Add(web4)
        Dim web5 As New Website("ASP.net", "http://asp.net")
        weblist.Add(web5)
        Dim web6 As New Website("Silverlight", "http://silverlight.net")
        weblist.Add(web6)
        Return (weblist)

    End Function

End Class

ASP.NET MVC Source Code is Available Under the Microsoft Public License

At Mix 2009 Microsoft has released the ASP.NET MVC 1.0 and after that Microsoft released the source code of ASP.NET MVC 1.0 source code under the Microsoft Public License (MS-PL).  MS-PL is an OSI-approved open source license.  The MS-PL contains no platform restrictions and provides broad rights to modify and redistribute the source code.  You can read the text of the MS-PL at: http://www.opensource.org/licenses/ms-pl.html.

Now with source code third party developers can also modify the source code according to their requirements and share with developer community. ASP.NET MVC 1.0 is also adopted by Mono project team

Download ASP.NET MVC

Click here to download and install ASP.NET MVC 1.0.  You can also install it using the new Microsoft Web Platform Installer V2 – which provides an integrated setup experience for the entire Microsoft web stack.

The ASP.NET MVC 1.0 source code is now available.  Scroll down to the bottom of the ASP.NET MVC download page and you’ll find links to both the ASP.NET MVC 1.0 integrated MSI setup, as well as a .zip file that contains the ASP.NET MVC source code.  The ASP.NET MVC source code includes a VS 2008 project file that enables you to build it.

ASP.net Special Folder

To have a convenient folder and file structure help web developers and designers to manage their web application in a efficient manner. With the release of .Net Framework 2.0, ASP.net reserves the some folder names, so developers can put special files in these folders.

App_Browser 

ASP.net reserve this folder name for storing browser definition files. Browser definition files are used to determine the client browser capabilities. Browser definition files have .browser extension.

App_Code

App_code folder can contain source code for utility classes as well business objects. Classes that are present in App_Code folder are automatically complied when your web application complied. Arbitrary file types can be placed in the App_Code folder to create strongly typed objects. For example, placing Web service files (.wsdl and .xsd files) in the App_Code folder creates strongly typed proxies. Code present in App_Code is automatically referenced by ASP.net Application.

App_Data

App_Data is used to store file that can be used as database files including MDF files, XML files, as well as other data store files. App_Data folder is used by ASP.net application for storing ASP.net application local database. Developers can also use this folder for storing data for their ASP.net Application.

App_GlobalResources

App_GlobalResources folder contains resources files that are complied into assemblies and these assemblies are available in Global scope. Resource files are strongly typed and can be accessed programmatically.

App_LocalResources

App_LocalResources folder also contain the same files that are being contained by App_GlobalResources  but files located in this folder are only available to a particular project, web page, master page or web user control.

App_Themes

App_Themes folder used by ASP.net to store files that are being used to define the look and feel of web application. App_Themes folder store skin, CSS and image files. Skin files are files have .skin file extension.

Bin

Bin folder contains complied assemblies(.dll) files for web user controls, classes or for components.

Technorati Tags: , , , , , ,

Overview Of ASP.net

Microsoft ASP.net

ASP.net is a web technology built on top of Microsoft .net framework. Microsoft released the first version of .net framework in 2002 called .net 1.0. ASP.net is successor of Microsoft’s Active server pages technology. ASP.net application are built on top of .Net CLR so they utilize the full power of all .Net framework supported languages. Traditional ASP pages have a number of limitations and application created in ASP were difficult to manage and they faced a significant performance and scalability issues. To overcome all these issues, Microsoft to come up with a new framework that will offer a clean separation code from the design. Some of the differences between ASP.net and ASP:

  • ASP.net programming model is completely object oriented. Apart from the object oriented support ASP.net applications are event driven, control based architecture.
  • Developers can use any programming languages included by Microsoft or any other third party programming languages for developing ASP.net applications. ASP.net applications can also be developed in multiple languages also.

Key Features of ASP.net

  • ASP.NET Is Integrated with the .NET Framework: .Net framework provide a massive collection of functionality and ASP.net application can utilize the same .Net framework classes as other .Net framework application like Windows or any other type of applications using .Net framework.
  • ASP.net Applications Are Complied: One of the biggest advantage with ASP.net applications is that they are always complied manes you can’t run any ASP.net application without compiling the code. When the code is compiled, it is translated into a language-independent and CPU-independent representation called Microsoft Intermediate Language (MSIL). At run time, MSIL runs in the context of the .NET Framework, which translates MSIL into CPU-specific instructions for the processor on the computer running the application.
  •   ASP.NET Is Object-Oriented: ASP.net follow completely object oriented programming model. ASP.net applications   have full access to all objects in the .NET Framework, but you can also exploit all the conventions of an OOP (object-oriented programming) environment. For example, you can create reusable classes, standardize code with interfaces, extend existing classes with inheritance, and bundle useful functionality in a distributable, compiled component.