Application Security Testing: An Integral Part of DevOps
ASP.NET 4.0 is the version of ASP.NET bundled with .NET Framework 4.0. In this article let us delve into what I think are the top 7 features of ASP.NET 4.0.
ASP.NET 4.0 application provides support to websites as well as web application projects. The default ASP.NET application provides a good starter project template with some common items which have to be built for almost all web based projects like a Master Page with a standard template, About us page, Login page, Register page, Change Password page, a default style sheet named Site.css which would already have been referred in the Master page, etc., This undoubtedly would reduce a lot of development effort. All you need to do is simply customize the predefined templates to your needs. If the developer is not interested in the default templates, ASP.NET 4.0 also provides web based projects called EmptyWebApplication and EmptyWebSite, which will not have any default items in the project except the web.config file. Fig 1.0 shows the default home page template.
Another noticeable thing would be, when you expand the Web.Config file you would find two files named Web.Debug.config and Web.Release.config. This is a new feature called Web.Config transformation, which will enable developers to maintain separate config files for different application environments. I will soon be writing an article on Web.Config transformation.
In my opinion the introduction of the new Chart Control in ASP.NET 4.0 makes the life of most web application developers a lot easier. In the earlier versions of ASP.NET in order to have a chart on the web page you have to download the MS charts and integrate it into the IDE which only exposed some basic chart features. For more chart features the developers had to use some third party chart controls. Now the ASP.NET chart control provides a wide range of features. In fact it also provides support for 3-D charts. Below is the list of some of supported chart types.
- Stacked Column
You need to simply set the data source for this chart control as you do it for a GridView and your chart is ready. Another good thing about the chart controls is that you can customize the style and appearance to a great extent. You can also provide a gradient style to your charts.
Fig 2.0 shows a sample Column Chart.
Below is the corresponding .aspx code for the above chart. Note that I have hardcoded the datapoints in order to make the example pretty simple.
<asp:Chart ID="Chart1" runat="server" Width="428px"> <series> <asp:Series Name="Series1"> <Points> <asp:DataPoint XValue="1970" YValues="1000" /> <asp:DataPoint XValue="1980" YValues="2000" /> <asp:DataPoint XValue="1990" YValues="3000" /> <asp:DataPoint XValue="2000" YValues="4000" /> <asp:DataPoint XValue="2010" YValues="5000" /> </Points> </asp:Series> </series> <chartareas> <asp:ChartArea Name="ChartArea1"> <AxisX Title="Year" IntervalOffsetType="Years"> </AxisX> <AxisY Title="City Population" IsLogarithmic="true"> </AxisY> </asp:ChartArea> </chartareas> </asp:Chart>
Fig 2.1 is a sample Pie chart
Below is the code for the above chart
<asp:Chart ID="Chart1" runat="server" > <Series> <asp:Series Name="Series1" ChartType="Pie" Legend="Legend1"> <Points> <asp:DataPoint Label="India" CustomProperties="OriginalPointIndex=0" YValues="40" /> <asp:DataPoint Label="China" CustomProperties="OriginalPointIndex=1" YValues="40" /> <asp:DataPoint Label="America" LabelAngle="-50" CustomProperties="OriginalPointIndex=2" YValues="10" /> <asp:DataPoint Label="Australia" LabelAngle="-10" CustomProperties="OriginalPointIndex=3" YValues="10" /> </Points> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> </asp:ChartArea> </ChartAreas> <Legends> <asp:Legend Name="Legend1"> </asp:Legend> </Legends> <Titles> <asp:Title Name="Population Chart" Text="Population Chart"> </asp:Title> </Titles> </asp:Chart>
ClientIDMode for controls
In earlier versions of the ASP.NET Framework if you place a control inside a container control like a Template column of a GridView, Template of a Login Control, etc., at runtime the IDs of those controls will be replaced with random unique IDs generated by ASP.NET itself. This was a big and long standing problem for the developers to access the control on the server side using
document.getElementbyId("controlid"). In simple terms the control ids generated at runtime were not predictable.
But .NET developers no longer find themselves in such situation because in ASP.NET 4.0 there is a property called
ClientIDMode for all the controls. This has provided good control over the ID generated for the content controls during runtime.
The types of ClientIDModes available are:
- AutoID - This is the same random way as it uses to happen in the earlier versions of ASP.NET.
- Static - The ID of the control will not change at the runtime. This is pretty handy setting if the control is being used in the container or in the child pages and needs to be accessed on the client scripts.
- Predictable - For the controls like a textbox in a GridView template column Static mode will not be useful because of the repeating rows of the GridView. In such scenarios Predictable mode comes in handy where the developer can provide a predictable value say a primary key of the GridViewRow using the ClientIDRowSuffix property. This will append the predictable unique value as suffix to the actual control id. For example if the actual control id in the TemplateColumn is txtBox and the ClientIDRowSuffix is the GridViewRowIndex then the generated IDs during runtime for row1 textbox ID will be GridView1_txtBox_1, for row2 it will be GridView1_txtBox_2 and so on.
- Inherit - This will inherit the ClientIDMode value from its parent control.
You don't have to provide the ClientIDMode for each and every control rather you could specify it at the page level in the page directive.
<%@ Master Language="C#" ClientIDMode="Predictable" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="MyWebApplication.SiteMaster" %> Or it could also be provided at the application level using the web.config specification as shown below. <system.web> <pages clientIDMode="Predictable"></pages> </system.web>
Note that the ClientIDMode specified at the control level will override the above settings in the page directive and web.config.