Usability, MVC, ASP.NET

24. Januar 2012 11:08
by Henrik Stenbæk
1 Kommentare

ASP.NET 4.0 acting strange when User-Agent equals Safari 5.1

24. Januar 2012 11:08 by Henrik Stenbæk | 1 Kommentare

During the last couple of days I have spend my working hours trying to resolve a strange problem on one of our production sites. I used a lot of time trying to figure out what coursed the problems and searched the web without any result. As part of the troubleshooting I also prepared a question for stackoverflow.com. It turned out when I started to post the question that stackoverflow was able to suggest a question with similar content and that this other question contained the answer – it has been the all the time but I wasn’t able to find it because I have googled the wrong keywords. In the hope that this could help other people that is googling with the wrong keywords I herby post the text that original prepared for stackoverflow (including a link to the correct answer).

“We have a website running on ASP.NET 4.0 Webforms (IIS 7). The site has been online for years (since 2008) running under ASP.NET 2.0. Recently (like October 2011) we lifted it to 4.0, and after that we have started to get complaints from Safari 5.x users that they can’t sign in to the site, but keep on getting redirected to the login page.

The site is running in a farm with four servers. When the problem occurs it’s not on all 4 servers at once. When a node starts redirecting the user, the situation will persist for an unknown amount of time and then the node will return to normal – we haven’t yet discovered how long this amount of time is, it could be equal to app pool recycling. After all we have experienced that recycling the app pole seems to solve the problem.

We have experienced that when we hit one of the servers that is “infected” with the problem, we don’t really need to use a native Safari 5.x browser. All browsers that is showing the Safari User-Agent is redirected. The problem exists when User-Agent is:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50

If we spoof a Chrome or Firefox to display this User-Agent the problem will occur. 

If the same browsers are showing their native User-Agent they have no problem in signing in and browsing the site. As if we spoof a Chrome or Firefox to display an older Safari User-Agent: 

Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; nl-nl) AppleWebKit/533.16 (KHTML, like Gecko) Version/4.1 Safari/533.16

they have no problem browsing the site.

The fact that any browser that impersonates as Safari 5.1 does experience the problem, have lead us to the conclusion that it is a 100% server related problem.

For some reason the server will decide that a Safari 5.1 browser is not suitable to browse the site as a logged in user and issue a 302 redirect to the login page.

This led us to look at the safari.browser file. When digging into this file it seems that there is no entry taking care of Safari browsers after version 4. We haven’t been able to verify this. But we can see that browsing the site with any of the above “User-Agents” results in different results when looking at System.Web.HttpBrowserCapabilities

The Safari 4.1 header returns

  • Platform = MacPPC
  • JavaScript Version = 1.7

The Safari 5.1 header returns

  • Platform = Unknown
  • JavaScript Version = 1.6

But if the problem is related to a missing entry in safari.browser why isn’t the problem persistent?

Could it be that if ASP.NET couldn’t recognize the browser it won’t bother checking the credentials cookie?

Does anybody have had any experience like this and have you solved it?”

Some of the words I used wend googling includes:

  • "safari.browser" asp.net
  • safari.browser file asp net
  • Request.Browser.Adapters renders
  • ASP.NET 4.0 keep on getting redirected to the login page

I searched stackoverflow for 

  • asp.net safari iis
  • CONFIG Browsers

The correct search is something like

  • applewebkit .net 4 user-agents

because it will lead one to the correct answer:

http://stackoverflow.com/questions/5478181/net-4-0-website-cannot-identify-some-applewebkit-based-browsers

It seems that I have found the root cause of the problem. The UserAgent -> BrowserCaps resolving mechanism uses a cache to temporarily store mappings. Unfortunately it uses (by default) the first 64 characters of the UserAgent string as cache key and THAT is just BS... Occasionally a user agent pops up that looks like a Safari, but really isn't and that one is not resolved properly (Mozilla 0.0), but the mapping is still stored in the cache, which means that all UserAgent strings with the same 64 character prefix are now incorrectly mapped as well until that cache entry expires (sliding window with 1 minute). The key length used for caching can fortunately be configured with

<browserCaps userAgentCacheKeyLength="..." />

in the config section. I've upped the key length to 256 and since that the problem has disappeared..”

25. Juni 2011 12:15
by Henrik Stenbæk
0 Kommentare

Fun with Google's new Search by Image

25. Juni 2011 12:15 by Henrik Stenbæk | 0 Kommentare

Google has created this new feature where you can search by upload a picture instead of writing a text.
 
To test the functionality I uploaded a picture with with myself and Mark Schulman (P! nk's drummer). Mark has sunglasses on, Google found a number of other pictures with two people on of which one is wearing sunglasses. My favorite: the image of the man and a panda (with sunglasses) LOL
 
 

31. März 2011 01:06
by Henrik Stenbæk
0 Kommentare

Dynamic robots.txt with ASP.NET MVC

31. März 2011 01:06 by Henrik Stenbæk | 0 Kommentare

If you have one application on your IIS and several domain names pointing to it, it’s possible to have different robots.txt files served based on the current domain name.

1. Add a route

CropperCapture[1]

2. Create the RobotsController

CropperCapture[2]

3. The SeoHelper just implements a simple way of determine what robots.txt file to return

CropperCapture[3]

4. Add the different versions of the robot.txt to the site root – remark the content for the robots.txt could be served from any source, I have just chosen a simple model to keep it simple

CropperCapture[4]

5. Run the site and request robots.txt

CropperCapture[5]

CropperCapture[6]

Get the source code: DynamicRobotsTxt.rar (21,66 kb)

1. Dezember 2010 00:35
by Henrik Stenbæk
0 Kommentare

Language select best practice

1. Dezember 2010 00:35 by Henrik Stenbæk | 0 Kommentare

Inspired by a discussion I had with a colleague recently (not really recently, more like 6 months ago) about the use of flags to choose language, I have reconciliation to assemble this list of best practice where users could select the language and culture on a website.

 

Ask users to select a culture

From a developer's standpoint, it is not enough that the user to select a language. To format dates, calendar, numbers and the like properly it is necessary to know language and country ("a culture").

 

en-US

en-GB

     
A large number with two decimals

123,321.99

123.321,99

First day of week

Sunday

Monday

Short date format

6/15/2009

15/06/2009

Within the same language exist culture-specific variations. A good (and now classic) example of this is from amazon where the text on the Add to Cart button varies between the  amazon.co.uk and amazon.com site:

image001 image002

 

Countries are not languages

The classic example of a bad “Choose of language” is the cases where a site prompts the user to choose a language from a list that only contains countries.

easportsactive

http://easportsactive.com/home.action has (until recently) this near to this wonderful misunderstood language selection. Entitled "Please Select your Language" invites the user to choose his language and then present a list of nine countries; several of them have more than one official language:

  • Canada has two primary languages: English and French (67.5% speak English only, 13.3% speak French only, and 17.7% speak both)
  • Belgium has two predominant languages: an estimated 59% of the Belgian population speaks Dutch (often colloquially referred to as "Flemish"), and French is spoken by 40% of the population.

 

Don’t display flags only

For many years, the experts recommended that you do not use flags for language selection. This recommendation has also found its way to W3C Working Draft “Authoring Techniques for XHTML & HTML Internationalization: Specifying the language of content 1.0”, Technique 16: Don’t use flags to indicate languages:

Flags represent countries, not languages. There are many countries that use the same language, and numerous countries that have more than one official language.

 

Yet there is a tendency that many sites still chooses to use the flag, this is linked to it may be difficult to scan a long list of countries and that a flag is a familiar and easily recognizable symbol.

When the flag is not used as the only symbol, but is followed by the country name and proper title (“select country”) it may work fine. For countries with multiple languages, these will appear after the country name as on www.tradedoubler.com where this technique work fine (note the two variants of Belgium and Switzerland).

tradedoubler

 

Treat the flag with respect

If you choose to use flags on a website it should be done with due respect to both form and color. Changing the flag can offend people's national sentiment but also actually be prohibited by law. In several western countries it is forbidden by law to scold other nations' flags. In Denmark, the only legal way to dispose of a national flag (Dannebrog) is by burning it while it is banned in Denmark to burn flags of other nations.

Apple.com has a complete overview of how not to treat all the world's flags. Under the heading "Choose your country or region" is a complete list of all the world's mistreated flags.

Apple

Who may, for example recognize the Japanese flag:

Apple_2

I dare not think of what a Muslim like the way the text (the Islamic declaration of faith) in the Saudi Arabia flag is pruned

Apple_1

For some reason it seems to Luxemburg and the Netherlands have the same flag, despite that the two flags are different on both the red and blue color (I think Luxembourg is the correct one).

Apple_3

 

Write the country and/or language name in its native tongue

delta_wrong_2 If a person who speaks only German enters the French version of the Delta Airlines website, it can be difficult to know that Germany is called Allemagne in French – Deutschland would be more correct

 

Language only

If the website does not have culture-specific formatting needs so it may be sufficient to let people choose a language and nothing else. Flickr has a list of languages written in native tongues:

flickr.

 

Language (followred by culture)

Facebook has chosen a solution where they listing language first followed by culture, if present: Français (Canada) and Français (France).

In the same way it’s possible to show both versions of Norwegian and it also opens the possibility to invent new cultures, notice “English (Pirate)” and “English (Upside Down)”, which is only possible due to this construction.

facebook2

 

Multistep culture select

Few websites offer users to select their culture through a multistage process. Pixmania.com is one of them, not graphically pretty :-) And it also assumes that the user knows his country's location on a map

pixmania1

(By the way – what has happened to Cyprus, it disappeared completely behind the "flag")

Clicking on the Switzerland flag on the map, shows a popup asking the user to select one of the 3 languages used in Switzerland

pixmania2

On the site the currency is default to CHF and the site still offers me to switch to one of the 2 other languages relevant for Switzerland.

pixmania3

The selected country and language is then shown in the address:

  • pixmania.com/ch/de/home.html
  • pixmania.com/ch/fr/home.html
  • pixmania.com/ch/it/home.html

 

Automatic culture selection

if the website uses Automatic culture selection: be polite and tell it to the user and give the opportunity to change back. Youtube automatically sets the user's language at the first visit ,from your browser's preferred language and shows a brief message about the choices made.

youtube

 

 

 

 

Suggestions instead of automatic selection

AlaTest suggests user to visit another domain (culture) version when the browser settings for preferred culture is not matched with the website culture.

alatest

No language

Finally consider if you need to have language selection at all.

Some sites don’t offer the user to select any language, if they have sites in different countries it’s possible to select the country and then gives the default and only language available for that country.

Amazon

amazon.com is an example of a side who don’t have language versions of their national sites. On the US site users is able to select Canada and are then getting the Canadian site in English.