Let’s get it right. Virtualization is about reducing the physical footprint of IT infrastructure and maximizing the utilization of the same. It helps to drastically reduce cumulative maintenance and onetime procurement costs of physical hardware. Since a virtualized environment (VE) is a logical representation of a physical environment hosted on real hardware and sandboxed, it makes practically possible to host multiple VEs on a single physical computer and an enterprise’s business and IT applications can be consolidated on to fewer physical hardware:
Virtualization helps in reducing infrastructure complexity (less hardware), power (more green) and cuts overall operational overhead.
Cloud offers the same infrastructure & cost benefits of virtualization – reduced physical hardware and associated operational/maintenance overhead. Almost all the cloud service providers today have implemented their cloud platform using virtualization and that is what confuses people more about virtualization and cloud. Simply put, virtualization is one of the ways of implementing cloud. In other words, nothing stops one from implementing a cloud infrastructure with hundreds of blade servers instead of virtualization, for example. Not just that, cloud enables sharing compute power/resources – RAM, disk space, processors, network bandwidth from a central pool of those resources on-demand basis.
US Federal Government’s National Institute of Standards and Technology (NIST) lists the following characteristics as essential for cloud model:
- On-demand self-service (cloud provisioning by consumers themselves)
- Broad network access (from a variety of/heterogeneous devices and software apps)
- Service usage to be measurable (monitoring & measuring resource usage – CPU, memory, disk space, network bandwidth, etc.)
- Elasticity (Cloud resources to be easily provisioned for increased & reduced load)
- Resource pooling (Computing resources pooled to be able to transparently share among multiple cloud consumers based on their demand)
As you can see, the above require capabilities much more than just virtualization part.
Think virtualization & cloud computing in parallel to classic ASP.NET web services & SOA. While ASP.NET web services are a means of realizing SOA, they are not SOA by themselves.
Though Visual Studio 2010 SP1 will have out-of-the-box support for developing and debugging web applications against IIS Express 7.5, you can still use plain VS 2010 against IIS Express with few manual steps. Here is how:
- Install IIS Express (IISE) 7.5 RTM (download it from http://goo.gl/nQ9Cu).
- Assuming IISE was installed at the default location – C:\Program Files (x86)\IIS Express, open up a command prompt window and navigate to that folder.
- Run iisexpress.exe. This would create the default configuration and other files underneath your Documents folder C:\Users\user_name\Documents\IISExpress\config) and startup IIS Express listening at a port configured by default:
- Press Q to quit IIS Express and open the ‘just created’ application host configuration file: C:\Users\user_name\Documents\IISExpress\config\applicationhost.config in Notepad (or your favorite!).
- Go to <configuration>/<system.applicatioHost>/<sites> section and make a replica of the existing WebSite1 site element below (or above) it – now the <sites> section will have two child <site> elements – the default WebSite1 and the copy. Make changes suggested from here to either the copy or the default WebSite1.
Let’s see how to hook up an existing web application with IIS Express using Visual Studio 2010 (without SP1); I am using BlogEngine.NET for this demo. The solution may sound hacky, but, there is no other way around to accomplish this as far as I know but leave a comment if you know any better ways.
Open your web application in VS 2010. Next, make a note of the port number that the web application uses if it is backed by the VS web server: select the web application in Solution Explorer and press F4. On the Properties dialog, you will see the port number as shown below:
The Properties dialog will not have the "Developer Web Server" section if you use the default IIS and hence you can use any port and change all dependencies wherever referenced. For instance, you need to update service reference URLs in WCF clients if the web app in question is a WCF service.
Now, switch back to applicationhost.config and make the following changes:
- Give any value you like for the name attribute of the <site> element but a unique number (within <sites>) for the id attribute.
- If your web application targets .NET 4.0, then add attribute applicationPool to the <application> element and assign Clr4IntegratedAppPool to it, otherwise Clr2IntegratedAppPool. Both the app pools are already defined in the host configuration file. This step is optional and required only if the application doesn’t work as intended
- For the root virtual directory, set physicalPath attribute value to the absolute path of your website root and path to be root (/). The VS web server by default runs your web app under a virtual path but it needn’t be so with default IIS or IISE.
- If your web application uses additional virtual directories, you should add them as well as the children of <application> element.
- For the <binding> element, use localhost as the host name, but for the port, use the port number noted above.
- Save the configuration file and please remember that I have not changed anything other than adding a new site and configuring it based on its existing configuration. A sample <sites> section with a new site configuration is shown below:
- Now, run "iisexpress /siteid:2" (or any switch that identifies the new site) at the command prompt and if everything went correctly, you should see an output similar to the one below (root site URL highlighted, which IISE picked up from the host configuration file):
- The last step is to attach Visual Studio 2010 to the running iisexpress.exe process: select menu Debug | Attach to Process… and choose iisexpress.exe:
(click to expand)
At this point you should be able to open the root website URL in a browser and hit any breakpoints you may have.
(click to expand)
Site in action…
(click to expand)
If your web application uses, the default IIS, then things are even easier: all you have to do is pick up any port that doesn’t conflict with services running already and start IISE.
I know things may not be as straight forward as what I have shown, depending on how your web applications are structured in the overall solution, but I hope you get the idea (or you may as well wait for VS 2010 SP1 RTM or use SP1 beta!).
After other Microsoft developer training kits, now is a new one: ASP.NET MVC Training Kit. Get it (~12 MB)!
Even today, many developers use the classic debugging ‘tool’,
, when developing ASP/ASP.NET applications. Typically, this is the choice when someone wants to do quick debugging in a page – check variable values at runtime, write trace messages, path coverage, etc without resorting to any IDE or other full-fledged debugging tools. However, the problem with
(in the context of debugging) is that it writes data without any line breaks, which doesn’t help many times. So, given the new set of capabilities in the .NET framework, why not have the
too? Here is what I came up with – an extension method for
class that gives line break!
void WriteLine (this
HttpResponse resp, object o)
resp.Write (o + “<br/>”);
As you can see, this extension method simply does the trick of appending a <br /> with the argument passed in. Way by which this method can be utilized include having it in a base page class from which your other pages derive from, have it in a utility class, etc, etc. Choice is yours! J
Today I saw a question in the ASP.NET newsgroup asking about
implementing a static (non-hyperlinked) site map path. As you know, the
control in ASP.NET 2.0 displays a breadcrumb showing the current spot in the
site map navigation defined in the web.sitemap XML file. Parent nodes in
the current navigation path are shown as links to the respective pages, each
separated by the path separation character (defined by the
property). However, if you would like a static breadcrumb, that is, without
making parent nodes as links but as plain text, just hook into the
ItemDataBound event of the
SiteMapPath control and clear the navigation URL (originally taken from the web.sitemap file) for every node.
Assuming a simple
SiteMapPath markup as below:
<asp:SiteMapPath ID="SiteMapPath1" runat="server" CurrentNodeStyle-Font-Bold="true" NodeStyle-Font-Size="Small" OnItemDataBound="SiteMapPath1_ItemDataBound" PathDirection="RootToCurrent" PathSeparator=" > " PathSeparatorStyle-Font-Size="Small" RenderCurrentNodeAsLink="false">
Have the following for the
protected void SiteMapPath1_ItemDataBound (object sender, SiteMapNodeItemEventArgs e)
if (e.Item.ItemType == SiteMapNodeItemType.Parent || e.Item.ItemType == SiteMapNodeItemType.Root)
// Control index may vary if additional controls have been defined in the node template
((HyperLink)e.Item.Controls).NavigateUrl = "";
The result would look something like this (assuming an apporpriate web.sitemap file is in place):
Without this change, the same SiteMapPath control would look like (parent pages hyperlinked):
One of the features of the ASP.NET application that I am currently working on requires copying dynamically generated files to a network share path. As guessed(!), the user identity of the ASP.NET worker process (IIS application pool, in case of Windows 2003) did not have the required privileges to the network path, causing the familiar “access denied” exception. The solution is pretty obvious: impersonate the file copying code with an user account that has necessary access rights to the share. Here is the pretty straight forward code for everyone’s benefit:
[DllImport ("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser (string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);
[DllImport ("kernel32.dll", CharSet = CharSet.Auto)]
private extern static bool CloseHandle (IntPtr handle);
if (LogonUser ("<user name with network share access>",
8, // LOGON32_LOGON_NETWORK_CLEARTEXT
0, // LOGON32_PROVIDER_DEFAULT
wi = new WindowsIdentity (token);
WindowsImpersonationContext wic = wi.Impersonate ();
File.Copy (@"<file source>", @"<network share/UNC path>");
Console.WriteLine ("LogonUser() failed with error code " + Marshal.GetLastWin32Error ());
If you too are interested in looking at the internals of ASP.NET AJAX (Atlas), download the source code at http://www.microsoft.com/downloads/details.aspx?FamilyID=ef2c1acc-051a-4fe6-ad72-f3bed8623b43&DisplayLang=en
Great material if you want to see the various server-side implementation of the ASP.NET AJAX framework.
One of the cool features in ASP.NET 2.0 is the ability to set focus to the input control having invalid input. This is accomplished by setting the SetFocusOnError property of the associated validator control(s) to true. However, the same feature can be achieved in ASP.NET 1.x using the documented and undocumented client-side API of the ASP.NET validation framework. Here is how:
Plug in the following script block in the .aspx file
var refCtl = null;
for (var i=0; i<Page_Validators.length; i++)
refCtl = document.getElementById(Page_Validators[i].getAttribute(“controltovalidate”));
if (refCtl != null)
In the code-behind, have this one liner in the page’s load event:
<submit button>.Attributes.Add(“onclick”, “setFocus();”);
This code has been tested for ASP.NET 1.x with Internet Explorer 6+.