September 8th, 2009 by virat.kothari §
Table of contents
- Introduction
- Define Tiers for the Application
- Role of Tiers
- Implementing CLR Stored Procedure in LINQ based n-tier Architecture Step by Step
- Steps to Create Architecture
- Using the code
- Conclusion
- Points of Interest
- History
Introduction
This article is a sequence of my previous article about “CLR Stored Procedure & creating it step by step”. In my previous article I have explained CLR Stored Procedure, benefits & drawbacks of it and also how to implement it. CLR Stored Procedure is very powerful and gives better results while executing complex logic, intense string operation or string manipulations, cryptography, accessing system resources and file management, etc. Development of any project in n-tier architecture is different taste and having its own benefits and drawbacks. Microsoft has launched LINQ i.e. Language Integrated Query with .net framework 3.0. LINQ can be implemented in variety of ways for e.g. LINQ with SQL, LINQ with objects, LINQ with dataset and LINQ with xml etc. I have implemented simple n-tier architecture few years back in my company. It is suitable for both web as well as desktop applications. It is a centralized n-tier architecture i.e. all the objects are resides at the same place in the target system. I don’t claim this as best but I have implemented this architecture as I want at least following benefits out of it.
- It must be secure, easy to implement and easy to deploy
- It must be tiered based and at least 3 tiered so that if we change code of any tier, we need to deploy dll of that tier only.
- Single architecture for web and desktop application with standard application performance
- Parallel development should be possible i.e. one developer can work with database, another can work with business logic and one more can work with user interface and so on
- No in-line SQL queries
- It must not be complex so that new developer can easily set on development without undergoing long training and existing developers can be easily migrated to and from any of the projects as basic development architecture of all the projects will remain same
Define Tiers for the Application
Now, let me explain various tiers of the architecture. Any good architecture will consist at least 3 important tiers viz. 1) User Interface or Presentation Layer 2) Business Logic Layer 3) Data Layer. The architecture which I am going to explain have 5 tiers. Any architecture having more than 3 tiers is called n-tier architecture. Following image will clarify it.

Following is the image showing architecture in our application. It contains following 4 tiers (see image) and 1 database so total 5 tiers.

Role of Tiers
Let me explain each of above tier in brief.
- Tier – 1: Presentation Layer: This layer will be responsible for various activities between Users and application. All the user interface related logic will reside at this layer. That means web forms or Win forms will reside here. This layer does not have direct access to the database or Data Access Layer. So, all the data goes in or comes out to Presentation Layer will be through the Business Logic Layer only. A reference of Business Logic Layer will be added to this layer. A separate project will be there for this layer.
- Tier – 2: Business Logic Layer: Business Logic Layer will perform all the Business Logics of the application. Business logic consists of two things viz., Core business logic and Data access logic. Data access logic is been segregated to different layer to provide more security and data encapsulation to the application. There will be a separate class for each table of the database to provide better management, in this layer. This class will have various methods. Business logic will be applied to data coming from or going to Presentation Layer and Data Access Layer. A reference of Data Access Layer will be added to this layer. A separate project will be there for this layer.
- Tier – 3: Data Access Layer: This layer is a part of Business logic but is separated from core business logic. All the data related operations between application and database will be performed over here. This layer will be created using “LINQ”. One LINQ to SQL class will be created over here and all the needed database tables or Stored Procedures will be dragged and dropped over here. This layer will have minimum manual coding. A separate project will be there for this layer.
- Tier – 4: CLR Stored Procedure Layer: This layer will be responsible for defining various CLR Stored Procedures. There will be a separate class for each table of the database to provide better management, in this layer. This layer is not directly associated with Presentation Layer, Business Logic Layer or Data Access Layer. CLR Stored Procedure will be deployed to SQL server. A separate project will be there for this layer. To know, what is CLR Stored Procedure and how to create it refer my article “CLR Stored Procedure and Creating It Step by Step”.
- Tier – 5: Database: This is core data and other objects to maintain and access it. For e.g. SQL server database. Core data is data in various tables and objects to maintain & access such data are various tables, Stored Procedures, CLR Stored Procedures, Views and Functions etc.
Physically there are 5 layers but logically they are 4 layers as assembly of CLR Stored Procedure will be the part of Database at the time of deployment.
To add reference of one project to another project is very simple. Just right click on the project >> Click on Add Reference. A dialog box will be displayed. Select “Projects” tab and select appropriate project in the list of projects. Click “OK” button. We can not add circular reference within project for e.g. In our case, Presentation Layer refers to Bussiness Layer and Business Layer refers to Data Access Layer. Now, we can not add reference of Presentation Layer to Data Access Layer as it will create circular reference.
Implementing CLR Stored Procedure in LINQ based n-tier Architecture Step by Step
Let us implement CLR Stored Procedure in LINQ based n-tier architecture. I have listed all SQL statements used for creating database, creating table, inserting dummy records in the table, etc. in the script attached with this article.
Application Development Specification
- IDE: Visual Studio 2008
- Framework: 3.5 with SP 1
- Language: C# 3.0
- Database: Microsoft SQL Server 2005 Express edition
- Operating system: Windows XP with SP 2
Steps to Create Architecture
1. Open Microsoft Visual Studio 2008 >> Create New Project. A dialog box will be opened. Select, Visual C# >> Windows on left side “Project Types” panel. Select, “Windows Forms Application” on right side “Templates” panel. Give proper name to project, solution and select location to save this solution. This project will be our presentation layer. Following image will make it clear.

A default form with the name “Form1” will be created with the project. Rename it to “Demo”. Design it as shown in following image. There is a Label control for heading, one Data Grid View control, a Group Box control to hold various buttons viz., Get Data, Insert Random Record, Delete Selected Record, Clear Grid and Exit. Following image will make it clear.

2. Right click on Solution, click on Add >> New Project. A dialog box will be opened. Select, Database Projects >> Microsoft SQL Server >> SQL CLR on left side “Project Types” panel. Select, “SQL Server Project” on right side “Templates” panel. Give proper name to project and select location to save this solution. This project will be our CLR Stored Procedure Layer. Follow the steps I have explained in my article “CLR Stored Procedure and Creating It Step by Step” to add CLR Stored Procedure in this project. Following image will make it clear.

Right click on the project >> Select Add >> Add New Items. A dialog box will be displayed as shown in following image. Select Visual C# Items from left “Categories” panel. Select Stored Procedure from right side “Templates” panel. Give proper name to it.

3. Right click on Solution, click on Add >> New Project. A dialog box will be opened. Select, Visual C# >> Windows on left side “Project Types” panel. Select, “Class Library” on right side “Templates” panel. Give proper name to project and select location to save this solution. This project will be our Business Logic Layer. I have added two classes to this project i.e. 1) “ConvertToDataTable” and 2) “CustomerSalesInformation”. “ConvertToDataTable” class has various methods to convert array of objects to DataTable or DataSet. CustomerSalesInformation class consist various methods to Insert a record, Delete a record and Get records from database. Following image will make it clear.

4. Once again, Right click on Solution, click on Add >> New Project. A dialog box will be opened. Select, Visual C# >> Windows on left side “Project Types” panel. Select, “Class Library” on right side “Templates” panel (same as step 3). Give proper name to project and select location to save this solution. This project will be our Data Access Layer.
5. Right click on “DataAccessLayer” project, Select Add >> New Item option from the menu. A dialog box shown in following image will be displayed. Select on Visual C# Items in left side “Categories” panel and “Linq to SQL Classes” in right panel “Templates”.

6. Open Server explorer and click on “Connect to database” button given at
top-middle of the server explorer window. It will start a new wizard to
connect to the database. Now drag and drop Stored Procedures
“CustomerSalesInformationDelete” and
“CustomerSalesInformationInsertRandomRecord”. Do NOT drag and drop
“CustomerSalesInformationGet” right now as we need to change it. I have
added “AccessData” class to add various useful methods and variables to
be used on Business Logic Layer. Write now I have declared one private
object of “LinqToSqlDataContext” and exposed it using property “Call”.
Following images will make it clear. Change the connection string I
have statically wrote while declaring object of “LinqToSqlDataContext”.

7. I have suggested not to drag and drop “CustomerSalesInformationGet” because it is a Stored Procedure which does not contain any SELECT query. That is why if you drag and drop it in .dbml file, the return type of the method of the said Stored Procedure will be “int” instead of ISingleResult and so it will not produce any result which we are expecting from this Stored Procedure. You can see this in .cs file of dbml. The work around I am going to explain is not the standard way but it works fine. Let me know if you find any better option. Following are the steps of the work around.
Step 1: Go to query analyzer and drop the Stored Procedure “CustomerSalesInformationGet” which was automatically created at the time of deploying CLR stored procedure, using following SQL statement.
DROP PROCEDURE [dbo].[CustomerSalesInformationGet]
Step 2: Create new stored procedure with the same name as stored procedure created at the time of deploying CLR stored procedure, using following SQL statements.
CREATE PROCEDURE [dbo].[CustomerSalesInformationGet]
AS
BEGIN
SELECT * from CustomerSalesInformation
END
Step 3: Now come to the Visual Studio and refresh the “Stored Procedure” element of the tree view. You can simply right click on the element and click on “Refresh” option of the menu or cliking on refresh icon at the top-left of Server Explorer. Now drag and drop “CustomerSalesInformationGet” stored procedure to the .dbml file. This will create a method for the said stored procedure with the return type “ISingleResult”. You can verify this in .cs file of dbml. So this will return the result per our expectation.
Step 4: Once again go to query analyzer and drop the manually created stored procedure “CustomerSalesInformationGet” using following SQL statement.
DROP PROCEDURE [dbo].[CustomerSalesInformationGet]
Step 5: Now come to the Visual Studio and Right click on “ClrStoredProcedureLayer” project and click on “Deploy” option of the menu. This will deploy CLR stored procedure to the database once again. Now do NOT drag and drop this stored procedure to the dbml file otherwise we have to repeat this whole work around.
8. You have to change connection at two places while using my sample source code.
1. In the “AccessData.cs” file where we have declared an object of “LinqToSqlDataContext”. Following will clarify this.
private static LinqToSqlDALDataContext objLinqToSqlDALDataContext = _
new LinqToSqlDALDataContext("Data Source=OM\\SQLEXPRESS;Initial Catalog=DbForClrDemo;User ID=sa;Password=airborne");
2. In the “CLRStoredProcedureLayer” project. Right click on the said project in solution explorer and click on “Properties”. A screen like following image will be displayed. Select “Database” tab and change the connection string at “Connection String” option where a textbox and Browse button is given.

9. Save the whole solution. Right click on the solution in solution explorer and click on “Build” option. Now, you can run the application by hitting F5. A dialog box will be opened as shown in following image. Click on “Get Data” button, it will retrieves records from the database and loads in to the grid. “Insert Random Record” will insert random record in the table and once again retrieves records from the database and loads in to the grid. “Delete Selected Record” deletes the selected record. “Clear Grid” button clears the records from the grid. “Exit” button will close and exit the application. Following is the demo of the same.

Using the Code
- Download the zip files for source code and sql script and extract them
- Create Database and tables using “Script to create Database and Table.sql”. Also, insert records in the table using same file
- Change connections at 2 places in application as explained in Step 8
- Run the demo.
- When you hit “Get Data” button for the first time, it will take little time to fetch data from database. Now, hit “Clear Grid” button and hit “Get Data” button once again, you will realize the speed. Also, try to hit “Insert Random Record” button continuously for many time. It inserts record to the database and fills the grid at every hit, but still see the speed of it.
- This will give little slow performance in web application than windows application.
Conclusion
Clr Stored Procedures can be efficiently implemented in n-tier architecture
Suggestion
Refer my another article “CLR Stored Procedure and Creating It Step by Step”
Points of Interest
- Exploring IMultipleResult in LINQ.
History
- 08th September, 2009: Initial release
using System;
using System.Windows.Forms;
using BusinessLayer;
namespace ClrInNTierPresentationLayer
{
/// <summary>
/// Represents demo form for the application
/// </summary>
public partial class frmDemo : Form
{
#region Constructor
/// <summary>
/// Constructor of the application
/// </summary>
public frmDemo()
{
InitializeComponent();
}
#endregion
#region Event Handler
#region Buttons
/// <summary>
/// Handles Click event of the button
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void btnGetData_Click(object sender, EventArgs e)
{
try
{
FillDataGridView();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Handles Click event of the button
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void btnInsertRandomRecord_Click(object sender, EventArgs e)
{
try
{
CustomerSalesInformation.CustomerSalesInformationInsertRandomRecord();
FillDataGridView();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Deletes selected record from the database
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void btnDeleteSelectedRecord_Click(object sender, EventArgs e)
{
try
{
if (dgvData.Rows.Count > 0)
{
if (MessageBox.Show(“Are you sure to delete selected record?”, “Confirmation”, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
CustomerSalesInformation.CustomerSalesInformationDelete(Convert.ToDouble(dgvData.CurrentRow.Cells["ID"].Value.ToString()));
FillDataGridView();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Handles Click event of the button
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void btnClearGrid_Click(object sender, EventArgs e)
{
try
{
dgvData.DataSource = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Handles Click event of the button
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void btnExit_Click(object sender, EventArgs e)
{
try
{
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion
#endregion
#region Private Methods
/// <summary>
/// Fills the data in the DataGridView
/// </summary>
private void FillDataGridView()
{
try
{
//Filling the grid with data
dgvData.DataSource = CustomerSalesInformation.CustomerSalesInformationGet();
//Formating the columns of the grid
dgvData.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dgvData.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dgvData.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dgvData.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion
}
}
June 22nd, 2009 by nikunj.padaliya §
In this article I have explained how to use CSS and jQuery function together.
I will give one example in which I have used CSS for textbox and one jQuery function for validation like numeric value and maximum 3 character allowed.
Example:
Create a CSS for textbox in which height, weight, border, font, text-align etc. is defined.
<style type =”text/css” >
.txt1
{
text-align :center ;
width :60px;
height :22px;
border: 1px solid #000000;
font-family: verdana;
font-size: 10pt;
font-weight:bold ;
}
</style>
Write jQuery function for validation for numeric value and maximum length of the textbox. Bind this function to textbox stylesheet on keypress event.
<script type =”text/javascript” >
$(document).ready(function (){
$(“.txt1″).bind(“keypress”,function(){
var str = (event.srcElement).value;
var len1 = str.length;
if (len1 > 2)
{
event.returnValue=false;
if(!(event.keyCode==45||event.keyCode==46||event.keyCode==48|| event.keyCode==49||event.keyCode==50||event.keyCode==51|| event.keyCode==52||event.keyCode==53||event.keyCode==54|| event.keyCode==55||event.keyCode==56||event.keyCode==57))
{
event.returnValue=false;
}
});
});
</script>
Now apply the CSS to the textbox.
<asp:TextBox ID=”Textbox1″ runat=”server” CssClass=”txt1></asp:TextBox>
By applying this CSS on textbox user can only enter numeric value upto 3 characters and also we have a good looking textbox.
I hope this simple solution will help you somewhere in your project.
» Read the rest of this entry «
June 13th, 2009 by vivek.navadia §
As we have discussed how to build the rendered control earlier, it is one step ahead in building custom controls. Earlier we have built the custom control starting from scratch. If you don’t want to start from scratch when building a custom control, you can build a composite control. When you create a composite control, you create a new control from existing controls.
Every ASP.NET control has a Controls property that represents all of its child controls. If you add child controls to a control, then the child controls are automatically rendered when the parent control is rendered.
Lets start from the beginning, Creating NumericTextBox (Only accepts Numeric values, else it give error message through validator.) is shown below. Create new VB Web Application Project and let’s name it NHSWebApplication. After Creating Web Application project just right click on App_Code folder (if not in solution then first create folder named App_Code) and add one class file named NumericTextBox.vb.
Note: Any code added to the App_Code folder is compiled dynamically.
The Code of NumericTextBox.vb file is as shown below
Namespace NHSWebApplication
Public Class NumericTextBox
”Inherit the control from Base Class CompositeControl
Inherits CompositeControl
”Declaring TextBox Web Control
Private NumericTextBox As TextBox
”Declaring ReqularExpressionValidator Web Control
Private NumericExpressionValidator As RegularExpressionValidator
”Overriding CreateChildControlMethod
Protected Overrides Sub CreateChildControls()
”Instanciate TextBox Control
NumericTextBox = New TextBox
”Assigning ID to text box control
NumericTextBox.ID = “txtNumericTextBox”
”Adding control
Me.Controls.Add(NumericTextBox)
”Instanciate RegularExpression Control
NumericExpressionValidator = New RegularExpressionValidator
”Assigning ID to RegularExpressionValidator Control
NumericExpressionValidator.ID = “vdtNumericExpressionValidator”
”Assigning Basic Properties to RegularExpressionValidator
NumericExpressionValidator.ControlToValidate = “txtNumericTextBox”
NumericExpressionValidator.ValidationExpression = “[0-9]*”
NumericExpressionValidator.ErrorMessage = “Invalid Inputs”
NumericExpressionValidator.Display = ValidatorDisplay.Dynamic
”Adding Cotnrol
Me.Controls.Add(NumericExpressionValidator)
End Sub
End Class
End Namespace
Here Class NumericTextBox is inherited from the base class CompositeControl. Two webcontrols Textbox and RegularExpressioValidator are declared.
Typically one has to override a control’s CreateChildControls() method. This method is called when a control builds its collection of child controls. In this method the objects of Textbox and RegularExpressionValidator are initialized and the some of the properties are set in order to get desired output.
”Assigning ID to text box control
NumericTextBox.ID = “txtNumericTextBox”
”Assigning ID to RegularExpressionValidator Control
NumericExpressionValidator.ID = “vdtNumericExpressionValidator”
”ID of controls that needs to be validate
NumericExpressionValidator.ControlToValidate = “txtNumericTextBox”
” Regular Expression that only accepts numeric values (0 to 9)
NumericExpressionValidator.ValidationExpression = “[0-9]*”
” Informative Message that needs to display on wrong input
NumericExpressionValidator.ErrorMessage = “Invalid Inputs”
Now just build your application and then add new Web Form. Let’s say TestCustomControl.aspx. Open its design view or HTML view and see the Toolbox. You will find the custom control named NumericTextBox. Just drag it on Design view or html code. See sample code of ASPX Page below.
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Testing Composite Control</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<cc2:NumericTextBox ID=”NumericTextBox1″ runat=”server” />
</div>
</form>
</body>
</html>
It will render the Textbox in browser with RegularExpressionValidator. The regular expression restict user to input non-numeric values. If any non-numeric values entered in textbox then it will show message ‘Invalid Inputs’. Here in this example, the message is kept static. You can always make it dynamic by creating properties of composite control and passed it from HTML.
By extending the properties of existing web control you can create more helpful composite controls. Hope this article will help to understand building custom composite control.
June 8th, 2009 by vivek.navadia §
The two basic types of controls are fully rendered and composite controls. When you build a fully rendered control, you start from scratch. You specify all the HTML content that the control renders to the browser. When you create a composite control, on the other hand, you build a new control from existing controls.
Typically, when building a basic control, you inherit your new control from one of the following base classes:
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.CompositeControl
The CompositeControl class inherits from the WebControl class, which inherits from the Control class. Each of these base classes adds additional functionality.
Building Rendered Controls
Let’s start by creating a simple fully rendered control. When you create a fully rendered control, you take on the responsibility of specifying all the HTML content that the control renders to the browser.
Create new VB Web Application Project from File Menu and let’s name it NHSWebApplication. After Creating Web Application project just right click on App_Code folder (if not in solution then first create folder named App_Code) and add one class file name TestControl.vb.
Note: Any code added to the App_Code folder is compiled dynamically.
The Code of TestControl.vb file is as shown below
‘Namespace Declared
Namespace NHSWebApplication
‘TestContril Class is inherited from base class CONTROL
Public Class TestControl
Inherits Control
‘Declaring Local Variables for Getting and Setting Value of ROWS and COLUMNS attribute
‘assigned from HTML code of ASPX page
Private _Rows As Integer
Private _Columns As Integer
‘Declaring Properties (Attributes) of control to set ROWS from HTML code of ASPX Page
Public Property Rows() As Integer
Get
Return _Rows
End Get
Set(ByVal value As Integer)
_Rows = value
End Set
End Property
‘Declaring Properties (Attributes) of control to set COLUMNS from HTML code of ASPX Page
Public Property Columns() As Integer
Get
Return _Columns
End Get
Set(ByVal value As Integer)
_Columns = value
End Set
End Property
‘Overrides the RENDER method to draw html content
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
writer.RenderBeginTag(HtmlTextWriterTag.Table)
‘First loop to create Rows
For i As Integer = 0 To _Rows – 1
writer.RenderBeginTag(HtmlTextWriterTag.Tr)
‘Inner loop to Create Columns
For j As Integer = 0 To _Columns – 1
writer.AddAttribute(“Style”, “border:solid 1px #000000″)
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(“Rendering Costom Control”)
writer.RenderEndTag()
Next
writer.RenderEndTag()
Next
End Sub
‘End of the Rendering of Custom control
End Class
End Namespace
As we see in above code RENDER method is override and the object of HtmlTextWriter class is passed to HTML Tag that needs to be rendered. For example
writer.RenderBeginTag(HtmlTextWriterTag.Table) same as <Table>
writer.RenderBeginTag(HtmlTextWriterTag.Tr) same as <tr>
writer.RenderBeginTag(HtmlTextWriterTag.Td) same as <td>
Attributes of each of the Tag is added using
writer.AddAttribute(“Style”, “border:solid 1px #000000″)
and it is same as
style=”border:solid 1px #000000)
so After each iteration it will create specified row and columns with specified format.
Now just build your application and then add new Web Form. Let’s say TestCustomControl.aspx. Open its design view or HTML view and see the Toolbox. You will find the custom control named TestControl. Just drag it on Design view or html code. See sample code of ASPX Page below.
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<cc2:TestControl ID=”TestControl1″ runat=”server” Rows=”2″ Columns=”3″>
</cc2:TestControl>
</div>
</form>
</body>
</html>
It will render a custom control on web form with Table having 2 rows and 3 columns with 1px Black border
|
Rendering Costom Control
|
Rendering Costom Control
|
Rendering Costom Control
|
|
Rendering Costom Control
|
Rendering Costom Control
|
Rendering Costom Control
|
Hope, this article will help you to understand how to build custom rendered control. I will write about building composite control soon.
May 29th, 2009 by nishant.shah §
What is Adobe Flex ?
Adobe Flex is a software development kit released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written using Adobe Flash Builder or by using the freely available Flex compiler from Adobe.
Adobe Flex takes you to the next level of web application development with the concept of Rich Internet Application(RIAs).You may have seen applications developed natively in Flash itself and realized that it offers a much more robust experience for the user where productivity is bolstered by ease of use,streamlined workflow,and real time interactivity that is impossible to accomplish in HTML itself. However developing rich applications in Flash for those who are core developers is daunting and unintuitive. The Flash development tool is geard for designers, and developing on a timeline is a strange concept. Flex removes that barrier entry by providing a programmatic way for developing these RIAs.
Flex is very prominent and familiar with professional developers. Flex is a set of products designed in an effective way based on efficient delivery of high performance.
Flex is a standard-based programming model for high performance rich internet applications. Flex application will take advantage of adobe flash player 9 and this will enable developer to extend the capabilities enables the client with richer applications in real time.
Flex is a cross-platform development framework for creating Rich Internet Applications(RIAs). A component based tool that you can use to develop apps that run using Flash player or Adobe Air. Adobe Flex Builder software is an Eclipse based IDE for developing RIAs.
Basics of Flex :
- Runs in the Flash Player or AIR.
- Tag based markup MXML serves as the basis for Flex Projects.
- MXML is a custom XML namespace,looks like <mx:MyTag></mx:MyTag>.
- Component based development : Containers / Layouts Components , UI Elements , Data Connectors.
- ActionScript 3 can be used to add behaviors or other interactivity not covered by MXML.
- Supports common OOP practices like MVC patterns,code behind,etc.
- MXML components can be brought onto the canvas via the GUI similar to Dreamweaver or VisualStudio.
- Markup can be written by hand with code assist, too. Again, similar to Dreamweaver or VisualStudio.
- MXML components have attributes that allow for modification of appearance or behavior.
- Components can be extended for additional capabilities or reuse via MXML or AS or a combo of both.
- Containers control layout (Canvas, Vertical Box, Horizontal Box)
- UI components display data, control interactivity or display states or other visual feedback (Datagrids, lists, buttons, selects menus,radio buttons, etc.).
- Data components load or send data (Services, XML, Remoting, etc).
- Other tags include: Script, Style, etc.
- Tags can be nested similar to HTML/XML.
Release history :
- Flex 1.0 – March 2004
- Flex 1.5 – October 2004
- Flex 2.0(Alpha) – October 2005
- Flex 2.0 Beta 1 – February 2006
- Flex 2.0 Beta 2 – March 2006
- Flex 2.0 Beta 3 – May 2006
- Flex 2.0 Final – June 28,2006
- Flex 2.0.1 – January 5,2007
- Flex 3.0 Beta 1 – June 11,2007
- Flex 3.0 Beta 2 – October 1,2007
- Flex 3.0 Beta 3 – December 12,2007
- Flex 3.0 – February 25,2008
- Flex 3.1 – August 15,2008
- Flex 3.2 – November 17,2008
- Flex 3.3 – March 4,2009
What is Flex Builder ?
Macromedia recently released Flex Builder (formerly known as “Brady”), an IDE based on Macromedia Dreamweaver MX 2004. Bundled with the Flex application server, Flex Builder provides a WYSIWYG environment for creating Flex applications, an integrated debugger, and code hinting for ActionScript and MXML (plus all of the features supported by Dreamweaver).
The IDE still shows some rough edges. For example, clicking “Help” in the “Manage Sites” dialog launches “Using Dreamweaver,” not “Using Flex Builder.” So, if you get stuck in the middle of defining a new Flex site, you won’t have access to Flex Builder’s excellent support documents. In test instances, opening any “On Demand” video tutorials launched Mozilla-even though it wasn’t set as the default browser.
Perhaps the best way to get a sense of the productivity benefits of Flex Builder is to compare it to Macromedia’s other Flash IDE, Macromedia Flash MX 2004 Professional. Both IDEs support a component called “Accordion” that provides a compact interface widget for showing and hiding information. A Flash developer can drag the Accordion component to the stage, but to populate it with data must use the ActionScript Accordion.createChild() method to instantiate a UIObject or link an existing symbol. It’s not rocket science, but it is time consuming. A developer working with Flex Builder, on the other hand, can simply drag an Accordion container to the stage and populate it with drag-and-drop controls such as form widgets or images. The difference in productivity is an order of magnitude. Think of Flex Builder as Visual Studio.NET Light for Flash.
Advantages of Flex :
-
Flex applications can be intuitive, easy to use, and almost have the feel of the desktop.
-
Easy to program and deploy.
-
Can be deployed right now on 50% or more of the world’s browsers, with ubiquity increasing daily.
-
Dedicated IDE based on Dreamweaver available now.
-
Doesn’t require a large client installation like the .NET runtime.
-
Extensive Visual component library.
-
Powerful coding tools.
-
Scalable and reliable solution.
-
Superb Flex programming model.
-
Easy Integration into a server application.
-
High performance data synchronization engine.
-
Interactivity due to video, audio, streaming and messaging components.
Disadvantages of Flex :
Examples :
May 29th, 2009 by nikunj.padaliya §
Security is one of the most important concerns in application software development. Building a robust security model is one of the most important factors that drive the success of application software. As far as security in ASP.NET is concerned, three terms come into my mind, i.e., Authentication, Authorization and Impersonation. Put simply, authentication authenticates the user’s credentials and authorization relates to the resources that an authenticated user has access to. This article is the first in a series of articles on ASP.NET security and discusses these concepts and their applicability.
Let us start our discussion with a brief outline on the sequence of events are as far as authentication and authorization are concerned when a new request comes in. When a new request arrives at IIS, it first checks the validity of the incoming request. If the authentication mode is anonymous (default) then the request is authenticated automatically. But if the authentication mode is overridden in the web.config file settings, IIS performs the specified authentication check before the request is passed on to ASP.NET.
Authentication
Authentication determines whether a user is valid or not based on the user’s credentials. Note that a user can be authorized to access the resources provided the user is an authenticated user. The application’s web.config file contains all of the configuration settings for an ASP.NET application. An authentication provider is used to prove the identity of the users in a system. There are three ways to authenticate a user in ASP.NET:
Forms authentication
Windows authentication
Passport authentication
Forms Authentication
This is based on cookies where the user name and the password are stored either in a text file or a database. It supports both session and persistent cookies. After a user is authenticated, the user’s credentials are stored in a cookie for use in that session. When the user has not logged in and requests for a page that is secured, he or she is redirected to the login page of the application. The following code snippet illustrates how this can be implemented in ASP.NET.
<configuration>
<system.web>
<authentication mode=”Forms”/>
<forms name=”LoginForm” loginUrl=”LoginForm.aspx” />
<authorization>
<deny users=”?”/>
</authorization>
</system.web>
</configuration>
Windows Authentication
Windows Authentication is used to validate a user based on the user’s Windows Account; however, this is only applicable in intranet environments where the administrator has full control over the users in the network. The following code snippet illustrates how we can implement Windows Authentication in ASP.NET.
<authentication mode=”Windows”/>
<authorization>
<allow users =”*” />
</authorization>
Passport Authentication
Passport authentication is a centralized authentication service that uses Microsoft’s Passport Service to authenticate the users of an application. It allows the users to create a single sign-in name and password to access any site that has implemented the Passport single sign-in (SSI) service. The following code snippet illustrates how we can implement Passport Authentication in ASP.NET.
<configuration>
<system.web>
<authenticationmode=”Passport”>
<passportredirectUrl=”LoginForm.aspx” />
</authentication>
<authorization>
<deny users=”?” />
</authorization>
</system.web>
</configuration>
Authorization
Authorization is the process of determining the accessibility to a resource for a previously authenticated user. Note that authorization can only work on authenticated users, hence ensuring that no un-authenticated user can access the application. The syntax for specifying authorization in ASP.NET is as follows.
<authorization>
< [ allow | deny ] [ users ] [ roles ] [ verbs ] />
</authorization>
In ASP.NET, there are the following types of authorizations.
URL Authorization
File Authorization
Authorization based on ACL (Access Control List)
Impersonation
According to MSDN, “When using impersonation, ASP.NET applications can optionally execute with the identity of the client on whose behalf they are operating. The usual reason for doing this is to avoid dealing with authentication and authorization issues in the ASP.NET application code. Instead, you rely on Microsoft Internet Information Services (IIS) to authenticate the user and either pass an authenticated token to the ASP.NET application or, if unable to authenticate the user, pass an unauthenticated token. In either case, the ASP.NET application impersonates whichever token is received if impersonation is enabled. The ASP.NET application, now impersonating the client, then relies on the settings in the NTFS directories and files to allow it to gain access, or not. Be sure to format the server file space as NTFS, so that access permissions can be set”.
Note that Impersonation is disabled by default and can be specified in the web.config file as shown in the code snippet given below.
<identity impersonate=”true”/>
or
<identity impersonate=”false”/>
To impersonate a particular identity, specify the following in your application’s web.config file.
<identity impersonate=”true” username=”joydip” password=”jude”/>