blog.mha.dk
The on-line blog of Michael Holm Andersen

301 Redirects on IIS7 – come again Microsoft!!

Friday, 10 September 2010 14:15 by mha

Creating a 301 Redirect in IIS7 is EVEN MORE CRAPPY than on IIS6 – I was going “nuts” trying to find out why my 301 Redirect didn’t work.

What I wanted to do (a pretty common scenario) was to redirect traffic from my URL without www to the www.somethinggoeshere.dk version of my domain name – however this (one should think!) simple task is not easily done!! Here’s how to do it:

You have to create a new website (one could wonder why it’s not possible simply to add e.g. 301 Permanent headers to a host name and in this way quickly be able to add a list of URLs which would be 301 redirected) – when creating the website you HAVE to enter a Physical Path when creating the site. The wizard forces you to pick a path even if you plan to redirect the site to a URL.

The most obvious would be to pick the root folder of the site you plan on redirecting to, however this (why, Microsoft?) caused an error for both sites due to a continuous redirection. You have to create an empty directory for the site you want to redirect, which makes no sense at all (why does the directory matter when all I want to do is make a 301 permanent redirect).

This ought to be MUCH SIMPLER if you ask me!

IE8, cookies and local addresses that are not localhost

Thursday, 19 November 2009 11:20 by mha

Recently installed Windows 7 which is really nice. IE8 is the default OS browser and typical the one I use as my “default development browser”, which means it is not my default browser (Firefox is), but it’s the browser that Visual Studio opens when I do a “View page in browser”.

I have multiple sites which use ASP.NET Membership (and hence use session cookies to keep me logged in). I typical change my ‘hosts’ file to something like this below, and of course set the ‘binding’ (host header) in IIS7 to match:

127.0.0.1    site1
127.0.0.1    site2
127.0.0.1    site3

(names have been changed to protect the clients :-)

However when I fired up VS2008 and tried to log into one of my sites which uses membership, I simply could not log in. After having done some HTTP Cookie debugging I realized that IE8 did not store my cookie. A fact that was proven correct as the same site worked fine i both Firefox and Chrome.

Surfing the net I found a that this is a “security feature” of IE8 – the thing is that if you have e.g.

Site: http://mha
Cookie domain: mha

should work, but if you do

Site: http://mha
Cookie domain: 127.0.0.1

..then it won't work, because IE sees that as security risk as 127.0.0.1 does
not match the requested hostname.

Microsoft recommend that you should always name internal servers with
hostnames that are FQDNs, such as mha.local - This also helps to mitigate
problems such as DNS failures and use of suffix handling - eg. if the DNS
automatic suffix for a machine on your network is .com, and you name a
server mha, a request to http://mha could end up requesting http://mha.com
because of the automatic suffix handling.

So to get this to work you need to stop using single words for internal site
URLs and start using e.g. localhost.mha

So .. in order to make IE8 accept cookies from internal sites running on localhost / IIS7, and is mapped in your ‘hosts’ file we need to do a couple of thing:

1) Make sure you’re using a full qualified hostname, e.g. localhost.aspnethotelV25

2) In IIS7 make sure you’ve set up your hostname correctly in binding:

iis7binding

3)  In your ‘hosts’ file, make a matching entry:

# --- IIS7 / localhost ---
127.0.0.1    localhost.aspnethotelV25

4)  In IE8 make sure to add your site to always allow cookies:

  • Go to Tools –> Internet Options
  • Click ‘Privacy’
  • Click ‘Sites’
  • In Address of website, enter your host header name
  • Click ‘Allow’

ie8cookie1

ie8cookie2

That’s it!! – Finally your site, running on your own localhost / IIS7 which is using a different name that localhost or 127.0.0.1 is now able to accept cookie (because we all know that cookies server up from localhost is a big security risk!?! :-)

Enjoy the wonders of Internet Explorer v8 (or simply use Firefox, Chrome or any other browser which just work out-of-the-box)

Are we hosted or not ?

Friday, 15 May 2009 10:35 by mha

In my classes (eg. in my Class Library) I sometimes need to find out if the code that is currently executing runs in a Hosted Environment (like an ASP.NET application) or not.

To find out we can use the System.Web.Hosting.HostingEnvironment.IsHosted property, which tells us whether the current application domain is being hosted by an ApplicationManager object (which manages ASP.NET application domains for an ASP.NET hosting application).

You can read more about the ApplicationManager Class on MSDN

V3 in the making...

Monday, 29 September 2008 20:51 by mha

Today I've started the development of "version 3.0" of the aspnethotel.dk website.

The site will (at last) be complety re-written, using a 3-tier approach. All access to data will be done using LINQ (currently only the front-end is using LINQ), the site will be multilingual, support international creditcards, improved (faster) AJAX, build using SEO Best Practices, and lot's of other cool stuff .. most important (at least to me!), the site will include all the functionality in the back-end which have been on my TODO list for quite a while.

If all goes well the new version will be completed before Xmas :-)

In the mean time, why don't you check out Kims new and MUCH improved ColorExplorer website .. really nice work, dude!

Increase your website performance!

Thursday, 10 July 2008 18:50 by mha

We all like our website to be as fast as possible (that's one of the reasons why we love .NET, right! :-)

A couple of minutes spend optimizing your IIS settings can also have a huge impact on the load time of your pages. Your website probably uses quite a few (semi) static files, like images, css and javascript - As these files does not change very often, there is really no need for your users to download these files every time they visit your site.

To cache these files, simply tell IIS to add cache headers. It's really simple to do:

1) Open IIS and locate your site.
2) Right click e.g. the "images" folder.
3) Select properties and choose the "HTTP Headers" tab. Check the "Enable content expiration" and set "Expire after 5 days".

The browser now compares the current date to the expiration date to determine whether to display a cached file, or to request an updated file from the server.

Umbraco v4 in beta

Wednesday, 9 July 2008 08:47 by mha

Umbraco v4.0 beta1 is available for download - looks like it's going to be a great release :)

Check it out / download the bits from: http://www.umbraco.org/v4

.. and by the way - aspnethotel.dk is of course capable of hosting both v3 and v4 umbraco sites! ('hidden' ad, beware! :-)

Categories:   .NET hosting | ASP.NET | C# | Tools
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Finally - ASP.NET AJAX v1.0 released

Wednesday, 24 January 2007 17:53 by mha

At last ASP.NET AJAX v1.0, formerly known as ATLAS, is shipping. This new Web development technology from Microsoft integrates cross-browser client script libraries with the ASP.NET 2.0 development framework - making it easier to develop Web Applications with a rich GUI, and improved user experience.

Complementing ASP.NET AJAX, the ASP.NET AJAX Control Toolkit offers developers a rich variety of client-side controls and extenders through a compilation of code samples and components.

I've been using ATLAS since the early CTP's, and are looking forward to integrate this technology into future Web Applications.

Update: www.aspnethotel.dk now supports ASP.NET AJAX on all web-servers - check out ajax.thinktwice.dk to see it in action!

Categories:   ASP.NET | AJAX | .NET hosting
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Database Publishing Wizard

Friday, 19 January 2007 04:44 by mha

Deploying all the .aspx, CSS and image files of a website to the hosting environment is not that big a deal, however making sure that the whole database including data is created correctly is sometimes more difficult.

At CodePlex they've launched a new project called "Database Publishing Wizard" which aid in deploying a SQL Server 2005 database (both schema and data) to a shared hosting environment on either a SQL Server 2000 or 2005 server. Also Scott Gu has written a detailed post about this nice tool, be sure to check it out.

Special discount!!

Wednesday, 14 December 2005 19:35 by mha

aspnetheader.gif

Students from Aalborg technical college (Aats) attending the Web-Integrator or Digital Media education will be able to buy a ASP.NET v2.0 webhotel including support for SQL Server 2005, Membership, Roles etc. at a special low price of 49,- incl. VAT. per month.

Check out the www.aspnethotel.dk website...

Update: This offer has expired!