Internet Explorer 7 + MVC 3 = Bad URLs?

This is strange. I say strangely, in IE 8 and up (and also in FF), my urls generated by Html.ActionLink () create a url in the correct form -> http://mydomain.com/myapp/mycontroller/myaction . but for IE 7 and IE8 running in quirks mode the urls are generated as -> http: /// myapp / mycontroller / myaction . This also affects anything that Url.Content () uses.

This is troubling because I have users still holding onto IE 7 for dear life (I don't get it either). Also, our Active Directory policy has things set for some (not all) users, so IE 8 is forced into compatibility mode and cannot be disabled. It also overrides the compatibility meta tag.

What should I check here in MVC? Is there a web.config parameter I need to look at?

Code: Action links:

@Html.ActionLink("My Text", "Action", "Controller", new { Param1 = Model.Param1 }, new { @class = "linkButton" })

Url.Content:
Url.Content("~/Content/openHS.png")

      

Update: I found a similar article referring to this issue in PHP: Why can't I use relative URLs with IE7?

Several other articles on the net have been referenced with the title tag <base>

. Try it now. used a search for "relative urls" "Internet explorer 7"

+3


source to share


1 answer


It works. I tested in WinXP mode with IE 8 in compatibility mode and also in IE 7 IE IE, IE 9, IE9, FF 11. No harm to my existing JavaScript

For a shaver:

@{
     string baseHref;

     if(this.Request.Browser.Type == "IE7" && !this.Request.UserAgent.Contains("Trident/5.0"))
     {
          baseHref = this.Request.Url.Scheme + "://" + this.Request.Url.Authority + Url.Content("~");
     }
     else 
     {
          baseHref = Url.Content("~");
     }
}

      



Then at the top <head>

:

<meta http-equiv="X-UA-Compatible" content="IE=9;IE=8;" />
<meta charset="utf-8" />
<base href="@(baseHref)"/>

      

One explanation above: Trident / 5.0 is an IE9 compatibility mechanism and seems to allow IE9 to interpret relative links according to the page domain instead of the base. I'm sure you can remove the Razor code if you so desire. This was the compatibility patch for me.

+1


source







All Articles