ASP.NET Worker Process Renamed in Windows Vista

August 15, 2009

So apparently the aspnet worker process has been renamed to w3wp.exe on Windows Vista. I hate this operating system more and more each day.


Configuring WCF on IIS 7.0 on Windows Vista

August 15, 2009

First of all, I want to say I hate Vista.

Ok, so this was my first experience using IIS 7.0 on Windows Vista for some local development and ohmigosh; what a pain. I am trying to test some WCF services and I needed to be able to debug. When attempting to view one of my services just to ensure it could be found, I received the following error:

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

I mean it makes sense right; why on Earth would you expect IIS 7.0 to be able to understand a svc file!?!

Luckily I found a solution to this problem from Rahul’s Blog on MSDN on how to fix the problem. The basic steps are:

  1. Open a new command prompt
  2. Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
  3. Execute servicemodelreg –i

After that, try navigating to your service again and it should work. Thanks again Rahul for this helpful tip!

-Flea#


How to Only Allow Numbers in A TextBox

October 13, 2008

I came across a problem the other day. I was working on a ASP.NET application written on the .NET 1.1 Framework and I need to restrict two text box controls to only allow numbers. Being written for 1.1, I did not have access to the slick AJAX Control Toolkit which I could had easily thrown on a extender to force only numbers, thus I had to resort to good old JavaScript!

There actually were lots of examples of doing this on the Internet, but it was challenging to find one that worked period or would work in multiple browsers! Finally, after doing extensive searches and tweaks, here is the final function I used to restrict a text box to only accept numbers:

Javascript Function


// A function that only allows numbers to be typed into a text field.
function NumberValidation(event)
{
var charCode = (event.which) ? event.which : event.keyCode;

return !(charCode > 31 && (charCode < 48 || charCode > 57));
}

ASP.NET Code


<asp:TextBox ID="PageSize" Runat="server" style="width:30px;" MaxLength="3" OnKeyPress="return NumberValidation(event);"></asp:TextBox>

*Note: Even though Visual Studio will indicate you cannot have OnKeyPress in the aspx, you can still put it there and it will work.


Setting the SSDIR environment variable in Microsoft Visual Source Safe

July 27, 2008

I have this problem crop up every once in awhile with using the command
line of Visual Source Safe 2005. I attempt to perform a task and I receive and error back saying “No VSS database (srcsafe.ini) found. Set the SSDIR environment variable to the path of srcsafe.ini for your VSS database.”

To correct this problem, open the command window and go to C:\Program Files\Microsoft Visual SourceSafe

Execute the following command:

set ssdir=\\yourserver\VSS\VSProjects

This should work, of course, verify where your srcsafe.ini file is located before setting the variable.

-Flea#


Windows Firewall and C#

June 19, 2008

This is great for any type of application that requires access to a network. I wrote this WindowsFirewall class that dumps out configuration settings for the Windows Firewall of a local machine. Currently, in this example it just spits it to the console, however, you can dump it to a text file easily. I found a similar example here using VB.NET. Also, Shafqat Ahmed’s .NET Blog had some other examples!

To begin, you will need to add a reference in your project to the COM assembly hnetcfg.dll which can be found at C:\Windows\System32\hnetcfg.dll

using System;
using NATUPNPLib;
using NETCONLib;
using NetFwTypeLib;

namespace ListOfProcesses
{
	/// <summary>
	/// A class that contains methods to display the current information
	/// about the local computers Windows Firewall.
	/// </summary>
	public class WindowsFirewall
	{
		#region Constants

		private const string CLSID_FIREWALL_MANAGER = "{304CE942-6E39-40D8-943A-B913C40C9CD4}";
		private const NET_FW_PROFILE_TYPE_ NET_FW_PROFILE_DOMAIN = NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_DOMAIN;
		private const string LINE_HEADER = "--------------------------------------------------------------------------------";
		private const string SHORT_LINE_HEADER = "-----------------";

		#endregion
		
		#region Constructor

		public WindowsFirewall()
		{

		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Displays a comprehensive list of information regarding the Windows Firewall
		/// </summary>
		public void DisplayFirewallInformation()
		{
			INetFwMgr manager = GetFirewallManager();
			
			this.DisplayFirewallProfile(manager);
		}

		#endregion

		#region Private Methods

		/// <summary>
		/// Returns a firewall manager object
		/// </summary>
		/// <returns>INetFwMgr interface</returns>
		private static INetFwMgr GetFirewallManager()
		{
			Type objectType = Type.GetTypeFromCLSID(new Guid(CLSID_FIREWALL_MANAGER));
			
			return Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr;
		}
	
		/// <summary>
		/// Writes out various firewall configurations for the local firewall policy.
		/// </summary>
		/// <param name="manager">INetFwMgr object</param>
		private void DisplayFirewallProfile(INetFwMgr manager)
		{
			         
			INetFwProfile profile = manager.LocalPolicy.CurrentProfile;

			/*
			 * 
			 * Profile Information
			 *    
			 */

			Console.Write(WindowsFirewall.LINE_HEADER);
			Console.WriteLine("Windows Firewall Report\n");
			Console.WriteLine("\n\n{0}\n{1}", "Profile", WindowsFirewall.SHORT_LINE_HEADER);
			Console.WriteLine("Firewall Policy Type: {0}", this.GetPolicyType(profile));
			Console.WriteLine("Exceptions Not Allowed: {0}", profile.ExceptionsNotAllowed);
			Console.WriteLine("Notifications Disabled: {0}", profile.NotificationsDisabled);
			Console.WriteLine("Remote Administration Enabled: {0}", profile.RemoteAdminSettings.Enabled);

			/*
			 *    
			 * ICMP Settings
			 * 
			 */

			Console.WriteLine("\n\n{0}\n{1}", "ICMP Settings", WindowsFirewall.SHORT_LINE_HEADER);
			Console.WriteLine("Allow Inbound Echo Request: {0}", profile.IcmpSettings.AllowInboundEchoRequest);
			Console.WriteLine("Allow Inbound Mask Request: {0}", profile.IcmpSettings.AllowInboundMaskRequest);
			Console.WriteLine("Allow Inbound Router Request: {0}", profile.IcmpSettings.AllowInboundRouterRequest);
			Console.WriteLine("Allow Inbound TimeStamp Request: {0}", profile.IcmpSettings.AllowInboundTimestampRequest);
			Console.WriteLine("Allow Outbound Destination Unreachable: {0}", profile.IcmpSettings.AllowOutboundDestinationUnreachable);
			Console.WriteLine("Allow Outbound Packet Too Big: {0}", profile.IcmpSettings.AllowOutboundPacketTooBig);
			Console.WriteLine("Allow Outbout Parameter Problem: {0}", profile.IcmpSettings.AllowOutboundParameterProblem);
			Console.WriteLine("Allow Outbound Source Quench: {0}", profile.IcmpSettings.AllowOutboundSourceQuench);
			Console.WriteLine("Allow Outbound Time Exceeded: {0}", profile.IcmpSettings.AllowOutboundTimeExceeded);
			Console.WriteLine("Allow Redirect: {0}", profile.IcmpSettings.AllowRedirect);

			/*
			 *    
			 * Port Information
			 * 
			 */

			Console.WriteLine("\n\n{0}\n{1}", "Port Information", WindowsFirewall.SHORT_LINE_HEADER);
			Console.WriteLine("Globally Opened Ports: {0}", profile.GloballyOpenPorts.Count);

			// Display detailed port information.
			foreach (INetFwOpenPort port in profile.GloballyOpenPorts)
			{
				Console.WriteLine("\n\nPort Name: {0}", port.Name);
				Console.WriteLine("{0, 20}{1}", "Port Number: ", port.Port);
				Console.WriteLine("{0, 20}{1}", "Port Protocol: ", this.GetPortType(port));
				Console.WriteLine("{0, 20}{1}", "Port IP Version: ", this.GetIPVersion(port));
				Console.WriteLine("{0, 20}{1}", "Port Enabled: ", port.Enabled);
				Console.WriteLine("{0, 20}{1}", "Remote Addresses: ", port.RemoteAddresses);
			}

			/*
			 *    
			 * Service Information
			 * 
			 */
			
			Console.WriteLine("\n\n{0}\n{1}", "Services Information", WindowsFirewall.SHORT_LINE_HEADER);
			Console.WriteLine("# of Services: {0}", profile.Services.Count);

			// Display detailed service information.
			foreach (INetFwService service in profile.Services)
			{
				Console.WriteLine("\n\nService Name: {0}", service.Name);
				Console.WriteLine("{0, 20}{1}", "Enabled: ", service.Enabled);
				Console.WriteLine("{0, 20}{1}", "Scope: ", this.GetServiceScope(service));
				
				// Obtain all the port information the service is utilizing.
				foreach (INetFwOpenPort port in service.GloballyOpenPorts)
				{
					Console.WriteLine("{0, 20}{1}", "Port Number: ", port.Port);
					Console.WriteLine("{0, 20}{1}", "Port Protocol: ", this.GetPortType(port));
					Console.WriteLine("{0, 20}{1}", "Port IP Version: ", this.GetIPVersion(port));
					Console.WriteLine("{0, 20}{1}", "Port Enabled: ", port.Enabled);
					Console.WriteLine("{0, 20}{1}", "Remote Addresses: ", port.RemoteAddresses);
				}
			}

			/*
			 *    
			 * Authorized Applications
			 * 
			 */

			Console.WriteLine("\n\n{0}\n{1}", "Authorized Applications", WindowsFirewall.SHORT_LINE_HEADER);
			Console.WriteLine("# of Authorized Applications: {0}", profile.AuthorizedApplications.Count);

			// Display detailed authorized application information.
			foreach (INetFwAuthorizedApplication application in profile.AuthorizedApplications)
			{
				Console.WriteLine("\n\nApplication Name: {0}", application.Name);
				Console.WriteLine("{0, 20}{1}", "Enabled: ", application.Enabled);
				Console.WriteLine("{0, 20}{1}", "Remote Addresses: ", application.RemoteAddresses);
				Console.WriteLine("{0, 20}{1}", "File Path: ", application.ProcessImageFileName);
			}

		}

		/// <summary>
		/// Returns a friendly string format of the policy type.
		/// </summary>
		/// <param name="profile">INetFwProfile object</param>
		/// <returns>string</returns>
		private string GetPolicyType(INetFwProfile profile)
		{
			string policyType = string.Empty;
			
			// Displays what type of policy the Windows Firewall is controlled by.
			switch (profile.Type)
			{				
				case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_DOMAIN:
					policyType = "Domain";
					break;
			
				case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_STANDARD:
					policyType = "Standard";
					break;

				case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_CURRENT:
					policyType = "Current";
					break;

				case NET_FW_PROFILE_TYPE_.NET_FW_PROFILE_TYPE_MAX:
					policyType = "Max";
					break;

			}

			return policyType;
		}
		
		/// <summary>
		/// Returns a friendly string format of the type of protocol.
		/// </summary>
		/// <param name="port">INetFwOpenPort port object</param>
		/// <returns>string</returns>
		private string GetPortType(INetFwOpenPort port)
		{
			string protocolType =  string.Empty;
			
			switch (port.Protocol)
			{
				case NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP:
					protocolType = "TCP";
					break;

				case NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP:
					protocolType = "UDP";

					break;
			}

			return protocolType;
		}

		/// <summary>
		/// Returns a friendly string format of the IP version.
		/// </summary>
		/// <param name="port">INetFwOpenPort port object</param>
		/// <returns>string</returns>
		private string GetIPVersion(INetFwOpenPort port)
		{
			string ipVersion = string.Empty;

			switch (port.IpVersion)
			{
				case NetFwTypeLib.NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY:
					ipVersion = "Any";
					break;

				case NetFwTypeLib.NET_FW_IP_VERSION_.NET_FW_IP_VERSION_MAX:
					ipVersion = "Max";
					break;

				case NetFwTypeLib.NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V4:
					ipVersion = "IPV4";
					break;

				case NetFwTypeLib.NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V6:
					ipVersion = "IPV6";
					break;
			}

			return ipVersion;
		}

		/// <summary>
		/// Returns a friendly string format of the service scope.
		/// </summary>
		/// <param name="service">INetFwService object</param>
		/// <returns>string</returns>
		private string GetServiceScope(INetFwService service)
		{
			string serviceScope = string.Empty;

			switch (service.Scope)
			{
				case NetFwTypeLib.NET_FW_SCOPE_.NET_FW_SCOPE_ALL:
					serviceScope = "All";
					break;

				case NetFwTypeLib.NET_FW_SCOPE_.NET_FW_SCOPE_CUSTOM:
					serviceScope = "Custom";
					break;

				case NetFwTypeLib.NET_FW_SCOPE_.NET_FW_SCOPE_LOCAL_SUBNET:
					serviceScope = "Local Subnet";
					break;

				case NetFwTypeLib.NET_FW_SCOPE_.NET_FW_SCOPE_MAX:
					serviceScope = "Max";
					break;
			}

			return serviceScope;
		}

		#endregion
	}
}

IntelliSense stops working in Visual Studio 2008

May 1, 2008

I had an annoying problem in Visual Studio 2008 that cost me about 3 hours of time. I was working in C# and noticed that my IntelliSense had ceased to work. I went into the options under C# and sure enough IntelliSense was still checked; so I removed the checks, hit OK, restarted Visual Studio, came back in and turned IntelliSense back on. However. It still did not work.

3 hours later, I found the source of my problem. The “Auto list members” check box was no longer checked, thus disabling IntelliSense. This was obscure because one would have thought something with this much control over IntelliSense would have actually been on the IntelliSense settings form but, either way, it fixed the problem as soon as I added the check back.

So if your IntelliSense stops working, make sure you have the “Auto list members” box selected.

1.Goto Tools | Options
2.Text Editor
3.C#
4.General
5.Check ‘Auto list members’


US Zip Code Table for SQL 2005

March 23, 2008

I am working on a web application that requires that the user to enter in a zip code and then the city and state would be returned. This type of functionality is quite common, but for some of us developers, we don’t want to pay for the data needed to make this happen. Granted, it didn’t take me too long to find a free table of zip codes, but I did have to do some minor work to hook it all up. So, just to add to the bounty of the Internet, I’ve uploaded the CSV file to one of my servers for you to download along with instructions below for inserting it into your SQL 2005 database. Since this is in a CSV file, you can also use it for MySQL or any other database.

  1. Click here for the ZIPCODE CSV file. Download it to the root of C, just something simple.

  2. Run the following SQL to create the ZipCode table in your database:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ZipCode]
(
[ZipCode] [varchar](10) NOT NULL,
[Latitude] [varchar](50) NOT NULL,
[Longitude] [varchar](50) NOT NULL,
[City] [varchar](200) NOT NULL,
[State] [varchar](50) NOT NULL,
[County] [varchar](70) NOT NULL,
[ZipClass] [varchar](50) NOT NULL
) ON [PRIMARY]
GO

  1. Run the Bulk Insert command to load the CSV file into the table:

BULK INSERT ZipCode
FROM ‘C:\zipcodes.txt’
WITH
(
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’
)
GO

There ya go, you now have a free zip code table of all 42,000+ United States zip codes! Note that you might need to change the commas and ‘ ‘ marks; sometimes these characters are formatted differently when posted on the web and it can cause havoc in SQL because SQL does not recognize the characters. Just be prepared to change them!

-Flea#


Follow

Get every new post delivered to your Inbox.