Thursday, January 19, 2012

Reading 64-bit registry

Prior to .Net 4.0, there were some problems figuring out how to read the 64-bit Registry vs. the 32-bit Registry.

Fortunately, .Net 4.0 has now added support for reading the 64-bit Registry via the following methods:

You can find a code sample here on how to deal with the 32-bit vs. 64-bit Registry in .Net 4.0:

Detecting 64-bit OS in Microsoft.Net 4.0

If you have ever worked with a version of the Microsoft.Net Framework prior to v. 4.0, you probably have been frustrated by the lack of a native Microsoft.Net API to detect whether or not the underlying Operating System (OS) is a 32-bit OS or a 64-bit OS.

Well, now with Microsoft.Net 4.0, you finally have that capability!

You simply reference Environment.Is64BitOperatingSystem in your code!

In addition, they have also added the option for Environment.Is64BitProcess if you have a need to detect whether the running process is a 32-bit or 64-bit process (such as when running in IIS 7/7.5 when the Application Pool settings dictate whether or not you are running in a 32-bit or native 64-bit process).

You can read more about the Environment class here: 

Sunday, January 15, 2012

Dynamically setting the selected value in List-based controls

If you ever have the need to dynamically add controls to your screen or to simply set the selected value in a List-based control such as a DropDownList, CheckBoxList or RadioButtonList, you can follow the example below:

Essentially, the crux of the code that accomplishes this for you is the following:

RadioButtonList1.Items.FindByText(searchString).Selected = true;

You can alternatively also use the .FindByValue method if that suits your needs better.

Thursday, January 12, 2012

Finding the WIF SDK Visual Studio Project Templates

If you are looking for the Windows Identity Foundation SDK Visual Studio Project Templates, you can find them here:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\Web\CSharp\1033
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\Web\CSharp\1033

Extracting the .zip files and examining the contents can be useful in determining how to create your own WIF-based Visual Studio project templates.  If you have noticed, the WIF-based Visual Studio project templates installed by the WIF SDK also automatically run the FedUtil wizard in the background.

You will find this within the .vstemplate file:

      Microsoft.IdentityModel.Tools.VS, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL

You can then utilize this content in your own WIF-based Visual Studio project templates by manually editing the resultant .vstemplate files.

Wednesday, January 11, 2012

Unable to discover other devices on the network

I recently built a customized Windows Server 2008 R2 installation using RT Server Customizer.

However, after I installed the OS, I noticed that I could no longer access any of the devices on my network.  There were no specific error messages when running the Network Troubleshooter wizard, therefore, I was left to attempt several other things to try and determine the root cause of the problem.

Fortunately, I attempted to run the following at the command line: ipconfig /flushdns

Once I ran this command, I received the following error message: Could not flush the DNS Resolver Cache: Function failed during execution.

After doing a quick Google search for this error message, I found the following Microsoft support article:

This states that you have to ensure that the DNS Client service has been enabled and started on the server.  I looked in my Services Control Panel and sure enough, the DNS Client service had been disabled!

Tuesday, January 10, 2012

Creating Visual Studio Extensions

If you are interested in creating re-usable templates for Visual Studio, you can create these templates quite readily through the help of the Visual Studio SDK and the Export Template Wizard.

Using the Export Template wizard, you will actually be provided with the option to Export a Template as a VSIX file.

Generally, when you Export a Template from the Visual Studio File menu, it simply exports a template as a .zip file which must be manually placed in a Template directory of your choosing.

However, while using VSIX files, you can actually produce an installable template which can be integrated with Visual Studio.

Here is an MSDN article describing one method of creating Visual Studio extensions using the Export Template wizard:

You can download the Visual Studio 2010 SP1 SDK from here:
You can download the Export Template Wizard from here:

Installing the Visual Studio SDK

One issue I recently encountered was while attempting to install the Visual Studio 2010 SDK.

When I performed a Google search for Visual Studio 2010 SDK and came across this particular download link:

However, if you look at the date for the release of the Visual Studio 2010 SDK, you will notice that it was originally released in 2010, thus making it quite old.

If you then attempt to install it on a machine that already has an installation of Visual Studio 2010 SP1, you will discover that it cannot find an instance of Visual Studio on your machine.

Therefore, if you have Visual Studio 2010 SP1 installed, you will instead have to install the Visual Studio 2010 SP1 SDK instead:

So if you need the Visual Studio SDK to begin creating Visual Studio extensions, just make sure you have the correct corresponding version of the Visual Studio SDK downloaded!

Adding files from an ASP.Net Web Site to an ASP.Net Web Application

If you have ever worked with both ASP.Net Web Sites and ASP.Net Web Applications, you will probably have noticed that the biggest difference between the Web Site and Web Application projects is that the Web Application projects also include a .aspx.designer.cs file.

Unfortunately, if you add a file from an ASP.Net Web Site project to an ASP.Net Web Application project, that file is not automatically added for you.  In addition, the Web Application project will not even compile if that .aspx.designer.cs file is not present!

Fortunately, though, there is a workaround to allow your ASP.Net Web Application projects to compile successfully.

  1. Add your ASP.Net Web Site files as usual to your ASP.Net Web Application project
  2. Right click on your ASP.Net Web Application project and select "Convert to Web Application"
  3. When prompted with a dialog stating that the files will add the necessary designer and code behind files, click Yes.
  4. This will now add the necessary files that were previously missing to the ASP.Net Web Site files.
  5. Attempt to re-compile your application now.  
  6. Your project should either successfully compile or at least compile with fewer "designer-related error messages"

Security Token Services

As you may already know, you can create sample STS Web Sites using the WIF (Windows Identity Foundation) SDK through the installed Visual Studio project templates.

However, if you are looking anything more complex than the basic STS templates provided to you, you can look at these 2 CodePlex projects which offer a bit more functionality than the out-of-the-box STS functionality:

The Identity Server project is a bit newer project, but you can use either of the projects for development purposes.  The projects are meant as a good reference for how to implement your own custom STS.