Monday, December 10, 2012

Setting a "Content-Disposition" HTTP Header in Web API Controller Method

When developing an ASP.NET Web API controller method that allows to download a file it is considered a good practice to set a "Content-Disposition" header to guide a browser of a name of a file being downloaded.

There are two different ways to approach this simple task. First is to add a new HTTP header to the HTTP response using string values for the header's name and value. The second is to try and use the .NET framework's infrastructure methods that presumably should make this task easier.

The first method seems to be very simple but potentially dangerous: one would need to hard-code string values and be totally responsible for the values to be properly formatted according to the W3C standards.

The second method is to try and delegate handling of the specifics of the HTTP protocol to the .NET framework by using corresponding presumably built-in methods. This seems more appropriate and even easier to achieve. However due to poor documentation of the Web API extensions that is easier said than done. without further ado this is how it's done:

Only one string value here should hard-coded with a guideline available in the official documentation so it's not that bad.

If you find this information possible share it with your fellow colleagues so it may save their valuable time.

Tuesday, February 21, 2012

Fixing 'Bootmgr is missing' problem on Windows 7

The reason for this post is that it took me three hours on the weekend to fix this problem and based on the amount of search results the Google returns for that keywords I figured there are a lot of people facing such a problem. So my goal is to provide with a simple explanation and easy fix to save one's time and may be even prevent this problem from happening.

Let's start first from understanding what exactly is the problem. Secondly we see how to fix it and lastly we discuss the scenarios that could cause such a problem.

The problem

When one tries to boot up a computer with Windows 7 OS on it and instead sees a black screen with a message "Bootmgr is missing - Press CTRL+ALT+DEL to restart". (I guess it's obvious that restarting will not fix the problem)

There is an important condition for the fix described in this article: the computer was booting before but after some changes this error occurred. If this is not the case than the solution might not be applicable but from another hand it would not hurt to read further.

So what exactly is the problem? The answer is easy: it's right in the message. Windows is looking for a file with a name "bootmgr" and cannot find it. This is a hidden file of a size about 320Kb that should reside in the root of a boot partition on a hard drive where the Windows OS is installed. We will discuss the reasons why it's missing later but now since we know what the problem is how can it be fixed?

The fix

Copy the bootmgr file from the source to the root of the boot Windows partition on hard drive. An XCOPY command can be used with an /h switch that allows copying hidden and system files. For example:
X:/>xcopy bootmgr C:\ /h

Where to find the bootmgr file?

This is an important question. The answer depends on a particular computer's configuration but based on the problem statistics let's just mention the most probable locations to search for the file (don't forget it's hidden):
  • Root of another hard drive with Windows 7 on it
  • Root of another partition on the same hard drive with Windows 7 on it
  • Windows 7 installation DVD
Once you figure the location of the bootmgr file simply copy it over to a boot partition and restart the computer: it should be able to boot in windows successfully this time and you are done.

The possible causes of the problem

In my case and based on the Internet search results that seems to be a very popular cause I have installed a second hard drive in the computer and then installed Windows 7 on a new hard drive. The key here is that Windows installer did not copy the bootmgr file on a new hard drive because it already existed on an old hard drive. The same problem would have happened if Windows was installed on a new partition on the same hard drive where another Windows installation present. These two reasons cover over 80% of the problem occurrences with some variations around different versions of Windows that existed at the moment of a new Windows installation and dual-boot related problem with the same outcome.

Another set of reasons relate to hardware problems with hard drives and not covered in this post for an obvious reason that the only solution for that is to replace a hard drive and reinstall Windows.


Apparently the only proper way of installing Windows is first to hide a hard drive or a partition with another Windows installation and once a new Windows is installed make it visible again. Unfortunately to the best of my knowledge that is not mentioned in the installation instruction.

Advanced technical details

For those who would like to dig a bit deeper I suggest to boot into a Windows Recovery environment (F8 for Windows boot advanced options), open a command line prompt and use a bcdedit utility to explore the BCD (boot configuration database) content to see where Windows looks for the bootmgr file.


Once the cause of the problem is understood the fix is easy however the search for the cause has been significantly slowed down by an amount of misinformation that Google search returned.