Pages

Thursday, February 27, 2014

Get MIME Type by file extension

I was searching for a way to get the MIME type of a file by file extension and .NET Framework 4.5 comes to the rescue.

You can make use of API GetMimeMapping which is found in the .NET Framework 4.5 System.Web.dll

Here is the documentation of it - http://msdn.microsoft.com/en-us/library/system.web.mimemapping.getmimemapping.aspx

Example on how you can use it

string mimeType = System.Web.MimeMapping.GetMimeMapping(fileName);

If you are running your ASP.NET web application in the integrated mode in IIS then this API actually uses the list of MIME types in the IIS and so seems to me that even if your IIS MIME types list gets upgraded, you dont need to update your code, huh..cool .. isn't it?

Hope you find this useful.

Reference - http://blogs.msdn.com/b/webdev/archive/2013/02/14/getting-a-mime-type-from-a-file-extension-in-asp-net-4-5.aspx

Monday, February 24, 2014

Windows Azure cannot perform a VIP swap between deployments that have a different number of endpoints - Error solved

I have been taking a look at Windows Azure VIP swap feature and started facing this issue.

What this issue is all about and what is VIP Swap?

I had deployed an application on the production slot of a cloud service and the test application was deployed on the staging slot of same cloud service.
When you have both deployments of a cloud service up and running, you can perform a VIP swap which is nothing but the swap between your virtual ip addresses of production and staging deployments and doing so your production deployment becomes the staging and staging deployment becomes the production deployment.

But then after trying to perform VIP swap I started facing an error which says
Windows Azure cannot perform a VIP swap between deployments that have a different number of endpoints.
Though error was too obvious and pointing to the exact issue still as a typical developer I preferred to do a quick search on web and it seemed like its a very common issue which is faced by many people and so documenting the possible solutions.

All right, what is the solution?

Solution is quite easy as error is descriptive enough - check the number of endpoints of your cloud service deployments.

  • Check the cscfg files of both deployments i.e. production and staging. The number of input endpoints on both deployments should match.
  • Check endpoint ports of both slot's deployments e.g. Https / Http. (443/80)
  • Check if one of your deployment has remote desktop enabled on any of it's role instances because it ultimately ends up opening another port internally on your cloud service. If remote desktop is enabled then it needs to be enabled on both deployment slot's instances.

Takeaways:

Ideally your both deployments should match exactly because whenever you will want to put something on the production slot by swapping it with staging then you must have to make sure that it works correctly and this is why the staging slot is used for internal testing purpose, however there might some scenarios where you might want to have different deployments on both slots e..g Site under maintenance on production slot while you upgrade your deployment on staging and test it. So make sure to have a close look on the endpoints of your both deployments and now you know how.