enabling caching of js/css files with nodejs/iis7 reverse proxy - caching

I have a nodejs backend, site served through iis7 via reverse proxy as per this website: https://alex.domenici.net/archive/deploying-a-node-js-application-on-windows-iis-using-a-reverse-proxy. In the node app i have a middleware layer to all get requests to cache content, like so
res.set('Cache-control', public, max-age=${period})
When running on my local machine i'm checking the headers via google developer tools and it does look like caching is working properly. When I move it to production, i can't seem get it to work. On IIS i've configured the HTTP Response Headers to expire after 10 days. My web.config looks like so (again per the link above)
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00"/>
</staticContent>
</system.webServer> </configuration>
Tried various things without success. The only possible lead i have at this point is from this thread
https://social.msdn.microsoft.com/Forums/vstudio/en-US/981bf691-ed6e-460a-9e99-af24fc8bfc0e/nodejsweb-apps-output-cache-not-working-for-node-web-app?forum=opensourcedevwithazure
but i have no idea how to make the suggested change in the web.config file. A couple of notes, im currently just running my node app in the command prompt like so: node app.js, not as node bin/www as suggested in the link (having some odd issues). Also, the site is still very much in development so on ssl. Read that chrome might have some issues with it, but the problem is present in all browser tested (chrome, firefox, etc...)

Related

"Leverage browser caching" not working in IIS or Page Speed reporting wrong

I have tried set this in web.config:
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
I also modified the value through the GUI but my Response Headers still says no-cache:
I read several posts and this one looked promising but still I can't get it to work.
From what I understand from this image the image bbb.png is taken from the cache but Page Speed (after refresh, and after waiting a couple of minutes) that it still is not being cashed:
Why isn't this working?
According to https://varvy.com/pagespeed/ I'm not caching 3rd party images:

web config errorMode

Hey guys I am kind of new to all of this so this might be a simple question but I want some clarification on this topic. I have a website and when an Http error occurs I send people to a customized page this works perfectly. The only issue is that it is also sending me to that customized page. I would like it so that I can see detailed errors on the production server (reason is that sometimes error pop up in production server and not in the development server) and send everyone else to the customized page this last part is done the first part I am having trouble with this is what I have in my web.config
<system.web>
<customErrors mode="RemoteOnly" />
<compilation debug="false" targetFramework="4.0" />
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="500" subStatusCode="-1" />
//this is working
<error statusCode="500" subStatusCode="-1" prefixLanguageFilePath="" path="~/myerrors" responseMode="file" />
</httpErrors>
and my last question is how would the production server know that your LocalHost?
I suspect that you're confusing terminology here, so I'll try and clarify.
A connection from "localhost", in this context, means that you are connecting to the website from the same computer that the site is running on. This can happen if you're developing it on your local machine, or if you've used remote desktop to connect directly to the server and are browsing the site from that session.
If you are on your own machine connecting to your production server, you are no longer "localhost" - you are Joe Bloggs out on the Internet, the same as every other user, and you will get the same error page.
I would suggest adding additional functionality to the customised error page to pick up who is accessing it (if you are authenticating users), or using an external component such as ELMAH to help you with your error logging.

Lightswitch, AJAX and Access-Control-Allow-Origin

I am preparing to demo Lightswitch to a group of about 100 software developers in a couple weeks and
have run into a snag.
I have a VS2012 solution with two projects:
Lightswitch - simple data model and ApplicationData.svc
Web - contains a web page that attempts to communicate with the ApplicationData.svc using JQuery Ajax
My problem is when I try to run the solution and execute the AJAX command, I get the following error:
XMLHttpRequest cannot load http://localhost:37650/ApplicationData.svc/MyEntities. Origin
http://localhost:53408 is not allowed by Access-Control-Allow-Origin.
After googling around for a while, I found this advice, which looked promising:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
But it did not resolve the issue. Any ideas?
Thanks!
You may need to add:
headers: { "If-Match": " *" }
see:
A Full CRUD DataJs and KnockoutJs LightSwitch Example Using Only An .Html Page
http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/128/A-Full-CRUD-DataJs-and-KnockoutJs-LightSwitch-Example-Using-Only-An-Html-Page.aspx
I solved the same problem with this:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Max-Age" value="3600" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept, MaxDataServiceVersion" />
<add name="Access-Control-Allow-Methods" value="PUT, POST, GET, DELETE, MERGE, OPTIONS" />
</customHeaders>
</httpProtocol>
I've been running into the same issue, only mine is that I am creating a HTML5 JQuery Mobile application that is NOT a web application. The app is JQuery based app that I am going to run through PhoneGap. My issue is that when I make the calls from the mobile app, I get the same cross domain issues.
What browser are you using to test? I am doing Chrome and I get the issue because of the initial Options request (see http://www.w3.org/TR/cors/ ). I've tried a bunch of possible solutions, like updating config files and so on, but to no avail.
My next kick at the cat will be to intercept the initial Options request by creating an IHttpHandler that I can apply as an attribute to the WCF service I am using (did I mention that I created custom WCF services within the Server project in the LightSwitch solution?).
I'll keep you posted...
Paul

How to set cache expiry date

Trying to cache a large js file on the client browser. When I check firefox's cache information, it shows the js to expire on 12/31/1969. I'm using IIS6 and have tried adding the following code to the web.config:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
Still the same. How can I get the browser to cache this file?
In IIS, right click on your Site node and click Properties. Go to the HTTP Headers tab, tick Enable content expiration and set an expiry time.
You may have to configure that in IIS, I'm not sure that IIS6 honors that web.config setting like IIS7 does.

server error:405 - HTTP verb used to access this page is not allowed

I have a php Facebook application which I have uploaded in a Microsoft server. When I run the application i get this error. Does anybody know the cause of this ?
405 - HTTP verb used to access this page is not allowed. The page you
are looking for cannot be displayed because an invalid method (HTTP
verb) was used to attempt access.
Even if you are using IIS or apache, in my guess you are using static html page as a landing page, and by default the web server doesn't allow POST or GET verb on .html page, facebook calls your page via POST/GET verb
the solution would be to rename the page into .php or .aspx
and you should be good to go :)
In the Facebook app control panel make sure you have a forward slash on the end of any specified URL if you are only specifying a folder name
i.e.
Page Tab URL: http://mypagetabserver.com/custom_tab/
you can add these lines to the web.config:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
It means litraly that, your trying to use the wrong http verb when accessing some http content. A lot of content on webservices you need to use a POST to consume. I suspect your trying to access the facebook API using the wrong http verb.
I fixed mine by adding these lines on my IIS webconfig.
<httpErrors>
<remove statusCode="405" subStatusCode="-1" />
<error statusCode="405" prefixLanguageFilePath="" path="/my-page.htm" responseMode="ExecuteURL" />
</httpErrors>
I've been pulling my hair out over this one for a couple of hours also. fakeartist appears correct though - I changed the file extension from .htm to .php and I can now see my page in Facebook! It also works if you change the extension to .aspx - perhaps it just needs to be a server side extension (I've not tried with .jsp).
Try renaming the default file. In my case, a recent move to IIS7.5 gave the 405 error. I changed index.aspx to default.aspx and it worked immediately for me.
In my case, IIS was fine but.. uh.. all the files in the folder except web.config had been deleted (a manual deployment half-done on a test site).
I got this error when I was using jquery and lib was not present in the given path, once jquery lib is added back error was gone.
[File name - calculate.html]
I had this err on the host too (my project was .net core2.1 webapi )
please add this code in web config in host :
<modules>
<remove name="WebDAVModule" />
</modules>

Resources