<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msdnbangladesh.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Jalal @ Work</title><subtitle type="html">By reading this blog you agree that Jalal will not be responsible for any harm done to your PC and your personal life.</subtitle><id>http://msdnbangladesh.net/blogs/jalal/atom.aspx</id><link rel="alternate" type="text/html" href="http://msdnbangladesh.net/blogs/jalal/default.aspx" /><link rel="self" type="application/atom+xml" href="http://msdnbangladesh.net/blogs/jalal/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.31106.3070">Community Server</generator><updated>2009-03-25T11:50:00Z</updated><entry><title>Better accessibility with AccessKey in Asp.net controls</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/11/22/better-accessibility-with-accesskey-in-asp-net-controls.aspx" /><id>/blogs/jalal/archive/2009/11/22/better-accessibility-with-accesskey-in-asp-net-controls.aspx</id><published>2009-11-22T14:39:30Z</published><updated>2009-11-22T14:39:30Z</updated><content type="html">&lt;p&gt;All of us has seen that every control in Asp.net has a property called AccessKey, but many of us do not know (or may be lazy to know) and use it. But I think it is a good feature that can increase accessibility of a website. Specially Linux user/ users who do not use mouse that frequently can access the fields with short cut key.&lt;/p&gt;  &lt;p&gt;How to set it? Well it is so simple. Just set the AccessKey property to a letter. For example, myControl.AccessKey = “U”&lt;/p&gt;  &lt;p&gt;and then access the field with shortcut “Alt+U” (in firefox Alt+Shift+U)&lt;/p&gt;  &lt;p&gt;you must make sure that you have not set a short cut that is already a shortcut for the browser itself. that is setting AccessKey= “L” will not work in firefox as it is reserved by firefox itself.&lt;/p&gt;  &lt;p&gt;You can also mark the label of the control with underscore (which is a norm for shortcut key) so that users can understand that this field has shortcut key support. For example, &lt;u&gt;N&lt;/u&gt;ame where “N” is AccessKey for this field.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=62755" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Asp.net" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Asp.net/default.aspx" /><category term="Accessibility" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Accessibility/default.aspx" /></entry><entry><title>Microsoft released Silverlight 4 Beta 2</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/11/21/microsoft-released-silverlight-4-beta-2.aspx" /><id>/blogs/jalal/archive/2009/11/21/microsoft-released-silverlight-4-beta-2.aspx</id><published>2009-11-20T18:57:31Z</published><updated>2009-11-20T18:57:31Z</updated><content type="html">&lt;p&gt;2 days ago in last PDC Microsoft released Silverlight 4 Beta 2. I sneaked through the feature list a while ago. It seems some interesting features are included along with performance tuning.&lt;/p&gt;  &lt;p&gt;Before I discuss about the features I want to focus on the performance issue as it caught my eyes and I think others will also be interested on it. “Silverlight 4 applications start quicker and run &lt;font color="#008000" size="4"&gt;200%&lt;/font&gt; faster than the equivalent Silverlight 3 application.” This line was the source of my interest. If this is true than I think everyone will have to look at Silverlight 4 before eating up Silverlight 3 completely. Its not 10% or 20% its 200%, if this is true than it is a huge boost up. Though I hardly believe this will be true for all cases. My assumption is some specially slow feature like RIA service and networking features has been tuned up mostly. Still lets see how fast it is.&lt;/p&gt;  &lt;p&gt;Now lets get a look at the new features,&lt;/p&gt;  &lt;p&gt;There is some big list, but I will pick up those that caught my eyes.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Webcam and microphone to allow sharing of video and audio for instance for chat or customer service applications. &lt;/li&gt;    &lt;li&gt;Audio and video local recording capabilities capture RAW video without requiring server interaction, enabling a wide range of end-user interaction and communication scenarios for example video conferencing.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Few days ago, I was looking for a video conferencing feature for website. As a .net developer my search went to Silverlight 3 and I was pretty sure that there is something for this, but unfortunately I ended in a dead end. My friend who was actually asking me to make a video conference tool for his website made me do this query on Silverlight, but I was surprised to see that though it is possible with Flash, it is still not possible with Silverlight 3 or at least no straight forward support for it in Silverlight 3 (I am not so sure whether it is possible somehow using the streaming feature, at least to me it was not so promising for this issue). But now with Silverlight 4 it will be possible. I am waiting for the full release of it.&lt;/p&gt;  &lt;p&gt;some more……&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Read and write files to the user’s MyDocuments, MyMusic, MyPictures and MyVideos folder (or equivalent for non-windows platforms) for example storage of media files and taking local copies of reports. &lt;/li&gt;    &lt;li&gt;Run other desktop programs such as Office, for example requesting Outlook to send an email, send a report to Word or data to Excel. &lt;/li&gt;    &lt;li&gt;COM automation enables access to devices and other system capabilities by calling into application components; for instance to access a USB security card reader.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I was surprised to see that it is now so easy to access user’s machine form Silverlight 4 application. Well I am not saying that it will be always intended and I must say over using or misusing it may not be a good idea. But now there is a friendly and easy way to open up an Excel file from Silverlight application and even establish a communication between them so that if any change made to the Excel file, it show up in Silverlight 4 application and vise versa .&lt;/p&gt;  &lt;p&gt;Also cross domain request can be easily made for requests that do not require authentication - even without a security policy file.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Support for Google’s Chrome browser.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Yes this support is important, there is nothing more frustrating to deliver a product to a client and to find out that he is a Chrome fan and your application do not run on it.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Content protection for H.264 media through Silverlight DRM powered by PlayReady. &lt;/li&gt;    &lt;li&gt;Output protection for audio/video streams allowing content owners or distributors to ensure protected content is only viewed through a secure video connection.&lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;Well those who care about copyright and data security can use these features for sure.&lt;/p&gt;  &lt;p align="left"&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="left"&gt;Bring data in to your application with features such as copy and paste or drag and drop.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;So now you can just make an MP3 application with Silverlight 4 and drag an MP3 file on it and will start to play, yes it is now possible. Well done!&lt;/p&gt;  &lt;p align="left"&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="left"&gt;Comprehensive printing support enabling hardcopy reports and documents as well as a virtual print view, independent of screen content.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;Well I am not a hard core user of report yet. It seems like Microsoft takes it as the top feature putting it&amp;#160; on the top. I think they have done a good job with the reporting charts and printing. So I have to have a look at it yet.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;There are other many features like new set of controls, drag drop, auto binding, full intellisense for XAML and C# and VB languages, and many more. just go to &lt;a href="http://silverlight.net/getstarted/silverlight-4-beta/"&gt;Silverlight website&lt;/a&gt; to find out more about it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=61856" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Silverlight" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Silverlight/default.aspx" /></entry><entry><title>Reference to asp.net configuration file schema in msdn</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/11/06/reference-to-asp-net-configuration-file-schema-in-msdn.aspx" /><id>/blogs/jalal/archive/2009/11/06/reference-to-asp-net-configuration-file-schema-in-msdn.aspx</id><published>2009-11-06T09:27:30Z</published><updated>2009-11-06T09:27:30Z</updated><content type="html">&lt;p&gt;When we develop application, we frequently need to configure it through the configuration file, but I lose the msdn link to the schema explanation most of the time. &lt;/p&gt;  &lt;p&gt;for various version of .net framework the link is different, but if you can find one, you can easily choose the other versions as all versions are link in msdn.&lt;/p&gt;  &lt;p&gt;here is the link for 3.5 : &lt;a title="http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx" href="http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx"&gt;http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;an easily alternative is to look at the framework classes and to figure out the schema, but as i got the link at hand, i want to post it in my blog so that next time i don’t have to look for it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=54151" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Asp.net" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Asp.net/default.aspx" /></entry><entry><title>How to stop auto populate in text box</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/10/01/how-to-stop-auto-populate-in-text-box.aspx" /><id>/blogs/jalal/archive/2009/10/01/how-to-stop-auto-populate-in-text-box.aspx</id><published>2009-10-01T11:25:43Z</published><updated>2009-10-01T11:25:43Z</updated><content type="html">&lt;p&gt;Though auto populate of previously entered text in text box is helpful sometimes, still there are cases when we do not want this feature (may be because we have our own auto complete feature using ajax, so we don’t want it to block our cool auto complete)&lt;/p&gt;  &lt;p&gt;we can simply stop it by putting: autocomplete=&amp;quot;off&amp;quot; in the textbox like below.&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:TextBox runat=&amp;quot;server&amp;quot; ID=&amp;quot;tbMessage&amp;quot; autocomplete=&amp;quot;off&amp;quot;&amp;gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=32394" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Asp.net 2.0" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Asp.net+2.0/default.aspx" /><category term="XHTML" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/XHTML/default.aspx" /></entry><entry><title>Using Visual Studio Build Events</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/09/25/using-visual-studio-build-events.aspx" /><id>/blogs/jalal/archive/2009/09/25/using-visual-studio-build-events.aspx</id><published>2009-09-25T11:49:18Z</published><updated>2009-09-25T11:49:18Z</updated><content type="html">&lt;p&gt;Sometimes we may need to perform some action before or after the build process of visual studio. &lt;/p&gt;  &lt;p&gt;A simple case can be, when we open a solution which contains several projects and websites, and few of the websites hosted in IIS virtual directory, and we need to check the websites after build using IIS server. &lt;/p&gt;  &lt;p&gt;One solution can be to build the project folders as virtual directory so that they are directly available. But if for some reason that is not desired or say we need to put files together from 2 or more project into the IIS website (combined copy), in that case we can use the post build event to copy paste the required file in the location.&lt;/p&gt;  &lt;p&gt;Pre Build event can be configured as well in this way.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Select the project and go to properties, then Build event.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://i22.photobucket.com/albums/b344/codemaker/WCF/ScreenHunter_04Sep251910.gif" alt="" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If you press Edit Post Build, a popup will come. Here you can write down your desired commands.&lt;/p&gt;  &lt;p&gt;For example, i wrote commands to create few folders and copy some required files inside the IIS hosted websites.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://i22.photobucket.com/albums/b344/codemaker/WCF/ScreenHunter_02Sep251909.gif" alt="" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You can click the Macro button to see some listed helpful macros that can make your task easy.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://i22.photobucket.com/albums/b344/codemaker/WCF/ScreenHunter_03Sep251909.gif" alt="" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=30193" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Visual Studio" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Visual+Studio/default.aspx" /></entry><entry><title>.svc extension not working in Windows Vista or Windows 7</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/09/25/svc-extension-not-working-in-windows-vista-or-windows-7.aspx" /><id>/blogs/jalal/archive/2009/09/25/svc-extension-not-working-in-windows-vista-or-windows-7.aspx</id><published>2009-09-25T10:25:56Z</published><updated>2009-09-25T10:25:56Z</updated><content type="html">&lt;p&gt;In windows vista or Windows 7 .svc extension / MIME type is not configured by default. So when executing any WCF service call a 404 error will be issued.&lt;/p&gt;  &lt;p&gt;This problem can be solved by the following command:&lt;/p&gt;  &lt;p&gt;C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation&amp;gt;Service   &lt;br /&gt;ModelReg.exe –i&lt;/p&gt;  &lt;p&gt;This assumes windows in installed in C drive.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=30157" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Setup" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Setup/default.aspx" /><category term="WCF" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/WCF/default.aspx" /></entry><entry><title>How to debug localhost (or running in IIS) Asp.net applications</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/06/26/how-to-debug-localhost-or-running-in-iis-applications.aspx" /><id>/blogs/jalal/archive/2009/06/26/how-to-debug-localhost-or-running-in-iis-applications.aspx</id><published>2009-06-26T09:14:06Z</published><updated>2009-06-26T09:14:06Z</updated><content type="html">&lt;p&gt;Sometimes you may need to debug applications that you host in IIS. In case of a developer pc we can call it localhost applications. When we use Visual Studio, we can debug our application when we run the built-in web server of visual studio. &lt;/p&gt;  &lt;p&gt;But when we want to test our application properly in IIS server (which we should always do to get the true outcome of the application) that type of straight forward debug can’t be done. But still we can debug our application and that is not so difficult as well. Here is the steps,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;first deploy your application in IIS if it is not already deployed. In my case i created a virtual directory for my application in the usual way. lets say it can be run using the url &lt;a href="http://localhost/test"&gt;http://localhost/test&lt;/a&gt; . now lets run the site using browser. It is important to run the localhost site using the browser (and keep the browser open&amp;#160; in some case) because otherwise we may not see the asp.net worker process in the process list.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now run visual studio and open the project, put debug points where needed. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now we have to attach the debugger with the asp.net worker process to do the debug.&lt;/p&gt;  &lt;p&gt;Go to Debug &amp;gt; Attach to process…&lt;/p&gt;  &lt;p&gt;&lt;img src="http://i22.photobucket.com/albums/b344/codemaker/Visual%20Studio/visualstudio.gif" alt="" /&gt; &lt;/p&gt;  &lt;p&gt;Next choose the &lt;em&gt;&lt;strong&gt;aspnet_wp.exe (in case of windows xp it is aspnet_wp.exe and in case of windows server 2003 it is w3wp.exe)&lt;/strong&gt;&lt;/em&gt; and click Attach.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://i22.photobucket.com/albums/b344/codemaker/Visual%20Studio/attachprocess2.gif" alt="" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now browse the site using any the browser and debugger will fire wherever a debug point is placed. &lt;/p&gt;  &lt;p&gt;Happy debugging !!!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Special Notes:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If you open the application in multiple browser or multiple times, it may happen that there will be several instance of the asp.net worker process, that is multiple &lt;strong&gt;&lt;em&gt;aspnet_wp.exe/w3wp.exe&lt;/em&gt;&lt;/strong&gt; in the process list. you need to pick the one that you are using for debug. finding which one is the correct one can be done by trial and error or there are some blogs in the net about several ways on how to do so. but as long as multiple process is not being handled, there is nothing to headache. if you need to find out easily which one is the correct process in case of multiple process, use google to find the solution best suite you.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ad906f0e-7858-43fd-add3-fc39c26c4724" style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Debug" rel="tag"&gt;Debug&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IIS" rel="tag"&gt;IIS&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=1371" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Debug" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Debug/default.aspx" /><category term="Visual Studio" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Visual+Studio/default.aspx" /></entry><entry><title>Introduction to WCF (WCF – Part 1)</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/06/21/introduction-to-wcf-wcf-part-1.aspx" /><id>/blogs/jalal/archive/2009/06/21/introduction-to-wcf-wcf-part-1.aspx</id><published>2009-06-21T03:56:16Z</published><updated>2009-06-21T03:56:16Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;&lt;font color="#44b4ea"&gt;Introduction:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Windows communication foundation (WCF) is one of the recent buzz in the development world. The beauty of this technology has already attracting developers towards it. To get a long range view about what WCF is or what it can do I can say, it is the best way to build a distributed system. It leverages much hassle from the development team and lets them focus on the actual application. Before WCF there were many technologies that were used to build distributed applications or any application that has to communicate other channels to provide or consume service. RMI, SOAP, CORBA, COM+, XML etc are some of these old technologies that still may be dominating the distributed world. But it seems to me, soon it will change. I will explain it next why WCF is going to be in demand instead of the old rulers.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#44b4ea"&gt;What is the problem in old approaches:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Today’s world is different than before. Now we do not need isolated applications. The demand of software and business dependency on software has greatly increased, which created vast scope for applications and great demand of requirement. Services provided through applications now can’t be always provided in a single application. Different applications needs to communicate with each other to fulfill a demand. Applications are distributed and they need to communicate. This communication in fact is not so simplistic as it sound. The above technologies each had its pros and cons in communicating. Most of all each one is totally different than the other and developers need to learn a new technology to use it. There was no set standard or a common set of knowledge that could be used in different scenarios and need.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#44b4ea"&gt;The solution - the root of WCF:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;WS-*&lt;/i&gt; (pronounced “W-S-star”) is the solution for this diversity problem. It defines a set of standards that define, among other things, universal message structures and messaging choreographies that includes &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;WS-Addressing, &lt;/li&gt;    &lt;li&gt;WS-Security, &lt;/li&gt;    &lt;li&gt;WS-Trust, &lt;/li&gt;    &lt;li&gt;WS-SecureConversation, &lt;/li&gt;    &lt;li&gt;WS-Federation, &lt;/li&gt;    &lt;li&gt;WS-ReliableMessaging, &lt;/li&gt;    &lt;li&gt;WS-AtomicTransaction, &lt;/li&gt;    &lt;li&gt;WS-Coordination, &lt;/li&gt;    &lt;li&gt;WS-MetadataExchange, &lt;/li&gt;    &lt;li&gt;WS-Policy, and &lt;/li&gt;    &lt;li&gt;WS-PolicyAttachment &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;WCF can also be used in the Representational State Transfer (REST) architecture and other distributed architectures that use Plain Old XML (POX) messages.&lt;/p&gt;  &lt;p&gt;Although previously developers could write service oriented applications using web service and other technologies, but now developers can do it with more security, reliability, flexibility, and performance than before.&lt;/p&gt;  &lt;p&gt;WCF applications send and receive messages through the operating system I/O such as sockets, named pipes etc but the developers are abstracted from the bottom level details by WCF letting the developer think more on the application itself.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#44b4ea"&gt;Features of WCF:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;h5&gt;&lt;strong&gt;&lt;u&gt;Independent Versioning&lt;/u&gt;&lt;/strong&gt;&lt;/h5&gt;  &lt;p&gt;In a distributed environment, there are many segments that communicate and perform business task. For example, in a Enterprise Resource Planner (ERP) system, there can be inventory, human resource module, client feedback module, order, supply, payroll etc. All these may be somehow related to one another. And if we consider the whole system as a single application and each part as a module of it, any change happens to a module may need change in the other related modules too. On the other hand in the service oriented approach, each part is considered as an application, and each one communicates with the other part using messaging, so change made in one part or addition of a new part may not need any change in the other parts as long as it follows the &lt;i&gt;WS-*&lt;/i&gt;&amp;#160; specification. Which is allowing updating the version of a segment independently of the other segments.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Asynchronous One-Way Messaging&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In the traditional request reply model, we call for a service (lets say a function call at this point) and wait for it to return to us which actually halts the application at that point. As we know the asynchronous forward-only messaging is far more efficient for the I/O bound tasks but is more complicated. At this point some may think about the AJAX and say we already do it in AJAX. But he is forgetting that WCF is not only limited in web request, it handles all task that is performed in both web and desktop environment. No matter how expert the developer is, he will agree that doing I/O operations asynchronously is far more difficult. But WCF provides us the most ease in doing so. WCF is built from the ground up to support asynchronous forward-only messaging.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Platform Consolidation&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Microsoft supported several major technologies for distributed computing such as RPC, WSE, ASMX, Remoting, COM+, and MSMQ. All of them has its benefits and limitations. WCF combines features from different technologies and unifies them under one programming model to make the developer free from thinking about so many technologies.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="544"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="190"&gt;         &lt;p&gt;&lt;b&gt;Feature &lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="56"&gt;         &lt;p&gt;&lt;b&gt;WSE &lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="53"&gt;         &lt;p&gt;&lt;b&gt;ASMX &lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="72"&gt;         &lt;p&gt;&lt;b&gt;Remoting &lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="46"&gt;         &lt;p&gt;&lt;b&gt;COM+ &lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="64"&gt;         &lt;p&gt;&lt;b&gt;MSMQ &lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="61"&gt;         &lt;p&gt;&lt;b&gt;WCF&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="190"&gt;         &lt;p&gt;WS-* support &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="56"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="53"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="72"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="46"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="64"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="61"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="190"&gt;         &lt;p&gt;Basic Web service interoperability &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="56"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="53"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="72"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="46"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="64"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="61"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="190"&gt;         &lt;p&gt;.NET -to-.NET communication &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="56"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="53"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="72"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="46"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="64"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="61"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="190"&gt;         &lt;p&gt;Distributed transactions &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="56"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="53"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="72"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="46"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="64"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="61"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="190"&gt;         &lt;p&gt;Queued messaging &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="56"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="53"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="72"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="46"&gt;&amp;#160;&lt;/td&gt;        &lt;td valign="top" width="64"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="61"&gt;         &lt;p&gt;X &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Security&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;WCF supports many different security models making the application secure. And WCF has an extensible architecture, it is also relatively easy to extend WCF security to meet the needs of a particular application. WCF provides security by default. The security options range from the traditional transport-centric security to the more modern, message-based security, as dictated in WS-Security and related specifications.&lt;/p&gt;  &lt;h5&gt;&lt;strong&gt;&lt;u&gt;Reliability&lt;/u&gt;&lt;/strong&gt;&lt;/h5&gt;  &lt;p&gt;Reliability is a great factor in case of distributed system. The communication must be reliable in some cases. There are four type of reliability factor in the messaging world, they are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;At Most Once&amp;#160; &lt;/b&gt; A message must arrive at the destination no more than once.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;At Least Once&amp;#160; &lt;/b&gt; A message must arrive at the destination at least once.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Exactly Once&amp;#160; &lt;/b&gt; A message will arrive at a location only once.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;In Order&amp;#160; &lt;/b&gt; The order of the transmitted messages must be kept intact.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To ensure the reliability WCF provide extra care and facility.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Transactional Support&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As we know in real world we may need to perform several task in once scope, if one fail the others should be roll backed. WCF allows transactional scopes for communicating among the application(s).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Interoperability&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;WCF can communicate with applications that run in other Operating system. WCF can communicate with other applications that understand WS-*, Basic Profile (BP), and XML messages over TCP, HTTP, Named Pipes, and MSMQ.&lt;/p&gt;  &lt;h5&gt;&lt;strong&gt;&lt;u&gt;Performance&lt;/u&gt;&lt;/strong&gt;&lt;/h5&gt;  &lt;p&gt;As I mentioned above, WCF provides us the functionality provided by WSE, ASMX, Remoting, COM+, and MSMQ. Each of them has its benefits but for certain performance value. Such has MSMQ provides more reliability but trades with less performance, again Remoting is fast for .net to .net communication but is unable to communicate with a non .net application.&lt;/p&gt;  &lt;p&gt;WCF provides different level of interoperability and performance to meet our needs.&lt;/p&gt;  &lt;h5&gt;&lt;strong&gt;&lt;u&gt;Extensibility&lt;/u&gt;&lt;/strong&gt;&lt;/h5&gt;  &lt;p&gt;One power of WCF is its extensive design. WCF is designed to work with custom transports, channels, bindings, encodings, and architectural paradigms.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Configurability&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;WCF provide rich configuration options through XML configuration file which if used wisely can provide lot of benefits. Administrators can change the behavior of the application by configuring the XML file rather than getting involve the developer team. Though it should be used wisely as misuse can lead to unstable application that is hard to debug.&lt;/p&gt;  &lt;p&gt;   &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ec1a011c-bc8a-4b71-96dc-701832f3d119" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/WCF" rel="tag"&gt;WCF&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=1281" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="WCF" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/WCF/default.aspx" /></entry><entry><title>ASP.NET MVC Quick Reference</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/06/16/asp-net-mvc-quick-reference.aspx" /><id>/blogs/jalal/archive/2009/06/16/asp-net-mvc-quick-reference.aspx</id><published>2009-06-16T07:49:10Z</published><updated>2009-06-16T07:49:10Z</updated><content type="html">&lt;p&gt;Asp.net MVC is a new framework for web development. Lets have a quick look at it.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;font size="4"&gt;Installation:&lt;/font&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;To use it with Visual Studio 2008 and Sql Server Express 2005 / Sql Server 2005, download the MVC installer from the link following link: &lt;a href="http://www.asp.net/mvc/download/" target="_blank"&gt;http://www.asp.net/mvc/download/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;While the installer runs, it may ask you to install the Visual studio 2008 Service Pack 1 if it is not already installed. Download the installer from the following link: &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en" target="_blank"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If everything goes fine, you will see the MVC template under the visual stuido projects.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img src="http://i22.photobucket.com/albums/b344/codemaker/MVC/ScreenHunter_01Jun161348.gif" alt="" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;font size="4"&gt;Learning:&lt;/font&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The following link has many tutorials and materials to learn about MVC: &lt;a href="http://www.asp.net/mvc/learn/" target="_blank"&gt;http://www.asp.net/mvc/learn/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The NerdDinner tutorial/application is good to get started.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;font size="4"&gt;Basics:&lt;/font&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Asp.net MVC Element: (Model)&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Model acts as the wrapper of the data and business logic. It can use a separate project in the solution to fetch data using any popular ORM framework like LINQ to SQL, NHibernate or SubSonic.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Asp.net MVC Element: (View)&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;View are the UI elements like aspx pages, master pages, ascx controls that renders output in the browser, takes input from the users and sends them back to the server.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Asp.net MVC Element: (Controller)&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;In MVC every url is mapped to a method in some class, these classes are called controller. Controller determines how to interact with Model and View. Controllers take request from the View and contact the appropriate Model and then calls back a View again. All request handling decisions are made here.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0834d186-bbfd-4fb1-a7b7-fea991806163" style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Asp.net" rel="tag"&gt;Asp.net&lt;/a&gt;,&lt;a href="http://technorati.com/tags/MVC" rel="tag"&gt;MVC&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=1246" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="MVC" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/MVC/default.aspx" /></entry><entry><title>Solution of Error Code 29506 when installing SQL Server 2005 Management Studio Express on Vista</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/05/28/solution-of-error-code-29506-when-installing-sql-server-2005-management-studio-express-on-vista.aspx" /><id>/blogs/jalal/archive/2009/05/28/solution-of-error-code-29506-when-installing-sql-server-2005-management-studio-express-on-vista.aspx</id><published>2009-05-28T05:53:30Z</published><updated>2009-05-28T05:53:30Z</updated><content type="html">&lt;p&gt;while installing sql server 2005 management studio express in vista operating system, we may face an error. Here is the solution given,&lt;/p&gt;  &lt;p&gt;This is due to the new Vista feature called User Account Control or UAC. The fix is pretty simple and there are 2 different ways of implementing it.&lt;/p&gt;  &lt;p&gt;1. Under ‘Accessories’ from ‘All Programs’, right-click the Command Prompt shortcut and select ‘Run as Administrator’. Accept the UAC warning when prompted.   &lt;br /&gt;2. From the command prompt change to the directory that holds the SSMSEE installation .MSI file.    &lt;br /&gt;3. Enter the command .\SQLServer2005_SSMSEE_x64.msi if you’re running Vista x64 (64-bit) or .\SQLServer2005_SSMSEE.msi if you’re running Vista x86 (32-bit)    &lt;br /&gt;4. Press enter and complete the installation as normal.&lt;/p&gt;  &lt;p&gt;The second method is to disable UAC completely but I wouldn’t recommend it.&lt;/p&gt;  &lt;p&gt;Thanks to this post:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://digitalformula.net/databases/error-29506-when-installing-sql-server-2005-management-studio-express-on-vista/" href="http://digitalformula.net/databases/error-29506-when-installing-sql-server-2005-management-studio-express-on-vista/"&gt;http://digitalformula.net/databases/error-29506-when-installing-sql-server-2005-management-studio-express-on-vista/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=1084" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Vista" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Vista/default.aspx" /><category term="Sql Server 2005" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Sql+Server+2005/default.aspx" /><category term="Setup" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Setup/default.aspx" /></entry><entry><title>Difference between Theme and StyleSheetTheme explained</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/04/11/difference-between-theme-and-stylesheettheme-explained.aspx" /><id>/blogs/jalal/archive/2009/04/11/difference-between-theme-and-stylesheettheme-explained.aspx</id><published>2009-04-11T01:13:00Z</published><updated>2009-04-11T01:13:00Z</updated><content type="html">&lt;p&gt;Just like me, you may have wondered why there is theming options in ASP.NET - Theme and StyleSheetTheme. Understanding this difference may help you implement styling in your web page.&lt;/p&gt;  &lt;p&gt;Theme overrides the styling applied by control attributes, on the other hand StyleSheetTheme do not override them. &lt;/p&gt;  &lt;p&gt;Lets see an example of what is meant by the above line.&lt;/p&gt;  &lt;p&gt;Say, we have a have a page Default.aspx which declares the page directive,&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Page Theme=&amp;quot;MyTheme&amp;quot; %&amp;gt; &lt;/p&gt;  &lt;p&gt;If MyTheme contains a skin file which defines the style for default Label control&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:Label runat=&amp;quot;server&amp;quot; ForeColor=&amp;quot;Blue&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/p&gt;  &lt;p&gt;now if we use a label control in our Default.aspx page like below,&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:Label runat=&amp;quot;server&amp;quot; ForeColor=&amp;quot;Red&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/p&gt;  &lt;p&gt;The label control&amp;#39;s text will be in Blue color, becuase Theme always forcefully overrides the Styling attributes declared in the control level.&lt;/p&gt;  &lt;p&gt;Now if we change the Page directive to use StyleSheetTheme,&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Page StyleSheetTheme=&amp;quot;MyTheme&amp;quot; %&amp;gt; &lt;/p&gt;  &lt;p&gt;Now the label control font will be in Red as the StyleSheetTheme will no more override the inline style attribute.&lt;/p&gt;  &lt;p&gt;If we look at the order in which the styling is applied we may get a more clear idea.&lt;/p&gt;  &lt;p&gt;1.&amp;#160;&amp;#160;&amp;#160;&amp;#160; Theme attribute in the Page directive.    &lt;br /&gt;2.&amp;#160;&amp;#160;&amp;#160;&amp;#160; Theme declaration element in the Web.config file.     &lt;br /&gt;3.&amp;#160;&amp;#160;&amp;#160;&amp;#160; Local control attributes.     &lt;br /&gt;4.&amp;#160;&amp;#160;&amp;#160;&amp;#160; StyleSheetTheme attribute in the&amp;#160; Page directive.     &lt;br /&gt;5.&amp;#160;&amp;#160;&amp;#160;&amp;#160; StyleSheetTheme element in the Web.config file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=769" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Asp.net 2.0" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Asp.net+2.0/default.aspx" /><category term="StyleSheetTheme" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/StyleSheetTheme/default.aspx" /><category term="Theme" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Theme/default.aspx" /><category term="Theming" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Theming/default.aspx" /></entry><entry><title>Creating a custom Performance Counter</title><link rel="alternate" type="text/html" href="/blogs/jalal/archive/2009/03/25/creating-a-custom-performance-counter.aspx" /><id>/blogs/jalal/archive/2009/03/25/creating-a-custom-performance-counter.aspx</id><published>2009-03-25T04:50:00Z</published><updated>2009-03-25T04:50:00Z</updated><content type="html">&lt;p&gt;A nice feature of Asp.net is to monitor the performance of a web application using Performance Counter. This class is under System.Diagnostics namespace and provides helpful features for implementing counters that can be useful for monitoring site activity. &lt;/p&gt;  &lt;p&gt;We can observe the counter status from the Performance tool in Administrative Tools of the operating system. &lt;/p&gt;  &lt;p&gt;So, let us create a custom performance counter. &lt;/p&gt;  &lt;p&gt;Firstly, we will create an abstract class which will be the base class for all our performance counters for the current web application.&amp;#160; &lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyApp.BLL.Performance
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Counter
    {
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _categoryName = &lt;span class="str"&gt;&amp;quot;MyApp Counters&amp;quot;&lt;/span&gt;;

        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; CounterName
        {
            get;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Count
        {
            get
            {
                PerformanceCounterPermission permission = 
&lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer,
 Environment.MachineName, _categoryName);
                permission.Assert();
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (PerformanceCounterCategory.Exists(_categoryName))
                {
                    PerformanceCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounter(_categoryName, CounterName);
                    &lt;span class="kwrd"&gt;int&lt;/span&gt; count = Convert.ToInt32(counter.RawValue);
                    counter.Close();
                    PerformanceCounterPermission.RevertAll();
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; count;
                }
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; 0;
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Increase()
        {
            PerformanceCounterPermission permission = 
&lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer,
 Environment.MachineName, _categoryName);
            permission.Assert();
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (PerformanceCounterCategory.Exists(_categoryName))
            {
                PerformanceCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounter(_categoryName, CounterName, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                &lt;span class="kwrd"&gt;long&lt;/span&gt; currentCount = counter.Increment();
                PerformanceCounterPermission.RevertAll();
                &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ToInt32(currentCount);
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                PerformanceCounterCategory.Create(_categoryName, _categoryName,
                    PerformanceCounterCategoryType.SingleInstance, CounterName, CounterName);
                PerformanceCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounter(_categoryName, CounterName, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                counter.RawValue = 1;
                PerformanceCounterPermission.RevertAll();
                &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ToInt32(counter.RawValue);
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Decrease()
        {
            PerformanceCounterPermission permission = 
&lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer,
                Environment.MachineName, _categoryName);
            permission.Assert();
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (PerformanceCounterCategory.Exists(_categoryName))
            {
                PerformanceCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounter(_categoryName, CounterName, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                &lt;span class="kwrd"&gt;long&lt;/span&gt; currentCount = 0;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (counter.RawValue &amp;gt; 0)
                {
                    currentCount = counter.Decrement();
                }
                PerformanceCounterPermission.RevertAll();
                &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ToInt32(currentCount);
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                PerformanceCounterCategory.Create(_categoryName, _categoryName,
 PerformanceCounterCategoryType.SingleInstance,
                    CounterName, CounterName);
                PerformanceCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; PerformanceCounter(_categoryName, CounterName, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                counter.RawValue = 0;
                PerformanceCounterPermission.RevertAll();
                &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ToInt32(counter.RawValue);
            }
        }
    }
} &lt;/pre&gt;


&lt;p&gt;We will override the CounterName property in every child class, for example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyApp.BLL.Performance
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UserLoginCounter : Counter
    {
        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; CounterName
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Logged User Count&amp;quot;&lt;/span&gt;;
            }
        }
    }
} &lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;/pre&gt;

&lt;p&gt;now we can use the counter in an aspx page like the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Security;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.HtmlControls;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Xml.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Linkmate.BLL.Performance;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; _Default : System.Web.UI.Page
{
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!IsPostBack)
        {
            UserLoginCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; UserLoginCounter();
            tbxCount.Text = counter.Count.ToString();
        }
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UserEnter_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        UserLoginCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; UserLoginCounter();
        tbxCount.Text = counter.Increase().ToString();

    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UserExit_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        UserLoginCounter counter = &lt;span class="kwrd"&gt;new&lt;/span&gt; UserLoginCounter();
        tbxCount.Text = counter.Decrease().ToString();
    }
} &lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;One important point to note about the PerformanceCounter is, though we have assigned&amp;#160; PerformanceCounterPermission, still we will not be able to access the registry unless the user group accessing the application has right permission to do so. It will raise an exception: &lt;/p&gt;

&lt;p&gt;System.UnauthorizedAccessException: Access to the registry key &amp;#39;Global&amp;#39; is denied. &lt;/p&gt;

&lt;p&gt;A solution to this problem has been given &lt;a href="http://blogs.msdn.com/bclteam/archive/2006/09/08/746900.aspx"&gt;here&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a snapshot of that article is (in case the page is not available later on):&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Windows 2003, Windows XP x64 Edition, and Vista require that the user be part of the Performance Monitor Users group to read performance counter data. Simply adding your non admin user to this group will fix this problem. &lt;/p&gt;

&lt;p&gt;Accessing counters remotely is another story though. On Windows 2003, Windows XP x64 Edition, and Vista you still must be part of the Performance Monitor Users group on the remote machine but there is a problem with the PerformanceCounter class where it tries to read some registry keys on the remote machine that a non admin users do not have access to. To give your user read access to these keys without having to be an admin on the remote machine complete the following steps on the remote machine: &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Open the Registry Editor by going to the Start Menu and selecting Run…, then type “regedit”, and click the OK button. &lt;/li&gt;

  &lt;li&gt;Navigate to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg registry key. &lt;/li&gt;

  &lt;li&gt;Right click on the &amp;quot;winreg&amp;quot; key and select Permissions. Add users or groups to which you want to grant Read access. &lt;/li&gt;

  &lt;li&gt;Exit Registry Editor and restart Windows. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more explanation on this process see &lt;a href="http://support.microsoft.com/?kbid=153183"&gt;http://support.microsoft.com/?kbid=153183&lt;/a&gt;. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=366" width="1" height="1"&gt;</content><author><name>jalal</name><uri>http://msdnbangladesh.net/members/jalal/default.aspx</uri></author><category term="Asp.net 2.0" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Asp.net+2.0/default.aspx" /><category term="Deployment" scheme="http://msdnbangladesh.net/blogs/jalal/archive/tags/Deployment/default.aspx" /></entry></feed>
