# Saturday, September 26, 2009
Close up blog entry

I’m finding that SMTP is a bit of a nightmare. The blog software I’m using uses the .NET System.Net.Mail.SmtpClient class to send email using SSL. Trying to send email through my Yahoo or Comcast SMTP server would continually timeout.

It works fine if not using SSL, but I really do not want to send my email password base 64 encoded across the internet! In fact, beware using email clients that are not using SSL or at least CRAM MD5 for SMTP authentication.

I tried to send email using SSL using port 465 to both the Yahoo and Comcast SMTP server without success. To troubleshoot the problem I wrote a small console application to use the SmtpClient to send email. I tried every variation I could think of to no avail.

After a lot of web searching I found a post which alerted me to the possibility of using SSL with gMail using port 587

I tried port 587 on the Yahoo SMTP server, but it is not configured for SSL. I was finally successful sending an email using SSL with the Comcast SMTP server on port 587.  Of course, this was after hours and hours of frustration!

I never could get the Yahoo SMTP server to work. The SendEmail call hangs and finally times out. Maybe there exists another port that will work, but I decided to drop it for now.

Share/Bookmark
Saturday, September 26, 2009 12:12:17 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, September 19, 2009
Close up blog entry

This post addresses the situation in which you want to redirect all subdomains to your main domain and you are using host headers in IIS.  The main problem is the host header binding in IIS does not allow wildcards. Since you can not use wildcard host headers any subdomain requests will never reach your web site’s URL Rewrite processing. The following is the technique I use to do subdomain redirects on a web server hosting multiple sites using host headers.


For example lets say you have a web server that hosts www.abc-test1.com and xyz-test2.com. You want all subdomain requests to return 301 redirects to the main domain. 

First you’ll need to configure your DNS host to map all subdomains to your web site IP address. For www.abc-test1.com this will be something like *.abc.com.  How you accomplish the DNS configuration will depend on who handles your DNS. If your DNS provider does not provide wildcard DNS entries you’ll want to find one who does.


Create a web site without a host header defined. This web site will use URL Rewrite to redirect subdomain requests to your main domain. I chose to call this web site Redirector. It should never respond to web requests, so it is essentially an empty web site. The binding for the redirector site will look like the following:

redirector-binding

Your host header bindings for www.abc-test1.com and xyz-test2.com:

 abc-test1-binding

xyz-test2-binding


Your rewrite rules in the web.config file on the redirector site will look something like the following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="abc-test1 Redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
              <add input="{HTTP_HOST}" pattern=".*abc-test1\.com" />
              <add input="{HTTP_HOST}" negate="true" pattern="www\.abc-test1\.com" />
          </conditions>
          <action type="Redirect" url="http://www.abc-test1.com/{R:1}" redirectType="Permanent" />
        </rule>
        <rule name="xyz-test2 Redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
              <add input="{HTTP_HOST}" pattern=".*xyz-test2\.com" />
              <add input="{HTTP_HOST}" negate="true" pattern="^xyz-test2\.com$" />
          </conditions>
          <action type="Redirect" url="http://xyz-test2.com/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

The above rewrite rules will look the following in the GUI configuration:

abc-test1-redirect

xyz-test2-redirect


Given the above configuration if you request any subdomains they will be permanently redirected to the main domain. For example: test.abc-test1.com, www2.abc-test1.com, abc-test2.com, and any variation will be 301 redirected to www.abc-test1.com. Likewise test.xyz-test2.com, www2.xyz-test.com, www.xyz-test2.com, and any variation will be 301 redirected to xyz-test2.com.


There are likely other ways to accomplish subdomain redirects, but this is working out for me.  Hopefully this helps someone else as well.


	   
Share/Bookmark
Saturday, September 19, 2009 12:42:00 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, September 17, 2009
Close up blog entry

I use Vista with UAC turned on. I know, I know, just turn it off! :-) I’ve considered turning it off, but I’ve gotten used to it for the most part. The one file that drives me crazy though is the hosts file that sits in the c:\windows\system32\drivers\etc directory.

I very often need to edit the hosts file to override a domain name or create a domain name for testing. It drives me crazy to have to open it in my editor as administrator.

You can bypass this if you grant your logged on user read and write permissions to the hosts file. Now you can open the file without elevated administrator permissions :-D

Keep in mind you are reducing your security, but turning off UAC reduces your security even more.

By the way, I know some people would suggest turning off UAC entirely no matter what. I don’t get too bent out of shape about it either way. If someone uses drag and drop a lot I understand why UAC goes bye bye very quickly :-) I’m not much of a drag and dropper so I don’t mind much.

Share/Bookmark
Thursday, September 17, 2009 10:05:52 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, September 14, 2009
Close up blog entry

Most video games, especially console games, have varying difficulty levels. Usually a game will default to normal mode. Then for a real challenge you can choose hard mode. Unfortunately I was living life on hard mode for decades.

Everything was so difficult for me to get through. School, the US Navy, college, and  getting through a normal day was a constant challenge. I’d have to push myself so hard to accomplish anything. If I hadn't always been so tired so many things would have been so much easier.

I can tell now what it is like to live with OSA as I have a new frame of reference from which I live my daily life. I didn’t know for the majority of my life that how I felt was not normal. Sleep for 10 hours and wake up tired. Tired all day and every day. Wishing for a nap in the afternoon. Barely able to stay awake in the evening. Inevitably if I was asked how I felt my default response was, “I’m tired”.

My wife couldn’t take my horrible snoring and gasping when I slept. In the evening while talking to my wife I would literally doze off in the middle of a conversation. Thankfully she got me to finally go pursue my tiredness with my doctor and follow through with a sleep study and on to an OSA diagnosis. I’m not thankful for having OSA, but in a way I’m thankful it was something that can be identified and remedied. I now sleep every night with a Continuous Positive Air Pressure (CPAP) machine.

A CPAP machine is basically a small air compressor with a hose attachment. The hose attaches to a face harness which has a soft plastic piece which fits in your nostrils. The air pressure generated by the machine inflates the throat which stops it from collapsing while you sleep. In my case I stop breathing while I’m sleeping around every 3 minutes. When the air way closes up your body then has to jolt itself awake to keep from suffocating. This means a person with OSA never gets into deep REM sleep. I can tell you never getting that REM sleep makes life a bit difficult!

I’ve read forum posts about how it can be so hard for a lot of people to adapt to using a CPAP machine. It is too bad because it would change their lives. I hope someone will come up with something better than having to inflate a person every night. Fortunately I’m the type of person who can weather discomfort. Having a hose connected to my head blowing air up my nose all night isn’t exactly comfortable, but sleeping without it means a day of semi-wakefulness.

Sleep does become a bit of a chore. There is no lying down, getting comfortable, and drifting off to sleep. I don’t care though, I’d rather live the rest of my life awake rather than wandering around in a constant haze.

When I woke up the first night of using the CPAP machine at the sleep study clinic it was one strangest feelings of my life. I woke up and I wasn’t tired! The technician who woke me up asked me a serious of questions the first being did I feel alert. I replied that I actually did feel alert. I had never felt that way before in my life. I didn’t realize how a person is supposed to feel after sleeping.

This web site would not exist if I was not using a CPAP machine. I’ve wanted to create software on my own all my life, but I just couldn’t do it.  I was just too tired after getting through the day of work and life.

With my first son it was tough. For the first few months, with the sleep you get with a newborn, I felt like death warmed over. Normally if I get little sleep I wake up feeling sick to my stomach and my body and mind would just hurt. Now I’m still tired if I don’t get enough sleep, but I can get through the day without much problem.  During the 2 years I’ve used the CPAP machine I’ve probably only napped a few times even having to care for two young children. Absolutely amazing :-)

I normally would not divulge something of a medical nature to the public about myself, but if this helps one person find out they have sleep apnea and they get help then this post was well worth it.

If you suffer from constant tiredness no matter how much you sleep. If your significant other tells you that you gasp for air when you sleep. Please talk to your doctor and see if you can get referred to a sleep specialist. A sleep study is very expensive, so hopefully your insurance will cover it. If you have OSA and you can stand the CPAP machine it is well worth it. It will literally change the rest of your life for the better.

I only wish my OSA had been diagnosed and dealt with decades ago. I would have accomplished so much more of what I wanted to do. It is always better late than never though!

Share/Bookmark
Monday, September 14, 2009 12:13:53 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  | 
# Sunday, September 13, 2009
Close up blog entry
image

I don’t have much time to play games anymore given work, kids, and life in general. It  took me about six months to get through God of War :-) When I finally beat the game I took a mental pause and thought, “This might be the best game I’ve ever played”.

After letting that thought swirl around for a bit I’ve come to the conclusion that it is the best game I’ve every played.

Throughout the game you control Kratos, a Spartan warrior who serves Aries the God of War. I’m not sure you could call Kratos a hero as he does not hesitate to remove obstacles from his path whether they pose a threat or not. I’ll give fair warning: this game is extremely violent. This game is not for the faint of heart or maybe even the stout of heart. Kratos is outright brutal when fighting his enemies. He doesn’t pull punches or think twice about rip something in half :-)

From the cut scenes, boss fights, and the normal game play the game looks awesome. I give the graphics extra points just for the fact that it is a PS 2 game. Some of the boss fights are absolutely epic in scale. The way Kratos dispatches his enemies has a certain smoothness and power that most games do not come close to capturing. The game, more than any other I’ve played, successfully pulls off fighting many enemies at once. Sometimes Kratos has to plow through 15 to 20 foes without any awkwardness with the game controls.

Yes the game came out in 2005 so why review it? Well, others like me may be a bit behind the times, so if you haven’t played God of War go out and buy a PS 2 plus God of War and play a game that should not be missed!

Share/Bookmark
Sunday, September 13, 2009 11:01:06 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, September 08, 2009
Close up blog entry

I created a WCF web service that I wanted to host on a web site and domain different from my main TheThoughtfulCoder.com domain. The problem is AJAX calls can not be made to different domain names, even if they are sub domains.

I'm using dasBlog to host my main blog site and I don't want to put my web services in the same project. I want to keep my web services completely separate. So making a call from thethoughtfulcoder.com to a web service hosted on the domain services.thethoughtfulcoder.com can not be done. Hmmm...bummer!

I found a way to make this work in a straight forward manner. At least I think it is :-)

IIS 7 has an addon called Application Request Routing which allows IIS to proxy calls to another web site to satisfy cross domain rewrite rules. Ah ha! Now I can rewrite a reqeust to a service on my main site and on the web server rewrite it to my services subdomain. To set this up I followed the steps listed below.


Download and install Application Request Routing from Microsoft.
Go to the web server machine home in IIS Manager. The machine home is the root node of the web site in the Connections tree panel. Go into the Application Request Routing feature. ARR Snippet

In the Application Request routing configuration, check the Enable Proxy checkbox. I'm using the default application request routing settings. ARR Enable Proxy Snippet

I created a rewrite rule on the TheThoughtfulCoder.com that treats the directory http://TheThoughtfulCoder.com/ttcservce as the place holder for the web service. The rewrite rule will rewrite any URL with /ttcservice/ to the web service http://services.thethoughtfulcoder.com/TTCService.svc. Since application request routing is enabled on the web server the rewrite rule will cause IIS to make a proxy call to the other domain! In case you're curious I'm using host headers to separate the web sites hosted on a single web server.Service proxy rewrite rule The above rewrite configuration will generate the following XML in the web.config file:
<rule name="TTC-Service Rewrite" stopprocessing="true"> 
   <match url="^ttcservice/(.*)$"> 
   <conditions logicalgrouping="MatchAll">  
   <action type="Rewrite" url="http://services.thethoughtfulcoder.com/TTCService.svc/{R:1}">
   </action> 
   </conditions> 
   </match> 
</rule>

If you have any questions or need any clarification please let me know and I'll try to clarify the steps. Of course there are likely many other ways to accomplish making cross domain AJAX calls, but this solution might be good enough :-)

Share/Bookmark
Tuesday, September 08, 2009 10:59:32 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, September 07, 2009
Close up blog entry

I was missing the *.svc IIS 7 handler mapping. I started working on adding it manually but decided to research it a bit. It ends up you can run:

%windir%\Microsoft.NET\Framework\v3.0\WindowsCommunication Foundation\ServiceModelReg.exe –i

to add all the IIS configuration for WCF services. Use the Framework64 folder if you are using a 64-bit OS.

Share/Bookmark
Monday, September 07, 2009 4:39:05 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [1]  | 
Close up blog entry

This little utility makes calls to a WCF service that calls the appropriate .NET HttpUtility function to perform HTML and URL encoding and decoding. I often need to perform these operations on some text so I hope this will help others as well.

I created a RESTful WCF service with a lot of help from Rick Strahl's posts: jQuery AJAX calls to a WCF REST Service and WCF REST Configuration for ASP.NET AJAX. These are great posts about how to create WCF services that are callable from jQuery using JSON serialization.

Share/Bookmark
Monday, September 07, 2009 11:56:42 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |