HTML5 manifest no caching - asp.net

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

Related

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

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>

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

WebResource.axd return Empty response

Only on my development machine, when I point to a WebResource.axd file, I get an empty response.
Sample url: xxx.yyy.com/WebResource.axd?d=[Encrypted quesrystring]&t=[timestamp]
It does not happen on Integration server or QA servers. It also works on one of my colleague's machine, but not on another one's machine.
The webresoruce response, when it works returns CSS & JavaScript etc. It returns CSS & JavaScript for Ajax Control Toolkit.
Does anybody know why it would happen?
I have checked the web.config in the Framework folder and the mapping exists under
<httpHandlers>
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
I had this bug because my app applies Deflate compression on all text-resources.
After removing compression of all handlers, the problem is solved.

PUT and DELETE returns 404 for asp.net webapi in Windows 2008 Server IIS 7 and 7.5

I run into 500 - Internal Server Error when PUT/DELETE with windows 2008 server IIS. The response I get is:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>500 - Internal server error.</title>
<style type="text/css">
<!--
Formatting
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>500 - Internal server error.</h2>
<h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
</fieldset></div>
</div>
</body>
</html>
When I check my custom logs of my WebAPI I find that the call has not even hit the service.
My earlier experience was getting 404 - Not Found for PUT and DELETE and this behavior was consistent across Win7 and Win 2008 Server. For that I found this fix:
I applied the fix and PUT/DELETE works on windows 7. But after that when deployed the same service on IIS 7 in win2008 server I do not get 400. But I get "500 - Internal Server Error" from IIS or something even before that.
The same code works perfectly on windows 7 (IIS 7.5).
Any clues on resolution of such issues?
Edited Aug 29, 2012:
The issue of 500-Internal Server Error is detected by enabling fault-tracing in IIS7. The fix is this configuration.
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
Basically we need to remove "WebDAVModule" from modules and also remove "WebDAV" from Handlers. But now I am back to my old issue of 404-Not Found. Now even after having the below configuration i cannot get PUT/DELETE to work:
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
Unusually the same web application works perfectly on hosted separately (not under default web site) on the same system same IIS. So I suspect this is due to some parent website configuration which filters PUT/DELETE requests.
Any ideas on the same?
After agonizing over a very similar problem, I came upon this solution:
http://www.iis.net/configreference/system.webserver/security/requestfiltering/verbs
Using the Request Filtering settings, I was able to globally allow the PUT and DELETE verbs in IIS, which solved my problem. It ended my nightmare of 404.6 errors. (btw, I did not have webDAV installed and did add the verbs to the ExtensionlessUrlHandler)
Hopefully this info can save someone some time.
I make the Neil S` information more exact:
Delete WebDAV from "Modules"
Delete WebDAV from "Handler Mappings"
I delete WebDAV from IIS components to make sure WebDAV not exists and restart Windows
Go to "Handler Mappings" and find ExtensionlessUrlHandler (for 32 and 64 and Integrated), open it and go to "Request Restrictions" to second chapter "Verbs" and put some of the methods you need to the string. I have the next:
GET,HEAD,POST,DEBUG,PUT
I repeat the changes for three "ExtensionlessUrlHandler" states.
I do not change Request Filtering settings
So, 404 and 405 error for Put method was disappeared, I receive 200 status.
This solution works for me.
I had the same issue recently on my Win Server 2008 R2 / IIS 7.5 and it took me couple of hours just to found out it was caused by LiveStreamingHandler. LiveStreamingHandler module on the IIS causes the PUT and DELETE HTTP verb error.
Uninstall the Media Services 4.1 with Add and Remove program and reboot the server fixes this issue. Hope this help someone.
Try turning on custom error by adding
<customErrors mode="Off" />
You will see the actual cause of the 500 error when you browse to the API controller, e.g.: http://staging.site.com/api/book.
You will find more clues from the actual exception messages.

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