Configuring IIS 7.5 logging in Windows 2008

Raw log file for your website gives you the facility to see who’s been accessing your webpages with information on the client IP address, the time the request was made, the referrer, time taken to process the request and so much more. That’s why it is essential to have logging enabled for your site.

In Windows 2008, you can choose among different log file formats (IIS, NCSA, W3c and Custom). If you go to the IIS Management Console, you will see “Logging” under IIS features and when you double click on it, you will have a couple of options to choose from. IIS and NCSA do not allow you to change what is being logged but with the other two formats you can. W3C format is the preferred format for many people. With that format chosen for your log files, you can select which fields you want to get logged for each HTTP request by clicking on the “Select Fields” button next to the file Format. The log files are saved in the following directory by default:

C:\inetpub\logs\LogFiles

You can also choose how often a new log file is created by selecting the best option for Log File Rollover. For high traffic sites, you can have it daily or hourly but if you have a moderate traffic, going with the monthly log is the way forward. You should also check the option for “Use local time for file naming and rollover” to make it easier for you to distinguish between the various log files created.

Custom IIS logging

If you want to re-arrange the fields in your log file, you will have to go with Custom logging. For example, if you wanted the client IP address to come before the date and time of the http request, then only custom logging will allow you to do that. You cannot also change the name of the log file name, it is in the format of u_exYYMMDD.

Although custom logging for IIS gives you a lot of flexibility in terms of what gets logged and many more, there’s a major drawback to that approach and that is performance.  The IIS worker process handles custom logging and the HTTP.sys kernel-mode cache is disabled for IIS which degrades performance (see this link for more information).

Changed from pay monthly to pay as you go tariff with o2

Seeing that I was only using a fraction of the allowance on my pay monthly contract, I decided to downgrade to a pay as you go tariff on my iPhone. I opted for the text and web plan because that made more sense for me. I wanted to keep my mobile number and o2 said that they would send me another sim card through the post as the other one would not work when it was time for the switch over.

Couple of days after the call to 02 to switch plans, I received the Pay as you go sim card. I was told that I would need to switch the sim cards on the date that the switch over would happen which was 2 weeks from my initial call to 02. All they told me was that I would just need to remove my old sim card and insert the new one and everything would work fine. They also mentioned that it could take several hours before I would be able to use the new sim card.

On the switchover date which was yesterday, I changed sim cards because my pay monthly sim showed “No service” at the top instead of showing me the 02 mobile service operator. I tried to call my cell phone but I received “The person you are calling is not accepting anonymous calls” message. I thought that the new sim card was not ready to use. Since the switch over happens at midnight, I expected things to start working back to normal within 12 hours but I still could not get through at 7pm in the evening.

So my mobile phone was not working and I was getting nervous now. I tried switching it off and back on a couple of times but that did not work. Although I knew I couldn’t make calls because I have not topped up yet, I tried that as well and it prompted me to top up which I denied. I wanted to know that everything was working fine before I spend my money. O2 send me a couple of messages and they said that switching the mobile on and off until it connects is the way to go but obviously that did not work. I decided I was going to call 02 the next day if it does not work because if I call them on the same day, they would just say that it needs time and the switchover would happen sometime soon.

Well the next morning, the mobile was not working and I gave 02 a call and the agent told me that I need to top up first before I can use the phone. She said that it’s only when you top up for the first time that the pay as you go sim card gets activated. Well why did 02 not tell me anything about this in the first place? For a whole day I was not reachable, I could not make/receive calls and text messages and spent time looking on the net for a solution to the problem when o2 could just have told me this.

Instead of sending me text messages for extras that I can get, I would prefer them to tell me how to get my sim card to work. Anyway there was a new number on the new pay as you go sim card but that was overriden with my previous mobile phone number. For now everything is fine and I’ve associated my bank card with the sim for easy top up.

Upgrade to iPhone OS 4 and lose everything

A while back, when I was syncing my iPhone, a message popped up to say that there was a new version of the iPhone OS and that I should upgrade. Without much thought, I upgraded to the iPhone OS 4 and was very happy that I had the latest software for my iPhone.

A few days later, I noticed that some of my pictures were gone. Some recent pictures that I took when on holiday had disappeared. I blamed it on the upgrade and thought that at least I had the majority of my pictures.

Some time after that, I noticed that my music library had completely gone. So I’ve got an iPhone with no songs or videos. Seems like I’m using the iPhone for calling and nothing more now.

Since I use WIFI at home, I’m set up the iPhone to connect to my home broadband and every now and then I use it. What I didn’t realise is that wifi on the iphone connects you to the mobile carrier of your iPhone service provider and at the end of the month, I was presented with a bill of £25 just for data. I called up O2 and they said that I’ve used that much in terms of internet data and I was furious because with OS 4, iPhone has changed the way the network connection used to be. I’ve got a perfectly good computer at home and I would be silly to use my Iphone for internet if I have to pay for it when I’ve got broadband free at home.

I’ve had to completely delete the mobile carrier name from my iphone to prevent any further charges (delete mobile.02.co.uk). If you’ve got data included in your package, then you’re fine (idata.o2.co.uk) but having to pay unfair charges because Apple forgot to mention that they were changing the network properties in iTunes is ridiculous.

So if you’re upgrading to iPhone OS 4, you’ll definitely be in for a surprise!

Combining ASP.NET website into a single assembly

With a Web Application Project (WAP), you get a single assembly when you build your project. However with an ASP.NET Website, the output is spread among many dll files. The closest you will get is having all your classes in the AppCode folder in one assembly and the other classes in separate assemblies. Depending how many files you’ve got in your website, this can amount to a lot and I think having one single assembly is better for a number of reasons, the primary one being deployment onto a production server.

Instead of converting my ASP.NET website to a Web Application Project, I decided to use the aspnet_compiler.exe to build the website output and use aspnet_merge to merge the assemblies together. This means that everything for the website will be in one single assembly but note that other assemblies that you’re referring to will stay the same such as log4net, nhibernate etc.

You will need to go to Visual Studio Command Prompt to issue the following commands:

aspnet_compiler -v TestWeb -p “C:\Projects\TestWeb” “C:\Projects\TestWebCompiled”

aspnet_merge “C:\Projects\TestWebCompiled” -o Gis

This will first compile your website files and then merge the assemblies. You may encounter the following error when you use the aspnet_merge tool though:

aspnet_merge: error occurred: An error occurred when merging assemblies: ILMerge.Merge: ERROR!!: Duplicate type ‘FooterControl’ found in assembly ‘App_Web_xd23ggdz’.

In my case, it was because I had two web controls with the same name. I had to delete one of them but you can just rename yours and it should work fine afterwards.

There’s a great video at http://www.asp.net/general/videos/how-do-i-use-the-aspnet_mergeexe-utility-to-merge-assemblies showing you how to use the both the asp.net compiler and the asp.net merge tool.

The only thing I need to figure out now is how to remove certain files/folders from being compiled.

Cannot install iTunes on 64 bit Windows 7

I’ve installed Windows 7 64 bit on my computer which had Vista previously and I was in the process of adding the softwares that I use often when it came to iTunes on my list, problems started occuring. I downloaded the iTunes for windows (64 bit) without any problems but couldn’t get it to install. I’ve read on the web that quite a lot of people were having trouble downloading the iTunes setup package itself but my problem was different.

When I double click on the iTunes installer, it shows the progress bar for a split second and disappears. So I googled the problem and found that a lot of people were having the same problem. I know I’m using the 64 bit version of Windows and I downloaded the right package for my OS. On Apple’s website, I’ve tried everything listed on there. I’ve cleaned up my TEMP folder (in AppData under my username), remove all the programs (Bonjour service, QuickTime etc) and even changed msconfig to go onto selective startup as suggested by apple to no avail. I’ve had to uninstall Adobe Master Collection CS3 Suite to remove that annoying bonjour service and edit my windows features to delete everything from the TEMP folder and nothing worked.

I’ve spent hours on this and it’s really frustrating that I can’t sync my iPhone because Apple released a crap version of their iTunes installer. It’s not like there’s something wrong with my PC because I’ve got a fresh install of Windows 7 on it. So blame Apple! I’ve tried different versions, mix and match QuickTime as a standalone program or QuickTime with iTunes and nothing will get the iTunes install. I’ve even tried it on 3 separate computers! Now this surely is a joke, isn’t it?

Out of desperation, I installed a 64 bit version of iTunes 8.0 instead of iTunes 10.1.1 and got that to install without any problems. However when I plugged in my iPhone, iTunes complained that it was not compatible and that I needed to upgrade to the latest version (10.1.1). So all that for nothing. Deleted the old iTunes, tried again and back to square one. So now I’ve got an iPhone with no songs on it and I can’t sync it. Well done Apple.

UPDATE 08 Feb 2011 : I’ve just downloaded iTunes Setup 10.1.2  for Windows 64 bit and it installed without any problems. However when I plugged my iPhone to the computer, it did not recognise it. So I went to Device Manager in Control Panel and there was the little exclamation icon next to the “Apple Mobile USB Device” and I had to manually update the driver but after that I was able to sync my iPhone.

Designing an email notification system in asp.net

I’m currently working on a Question/Answer website and users are notified of new answers to a question they’ve subscribed. Similarly emails are sent out when there are new comments to an article for which you’ve subscribed. The other types of emailing present in the system is when a user registers for the first time and an activation email is sent out to them or when they send a request to reset their password through a “Forgotten Password” link or when the administrator wants to send out an email to every member (kind of a broadcast or newsletter thing).

To me, the registration and password reset email need to be sent straight away for a good user experience. So this can be done synchronously as soon as the registration form is completed or the password reset button is clicked. However when a user adds a new answer/comment, you cannot have the same worker process handle the notification, that is, send emails to subscribed users to tell them there’s a new answer/comment. This will be bad experience for the user who submitted the answer/comment because the request will be blocked until the emailing is done and if you have to notify 100 users, this can take a really long time.

There are a few things which can be done though such as getting the email sending to be done asynchronously, relaying the emails from IIS SMTP to the mail server or using MSMQ (Microsft Messaging Queue) to queue up the emails.

Sending emails asynchronously in C#

With .net 4.o framework, it has become even more easy to send emails asynchronously. You will need to have the Async property to true in the Page directive and use SendAsync instead of Send on the smtp object (you need to hook up the delegates as well but I’m not going into that for the time being).

What happens then is that the worker process which served the http request will be returned to the application pool once the async method is hit and another thread will be processing the asynchronously event. Once it is complete, the response is then sent to the user. The advantage of doing this is that you free up worker processes to serve other http requests instead of starving the thread pool. When your async job is finished, another worker process will be grabbed to finish off the request which had the async method.

The main disadvantage of the async page is that the user who initiated the request will have to wait until the async event completes before he sees any response. If you’re doing heavy work (as in emailing 100 people), then the user can get really frustrated and leave and that’s not very good for user experience. Http requests need to be quick and process intensive tasks need to be done by a background thread.

What we really need is a fire and forget method and that can be achieved with a background thread (see this link http://www.jdconley.com/blog/archive/2009/01/14/fire-and-forget-email-webservices-and-more-in-asp.net.aspx). Context switching is an expensive task though and the problem with this approach is that the thread will go into unmanaged code, so you will need to be careful what it’s doing.

IIS SMTP relay to remote mail server

Using the System.Net.Mail library is great but communicating through the SMTP protocol is an expensive task. First a connection has to be established with the remote mail server and then the destination email address needs to be checked and if it exists, then the delivery of the email can be done. Now imagine doing that for a large amount of emails. It will take a really long time. Therefore it is much easier to use PickupDirectoryFromIis or SpecifiedPickupDirectory for the SmtpDeliveryMethod.

If you use Network delivery, then the email will be sent through the smtp protocol but if you use PickupDirectoryFromIis, then the email is saved as a file in the \inetpub\mailroot\pickup folder with the .eml extension. Email files are easier to process and since you’re not connecting to the remote mail server and simply saving the emails as files, you will find it much quicker to process.

Once in the pickup folder though, you will need a certain process to deliver the emails. You can get IIS Smtp to deliver the emails directly or have it relay to your remote mail server.  The latter is the better approach since your mail server can do the spam checking and authentication and will not be blacklisted by other email servers.

IIS SMTP on Windows 7 and Windows 2008

It is important to note that Windows 7 does not come with a version of the IIS SMTP server. With Windows 2008 though, you can get the SMTP installed by going into Features and adding it but it runs in IIS6 mode and not IIS7 or IIS7.5. Therefore you will need to have IIS6 running on your server even if you use IIS7/7.5 for your websites.

The IIS SMTP service should be used as an email relay in the sense that email dropped in the pickup folder are forwarded to the actual email server (smtp) for processing.

Using Microsoft Messaging Queue (MSMQ) to notify users through email

A queuing system is a good way to send email as MSMQ can help with that. Basically, instead of sending the emails directly to the mail server through the network, you save the messages in a queue with MSMQ. They will stay in the folder they’re saved and another process (eg a windows service) can read that folder and process the emails (deliver them). The main advantage to this is that you do not overwork your CPU as in 100% at peak times and 0% during non-peak hours but rather use the CPU in a more efficient manner because the work is queued up and can be processed when resources becomes available.

The following link is a good start (http://dotnetslackers.com/articles/aspnet/Sending-email-from-ASP-NET-MVC-through-MVC-and-MSMQ-Part2.aspx).

Conclusion

The mechanism behind sending mass emails to users who have subscribed to a particular service is very important because you do not want your users to wait a long time because there’s a slow process which has been triggered by some action they’ve taken on your website. For the user, things must be quick and it is therefore important to have background tasks run on a different thread than the calling thread.

Question and Answer websites – Q&A

Knowledge should be easily shared and made available to others without having to pay an excessive amount of money. Ideally it should be free but there are times when that’s not possible. However I believe that many individuals have a lot of knowledge and experience which could be helpful to others and if these people were to share what they know, then life would be a lot easier to deal with.

I’ve always been fascinated with Question and Answer websites because the potential of these systems is really huge. At one point in everyone’s life, there comes a time when you have this doubt/question and you want someone to point you in the right direction. By yourself, it can take a substantial amount to time to resolve the problem but if someone was there to guide you, then it would make the hurdle easier to cope with.

My idea of a Q&A website is a place where people can ask questions no matter how trivial they might seem and get answers from other people. Of course, there’s no guarantee that the answers received will definitely resolve the problem in the said question but at least it can give the asker an idea how to go about solving the question. Sometimes there may be someone who’s had the same problem before and can therefore post a really good answer which would address the question being asked or there might be experts in the question field and therefore, it would be easier to tackle these questions objectively.

The Q&A system would need to have a reputation system whereby people who contribute constructively are rewarded in the community. This can be in the form of different levels attached to a user’s profile or points accummulated over a period of time. Not only does this show how engaging the member is but an answer from a reputable member is worth more attention than that from a person who posted his first answer. This is not to say that a novice cannot provide a great answer but when someone has built a reputation, it is easier to trust their contribution.

Questions can be voted on and rise up the scale when it gets really popular. This can be used to show that a lot of people actually like the question and think that it is interesting. They may not have asked the question themselves for one reason or another but are grateful that some other person has.

Answers should be votable as well and this helps to show which answers are better and which ones are not so good. When this happens, answers with more votes rise to the top and that helps a person searching for that particular question to easily locate the answer which more accurately addresses the question instead of the searcher having to go through all the answers and see which one is the best. Similarly a best answer option is a great way to label great answers and this should take that answer to the top of the page just below the question so that it is the first thing that you see when looking at a question.

Of course with such a system in place, it is upto the community to moderate the content that is being posted. So there must be a mechanism in place to report offensive content and members must be encourage to use that feature. Points should be awarded for doing good karma and the same applies for people trying to spoil the community, that is, negative points and when it gets below a threshold, an automatic ban is issued.

Articles for more in depth information

The question/answer website takes in generally a short question and several short answers. Most of the time, it is something very specific and there’s no need to go in details if a one line phrase can answer the question. This is why is believe that a section should be created for articles where indepth coverage of certain topics can be discussed. For example, an article on “Electric cars” might discuss the various technogies used and the best cars that we have so far whilst a question labelled “What is the best electric car” requires a 1 liner stating the make/model for the best electric car. However a link from the question page to the article page would be really helpful as a person looking for more information on the subject matter can read more.

Contests

I think that contests are a good way to engage the members of the website. You could do a contest for the best night photography and let members upload their best pictures and have other members rate/vote them. The one with the highest vote can receive a badge or something more tangible sent to him.

Poll

Poll is another good way to have your users interact with your website more. Polls can be anything really eg, have a list of 10 songs and ask users to vote on their favourite. At the end of a pre-determined time, you can close the poll and show the results to everyone.

Multiple networks in Windows 7 – Unable to connect to the Internet

After upgrading my Vista PC to Windows 7, I installed a few programs that I use frequently and was hoping everything was going to be fine. However things turned out to be a headache when I could no longer connect to the Internet. I connect to the Internet through a network cable that comes straight from my Netgear router, so there couldn’t be any wireless problems. I tried to hover over the little network icon in the system tray and it showed a message telling me that I was connected to multiple networks. I knew straight away that this was the problem and if I could get rid of multiple networks and make it connect to just 1 network (my home network), then that would solve my problem. Strangely enough, there was no option to delete the other network m (Public Network) from Windows.

I tried a few things and the only thing that worked was to disable the network adapter and enable it again. This would get rid of the multiple network problem and connect to my home network as it should do. However when the computer is restarted, the problem would come back again. I wanted to find a more permanent solution to the problem. So I searched on the web and it turned out to be a problem with a service called “Bonjour Service”. That’s  a program from Apple and basically it kicks in before another service and that’s where the problem starts. If you go into services, you will not find a service called Bonjour Service as it’s named some like “##IdString1…”. You will have to set that service to delayed autostart or disable it to get your internet working again.

The Bonjour Service got installed on my computer when I installed Adobe Photoshop CS3 but if you use iTunes, you are bound to have it as well. It’s a perfectly safe program but should be marked as Start type – Automatically (delayed) if you want no hassles with your internet connection.

SD card reader (Mass storage device) driver for Toshiba Windows 7

I recently upgraded one of my laptops from Vista to Windows 7 and everything went smoothly except when I tried to insert an SD card in the memory slot and found out that it was not working. When I checked Device Manager in Control Panel, I saw that there was a “Mass Storage” device which had the exclamation sign, meaning it was not working properly. It is this that was causing the problem and I tried to update the driver through Control Panel but Windows was unable to do it.

I also tried one of the recovery CDs that I got from Toshiba but that didn’t work as well. So I started looking on the web for a mass storage device for my Toshiba A100 027 laptop but couldn’t find it. It’s not even listed on the Toshiba website and they usually have quite a lot of drivers for you to download just in case you need them. Anyway, I was lucky enough to stumble upon a forum which had a link to a driver which would solve the problem. Here’s the direct link to the driver for the SD card reader:

http://www.station-drivers.com/telechargement/texas%20instrument/TIPCI_xx21_xx12_02_2.0.0.8.exe

I am always skeptic of downloading .exe file (executables) as they may contain viruses/trojans but the above link is safe and works well on my laptop. After installing it, I was able to get the SD memory card reader to work properly again.

Problem installing Visual Studio 2010 Ultimate on Windows 7 64 bit

I just upgraded my Vista computer to Windows 7 64 bit and when I tried to install Visual Studio 2010 Ultimate, it wouldn’t work. The setup process would just abort with a message telling me that the process could not be completed and show me a list of components which has not been installed.

At first I thought that it was a problem with Windows 7 64 bit but then again I have the same OS on my laptop and I didn’t have any problems installing it there. So I did a little bit of research on the net and found a couple of solutions. There are some things like checking your windows registry to see if there’s an entry in the 32 bit or 64 bit section of windows and since I just upgraded from 32 bit Vista to 64 bit Windows 7, I thought I might as well check it out but that was not the problem.

Some people who had the same problem said they were able to fix it by burning the iso file again. I gave that a try and when I placed the newly burned dvd into my dvd drive, it started the setup process but shortly afterwards aborted. My first iso image was burnt on a TDK DVD and the second one was on a Sony DVD. This shows that not all DVD ROMs are able to read all DVDs available on the market.

Anyway when that did not work, I plugged another DVD ROM in my computer and that did the trick. The whole problem was associated with the fact that the DVD ROM could not read the burnt iso of Visual Studio 2010 Ultimate edition and therefore setup had to quit without finishing the whole process.