Asp.net web page force document mode edge in IE? - asp.net

I have a webpage that is not working properly in IE unless I hit F12 and change the document mode to "Edge" under emulation. Is this something I can do programmatically on the page so the user does not have to do this? TIA

You could try adding the X-UA-Compatible META tag. This belongs in your <head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
Internet Explorer allows you to define which version's engine is used to render a page using the X-UA-Compatible META tag or HTTP header. A specific version can be designated or the latest version using the 'IE=edge' value.
You can also add custom HTTP headers in the ASP.NET web.config:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>

Related

HTML5 manifest no caching

Hello I got a question regarding no caching within my .net web application. I got an XHTML web application which is running with the following metatags:
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
I want to make this application a HTML5 valid application. After running it through the HTML5 validator it will output that those metatags are not valid.
I did some research on the internet and a lot of people suggest to use a manifest file like:
CACHE MANIFEST
# 2016-03-18 time 10:30 UTC v 1.01
NETWORK:
*
Where this basically says: for all files, do not read from cache but from network server. This sounds like the browser is not caching it at all. But a downside of this approach is that as been said in this post that you need to update the manifest file each time you do a (partial) postback. Which does not sound a very nice proper way to do that.
So I searched for an alternative method by using HTTP headers through my IIS via web.config adjustments. I found a source that says that you can use the following method:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
No I am wondering is this method a good approach in order to not cache my webapplication?
CACHE MANIFEST is for offline web apps and it's not an easy stuff to use at all, and as far as I know isn't even recommended way to make offline apps.
If you don't want your page to be cached in browser, then configuring response headers would be the right approach.
To prevent browser from caching a page completely, you can set following headers:
Cache-Control:no-store
Cache-Control:no-cache
Pragma:no-cache
Expires:Fri, 18 Mar 1999 12:22:21 GMT
Note that Pragma header is for HTTP 1.0, and Cache-Control:max-age is equivalent to Expires, but Cache-Control:max-age has higher priority, so there is no reason to have them both of them simultaneously
Use the manifest file as you described, and update it with javascript:
Your manifest:
CACHE MANIFEST
# 2016-03-18 time 10:30 UTC v 1.01
NETWORK:
*
Javascript:
var appCache = window.applicationCache;
appCache.update();
A good start to use appcache: A Beginner's Guide to Application Cache

external page and iframe issue

I have 2 websites hosted on windows server 2012. One website is using asp.net while other is wordpress. I want to embed asp.net page in wordpress. But, it is not showing anything. I did some research and came to know that perhaps, I have to allow permission for external website. Please guide me how to do it, should I add anything in web.config? I added below in asp.net but it did not help
<head>
<meta http-equiv="X-Frame-Options" content="allow">
</head>
Please guide, how to allow external website in iframe?
The iframe looks like below:
[iframe mydomain.com/signIn.aspx 640px 400px]
Thanks
You can do it in your web.config (if hosted on IIS 7.0 or later):
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Frame-Options" /> <!-- optional -->
<add name="X-Frame-Options" value="ALLOW" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
This must be added in the application being "framed" (in your case an asp.net app), not in the parent app (wordpress).
Reference: https://www.iis.net/configreference/system.webserver/httpprotocol

Internet Explorer compatibility mode

I have a ASP.NET web application which is supposed to work on IE.
If I go to compatibility View Settings and uncheck Display intranet sites in Compatibility View and the domain is not added in the box Websites you've added in Compatibility View, the users sees the code not the forms of the page.
If I check the checkbox, he still sees the code, only after I add it in the box I can see the actual forms of the page.
I tried
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=IE5" />
</customHeaders>
</httpProtocol>
</system.webServer>
but still the same problem.
Is there another way to force it from code? I understand in the future the checkbox will be disabled so I must find I way to force the compatibility mode.
Can I add it to the box for Compatiblity View from code?

IE9 throwing site to Quirks mode

I want to avoid that. I've tried:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
(from HTML5 doctype putting IE9 into quirks mode? )
And:
<meta http-equiv=”X-UA-Compatible” content=”IE=9″ />
(from Disable quirks mode for parent frame )
But neither helps. When I do F12 - Document mode IE9 standards - the page is shown fine.
Any solution?
If the page is local, or on an Intranet , Internet Explorer defaults to quirks mode.
If you put the same page on The Web, it would behave as expected.
To get it working as you want, as you are using ASP.NET, you can add this to your web.config file:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
This avoids having to override the user settings for all Intranet pages.
I was running the page locally and having this issue. I was using HTML5 and just starting my page with <html>.
When I added <!DOCTYPE html> it magically started working (even locally).
In context:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<add name="X-UA-Compatible" value="IE=edge" />
</head>
More info about IE8 and doctype.

Setting headers to override IE intranet compatibility mode in ASP.NET

I have an intranet site that loads in IE7 compatibility mode, unless the user has unchecked "Display intranet sites in Compatibility View" on their version of IE8. Unfortunately, the client wants this checked for other sites that they use, so I need to override this setting. I've tried the meta tag,
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
but it does not override the browser setting. However, this question indicates that a server heading will indeed override. This is the example code given in the top answer:
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
I've opened up web.config and put it in <system.webServer> but it doesn't work. I'm watching the headers with fiddler but it isn't adding the header at all. (Also, it still is forced to compatibility mode and Javascript confirms documentMode is 7.) I'm working locally with the ASP.NET Development Server
The <system.webServer> tag is specifically for IIS (7, I believe). It won't affect the Cassini server that Visual Studio uses in-house. If you only need to worry about this issue in a live dev environment, try testing on an instance of IIS. Otherwise, you may want to try IIS Express in development.

Resources