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, 2009First 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:
- Open a new command prompt
- Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
- 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, 2008I 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, 2008I 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#
The Price of Prejudice – A Response to Portfolio Magazine
June 23, 2008Portfolio Magazine, a left slanted business magazine wrote this edititorial commentary about why business should support gay marriage. I emailed the following response back to their editors (letters@portfolio.com) and also posted it on their blog.
————–
To the Editors of Portfolio Magazine,
I just finished reading your commentary The Price of Prejudice, where you commend the Supreme Court of California for overturning the vote of the people to legalize gay marriage. I think your appeal to business and capitalist to push for gay marriage to “recruit, retain and motivate the best and the brightest” is unfortunate and incorrect. The United States has been an economic powerhouse for decades, if not a century, without the need for gay marriage. Your warning to us that countries such as “Canada, Spain and South Africa” are legalizing gay marriage, therefore we should be concerned about losing top notch talent and business is laughable. The United States had an estimated $13.84 trillion GDP in 2007, where as Spain had $1.352 trillion, Canada was at $1.266 trillion and South Africa…..wait are you ready for this…. $467.1 billion GDP.
The most unfortunate realization about this article you wrote is that you completely deny the fact that the voters of California were overruled by the courts. You then go on to say how the “majority of Americans” oppose same-sex marriage. You should be writing an article about how disgusting and un-American it is for courts to overrule the people.
Your socialist agenda is going down a slippery slope when you favor activist courts over the vote of the people. I would hate for your magazine some day to get squelched by some activist court or government as your brethren in Iran have recently faced with the shut down of that Iranian Daily newspaper who simply opposed the Government.
I would protest your magazine by not paying for it and cancelling my subscription, but I don’t pay for it, I read it for free at the library. Isn’t socialism great?
Windows Firewall and C#
June 19, 2008This 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, 2008I 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, 2008I 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.
- Click here for the ZIPCODE CSV file. Download it to the root of C, just something simple.
- 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
-
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#
How to create a scheduled task using PowerShell
February 21, 2008I found this insanely easy, thanks to some well written Microsoft documentation (shocking I know). If you need to create a scheduled task of an application in your PowerShell script you can call the Schtasks.exe application. Below is an example I used to create a scheduled task to run my exe every day at 1:00a.m. using the System account:
Write-Host “Creating Account Collector Scheduled Task”
Schtasks /create /sc DAILY /tn AccountCollector /tr “`”`”`”`”C:\Program Files\AMF\AMFCollector.exe`”`”`”`”" /s devsbvm01 /ru System /st 01:00:00
Write-Host “Scheduled Task Created”
That’s it, works painlessly on a local or remote server, which in my example, devsbvm01 is my remote server. Now, you might be wondering “whats with all the quotes?”. Well, I struggled for a long time trying to figure out why the scheduled task would be created but would never run. Turns out that the qoutes were being stripped out, thus causing the path to break. I know its sleazy, but turns out you need four sets of quotes in order to keep them from being stripped out! If anyone ever finds a better way, let me know but this seems to be it for now! So make sure you put those quotes in there!
-Flea#
How to check if an object exists in a SQL 2005 Database
February 13, 2008When executing some SQL code on an object in database such as a table, stored procedure, or view, it is important to check to see if these objects currently exist in the database. It is important because it makes your code more reusable, especially if multiple developers will be running it on their local databases. Here is a simple line of SQL you can run to find various objects in a SQL 2005 database.
How to check if an object exists in a SQL 2005 Database
if exists (select * from sys.objects where [object_id] = object_id(‘the_name_of_your_object’))
begin
print ‘Hello World’
end
How to check if a stored procedure exists in a SQL 2005 Database
Say your Database contained several hundred stored procedures and you wanted to know if the stored procedure usp_GetNames existed. Simply run the following example from above:
if exists (select * from sys.objects where [object_id] = object_id(‘dbo.usp_GetNames’) )
begin
print ‘Hello World’
end
How to check if a view exists in a SQL 2005 Database
What if you wanted to create a new view called dbo.vw_OldCustomers, but wanted to see if that view existed before you created it? Again, run the same SQL code above.
if exists (select * from sys.objects where [object_id] = object_id(‘dbo.vw_OldCustomers’) )
begin
– Logic to create the view and populate it
end
-Flea#
Posted by fleasharp
Posted by fleasharp
Posted by fleasharp 