IIS 8.5 cache issue on rewrite if file not exists - iis

I need to achieve in IIS the following:
check for changed .txt files in dir with url http://server/dir/test.txt without cache
rewrite url to empty.txt if file does not exist
My configuration:
<rewrite>
<rules>
<rule name="test-txt" patternSyntax="Wildcard" stopProcessing="true">
<match url="*.txt" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="empty.txt" />
</rule>
</rules>
</rewrite>
<caching>
<profiles>
<add extension=".txt" policy="DisableCache" kernelCachePolicy="DisableCache" />
</profiles>
</caching>
If file is changed, I get code 200 and actual content. Works as expected.
If file not changed - 304. Works as expected.
If file is deleted, after first check I get error 404.0. Why?
After second request I get code 200 and content of empty.txt. Works as expected.
If I create file at that moment, it works as expected. But if make requests in short time intervals (every 3-4 seconds), it doesn't matter any more if file test.txt exists or not, I get code 304 or content of empty.txt if I change it. But if I stop requesting file for some minutes, it works again as expected.
It looks like IIS has some sort of cache for static file checking. How to make it work as expected with static files only? (and without getting error 404 if possible)

It is not output caching, its just about browser cache.
So if you want to prevent cache for specific folder, please place this in the root web.config of your website/application. In this case, you have to disable location path for both example.txt and dir directory
<location path="dir">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
<location path="empty.txt">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
If you want to disable browser cache for all site, please just set
<clientCache cacheControlMode="DisableCache" />
without location attribute.
Your rule works fine on my side, so you just have to disable client side cache for the required folder/file.

Related

Block web access to a single subfolder using IIS?

I want to block access from the web to the logs subfolder on a website. The following web.config seems to work...
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="logs" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
...but it will also block access to any logs folder in all subfolders (foo/logs, foo/bar/logs, etc.).
How can I block only the logs folder that is in the same folder as the web.config file?
I know I can put a web.config file directly in the logs directory, but that is not an option here because it will most likely get wiped by accident when someone wipes the log files.
You could iis url rewrite rule to block the request for a particular folder.
below is the rule:
<rule name="RequestBlockingRule16" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{URL}" pattern="^/s2/(.*)" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
</rule>
folder structure:
s1 is the site root folder.

(413) Request Entity Too Large in IIS 10 URL Rewrite

I have an IIS 10 server configured as a basic URL Rewrite reverse proxy to preauthenticate requests directed at another web server, the calls are all presenting client certificates over SSL. I'm having issues with (413) Request Entity Too Large errors with large POSTs.
I've tried setting this in applicationHost.config
<serverRuntime uploadReadAheadSize="2147483647" />
However this had no effect. Are there any other settings that control URL Rewrite's rejection of large POSTs?
The web.config for the reverse proxy is very simple:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://my.internal.server:444/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
To sum up from the comment.
Try changing <httpRuntime maxRequestLength="4194304" /> first.
If it doesn't work try <requestLimits maxAllowedContentLength="2147483647" /> next.
If it stills doesn't work leave me a comment.
Normal setting for max upload file size:
Setting the request limits in the root web.config of the site (default is 30 MB). This can be set in Internet Information Services Manager Program also (MACHINE->Site->IIS->Request Filtering->Edit Feature Settings)
<!– 100 MB . Format uses Bytes –>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength=”102400000″ />
</requestFiltering>
</security>

404 File or directory not found with query subpath

IIS 10 is throwing the error
404 File or directory not found
Only when I try to access the url with subfolder path like this:
http://myserveraddress.com/object/181
So it works without the subfolder. The subfolder path is used by Angular to query a rest interface so there is no physical folder path behind it, just used for querying behind the schene.
This actually works when running on localhost but not on the server.
Is it possible to configure IIS such that it allows any url path even though the physical folder path does not exist?
This loos more like a handler configuration issue, and also if your server is a brand new server may be you haven't installed the handlers which is supposed to process your request, if i have to take a request if you haven't configured the rest handlers required it is goind to the static file handler which tries to look for a folder in the request url path and throw an error, if you already have a setup running, check all the handlers and pre-requisites installed there and mimic the setting over in the new server as well
The solution was to add this to the Angular client web.config file
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
More detail can be found here Get Angular2 routing working on IIS 7.5

How writing a url rewrite inbound rule for clean URLs for IIS

I have running Typo3 on server 2012R2 and IIS. On the same server also exchange is installed.
Typo3 now creates clean URLs, but this URLs always creates a 404 error. I found a solution to solve this problem with
<system.webServer>
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="SpeakingURL" enabled="false">
<match url="(^(typo3|fileadmin|typo3temp|uploads)/|\.(php|js|css|jpg|png|gif|pdf)$)" negate="true" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
but than exchange is not working correctly anymore. So I have to look for a solution which detects only clean URLs.
Example: http;//www.myDomain.com/customers/name/location
This URL I have to send to index.php.
There is no querystring in the url and no dot or any extension in the path.
How can I build a rule for the IIS URL rewrite, that incomming clean URLs will be passed to index.php?
Your problem are two kinds of virtual URLs.
I don't know much about exchange, but I know TYPO3.
In TYPO3 you have some few real folders for files like images, CSS, JS and all HTML is virtual. While you have exact pathes for the files only your virtual content is responsible for pathes to the HTML (virtual pages). That makes it difficult to give fix rules for rewrites.
In normal TYPO3 installations you have only those real files and the rest is virtual and handled by /index.php.
But that only is valid if you use TYPO3 9 or the extension realurl (or the old simulatestatic). otherwise TYPO3 only uses index.php and handles the rest in URL parameter (e.g. ?id=124&L=2&type=98)
Solution:
disable realurl (con: no nice URLs)
or use the extension staticfilecache, which exports all CMS-pages as real files so no rewrite is necessary (con: no 'dynamic' content).
It seems to be, that I found a solution for my problem. Up to now, it works fine for me.
I have added the code below in the system.webServer section in the web.config file under wwwroot.
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<clear />
<rule name="Clean URL" enabled="true">
<match url="(.*)" />
<action type="Rewrite" url="index.php" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
This is for Typo3 9,5+

Sails looking in wrong directory

I'm new to sails.js and node.js, so the question might be trivial, but I couldn't find the answer. I have deployed my node.js app to a web site in IIS, so the app can be reached at http://example.com/myapp/. When browsing to http://myhost.com/myapp/app.js, I get http status 404 (Not found), because sail.jss is looking for URLs like http://myhost.com/images/logo.png, but this file is in fact located at http://myhost.com/myapp/.tmp/public/images/logo.png. This .tmp folder seems to be created on the fly by the framework.
Can someone shed some light on this?
[edit]
I have added rewrite rules in the web.config and it works much better. But it only works if I put the application at the root of my web site (acessing http://myhost.com/). If I put the application in a lower level (accessing through http://myhost.com/myApp), then the added rules do not seem to produce any effect.
Here is the web.config:
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="StaticContent">
<action type="Rewrite" url="assets{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
The key is to allow Express to handle all of the routing. The best way to do that is to route all traffic to app.js via iisnode (from: https://nodestream.wordpress.com/2015/11/24/sails-js-configuration-for-iis/):
<configuration>
<system.webServer>
<!-- Tell IIS to use the iisnode module to run your
application -->
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<!-- Add iisnode with the #nodeProcessCommand line if
you see the error: Make sure the node.exe executable
is available at the location specified in the
system.webServer/iisnode/#nodeProcessCommandLine element
of web.config. -->
<iisnode
nodeProcessCommandLine="%ProgramFiles%\nodejs\node.exe"
/>
<!-- Since behind the covers, Sails.js is just an express app
rewrite all urls to processed by iisnode via app.js. This
will sort out things like the routing to your public
resources (images, js, styles) and all configured rest
endpoints. -->
<rewrite>
<rules>
<rule name="root">
<match url=".*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Well the .tmp folder is created by Grunt. You can reference the gruntfile and the task folder. The pipeline.js allows you to select files/folders for grunt to inject and spit out. You can easily change this to point to /images and /js folders.
tasks/pipline.js
module.exports.cssFilesToInject = cssFilesToInject.map(function(path) {
return '.tmp/public/' + path; // Change this
});
module.exports.jsFilesToInject = jsFilesToInject.map(function(path) {
return '.tmp/public/' + path; // Change this
});
Another solution I could think of, however I am not sure if IIS has it, is to do a rewrite rule. When a user goes to site.com/images, point them to .tmp/public/images. It is common to see that in Apache servers.

Resources