Coldfusion page executed twice - iis

Hi I am having a strange problem. On our development server coldfusion pages are executed twice. This happens everytime. To find out what is causing this issue, I send an email containing the request details to myself like this:
<Cfmail from="*" to="*" type="html">
<cfdump var=#GetHttpRequestData()#>
#gettickcount()#
#createUUID()#
</cfmail>
I get the following response when calling a page containing .cfm:
content [empty string]
headers struct
TOMCATCGIHTTPURL000000006A6B0000 /test.cfm
accept */*
content-length 0
host *
user-agent curl/7.40.0
method GET
protocol HTTP/1.1
1590760731452
C7487929-D679-B029-6E236DEE7E19B8EB
and a second mail containing
content [empty string]
headers struct
X-Original-URL /test.cfm
accept */*
content-length 0
host *
user-agent curl/7.40.0
method GET
protocol HTTP/1.1
1590760731425
C7487814-FA6F-4699-182C2E7382A06A47
Now the really strange part. When i call an index.cfm without the filename like / the page is only executed once. For example calling a page located on /test/index.cfm as /test/ returns as single response:
content [empty string]
headers struct
X-Original-URL /test/
accept */*
content-length 0
host *
user-agent curl/7.40.0
method GET
protocol HTTP/1.1
1590762636945
C86B3A74-025F-6DBA-EA187DFEF7751F03
Details of environment: Windows 2016 server, IIS 10, Coldfusion 2016
Any thoughts on what is causing this issue.
UPDATE
I use rewrite rules. I tested disabling the rewrite rules (as suggested by Miguel-F) and then the page is executed only once. When adding a simple rewrite rule like this the page is executed twice:
<rule name="Test rule" stopProcessing="true">
<match url="^(.*)$" />
<action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>
This behavior only occurs on our development server. Our production server has none of these issues and also runs on windows 2016 IIS 10 and coldfusion 2016.
Coldfusion version for development server: 2016.0.13.316217 (Production server runs on exactly the same version and has no issues)

This is not really an answer, but a really long comment.
You need to find out if this is one request or two. Add in some code like this:
<cfparam name="request.count" default="0">
<cfset request.count++>
<Cfmail from="*" to="*" type="html">
<cfdump var=#GetHttpRequestData()#>
Request.count: #request.count#
<br />
#gettickcount()#
#createUUID()#
</cfmail>
If the file was requested twice, each email will say 1
If the file is being included somehow, then then second email will say the request count is 2

Related

Why IIS Rewrite - Redirect is not working?

Unable to get URL rewrite to work.
http://my.domain/sso/my_app => http://my.domain:81/my_app
It doesn't have to be complicated, right ?
http://my.domain:81/my_app displays the expected page.
Here is the rule:
<rewrite>
<globalRules>
<rule name = "Laravel secure on port 81" enabled = "false" patternSyntax = "ECMAScript" stopProcessing = "true">
<match url = "sso /(.*)" />
<action type = "Redirect" url = "http://localhost:81/{R:1}" appendQueryString = "true" />
</rule>
</globalRules>
</rewrite>
I am testing on the IIS server itself http://localhost/sso/mon_app : no redirect, connection failed.
I tried with Application Request Routing by activating the proxy, by checking or not "Use URL Rewrite to inspect incoming requests".
By checking, it creates a redirect rule that I adapted :
<rule name = "ARR_server_proxy" enabled = "true" patternSyntax = "ECMAScript" stopProcessing = "true">
<match url = "* sso / *" />
<action type = "Rewrite" url = "http://localhost:81/{R:1}" />
</rule>
Nothing to do, it does not work.
No log in Failed Request.
I have no more idea.
Thanks, you help me to find the error : it's the port number.
I didn't know that the port 81 is forbidden in my office.
After some other tests with the port 8080, it's OK.
Enable proxy is checked in ARR.
Use URL Rewrite to inspect incoming requests isn't checked in ARR.
The rule stays in the server level with the port 8080
<rule name="Laravel secure on port 8080">
<match url="sso/(.*)" />
<action type="Rewrite" url="http://my.domain:8080/{R:1}" />
</rule>
Did you check the enable proxy on ARR? Reverse proxy only can work when proxy has been enabled.
I think there are some points which make the redirect failed.
The rule Laravel secure on port 81 should be add at site level not server level. Reverse proxy is to proxy the request sent to one site to another site, instead of proxying the request as soon as the request is sent to the server (the request has not been sent to any site).
The rule ARR_server_proxy doesn't have () in match url. So {R:1} always null.
In summary, you juest need to remove this rule to default site(or any other site which bind to http://mydomian). Request can be sent to default site first. The url match the rule and ARR proxy it to http://my.domain:81/my_app.
If it still fail, please use failed request tracing to troubleshoot url rewrite.

How to serve static file (json) to a explicit path

I want to add a path mysite.com/_this when a request for this path is called I want to serve the json file that's under Sites/MySite/Content.
The caveat is I cannot implement this via code change. I need a way to implement this setup using the IIS CLI.
I have found the following article https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing, but it's a little cryptic and hard to follow.
Windows: Window Server 2016 (1607)
IIS: 10.0.14393.0
In my opinion, the right solution for your issue is iis URL rewrite module.
If you did not install the url rewrite module you could download from the below link:
URL Rewrite
then add a rule in web.config file:
<rule name="Json Redirect" stopProcessing="true">
<match url="([\S]+[.](json))" />
<action type="Rewrite" url="folderpath/{R:1}" />
</rule>
You can do all these changes in the IIS Manager UI, but if you want to script them, look into the PowerShell IIS cmdlets.

IIS URL Rewrite and ARR don't handle rewrite rule properly

I have a problem with some understanding of how the URL Rewrite and ARR work together. I have a site and a standalone service that generates and provides updated sitemaps for the site. Below is my rule to handle sitemap requests. It is a local rule in the web.config under sites directory (the site is hosted under IIS 10).
<rule name="Sitemap Rule" stopProcessing="true">
<match url="^sitemap.*" />
<action type="Rewrite" url="http://sitemap.mysitedomain/provider?key={R:0}" logRewrittenUrl="true" />
</rule>
All looks good but it doesn't work. The only response I've got is 404. I should note that the ARR module is active and it properly handles other proxy requests.
To be transparent on this rule imagine that some web-robot request http://mysitedomain/sitemap.xml and the real request will be served from the http://sitemap.mysitedomain/provider?key=sitemap.xml where sitemap.mysitedomain is hosted on different servers and different environment.
The strange things here is that if I put empty sitemap.xml to the root of mysitedomain all my requests to the sitemap.xml start working as expected and I started to get updated sitemap.xml from sitemap service and an empty one that I've placed to the root of the site.
Added some tracing info from failed request
For the failed requests I have next in the tracing file
...
ModuleName RewriteModule
HeaderName X-Original-URL
HeaderValue /sitemap.xml
Replace true
OldUrl /sitemap.xml
NewUrl http://sitemap.mysitedomain/v1/sitemap/provider?key=sitemap.xml
...
ModuleName ApplicationRequestRouting
Notification MAP_REQUEST_HANDLER
fIsPostNotification false
...
OldUrl http://sitemap.laf24.ru/v1/sitemap/provider?key=sitemap.xml
NewUrl /sitemap.xml
...
ModuleName ManagedPipelineHandler
Notification EXECUTE_REQUEST_HANDLER
HttpStatus 404
HttpReason Not Found
HttpSubStatus 0
ErrorCode The operation completed successfully. (0x0)
I should point again that if I place an empty sitemap.xml to the root of mysitedomain, than all start working as expected. I got actual data from sitemap.mysitedomain.
I have found why it is happen and it is not a problem with Url Rewrite or ARR modules. The main reason is that ASP.Net handle such requests and return 404 because there are no routes defined to process such paths.
To fix this we added ignore definitions for sitemaps urls
routes.IgnoreRoute("sitemap.xml");
routes.IgnoreRoute("sitemap/{*pathInfo}");

Getting 404 errors using Slim PHP on IIS7

I'm trying to use the Slim PHP framework with IIS7. Now on some routes I keep getting a 404 from IIS which I find really confusing. Here's my index php:
require 'slim/slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->notFound(function () use ($app) {
echo("not found!");
});
$app->get("/books/:id", function($id){
echo("hello book " . $id . "!");
});
$app->get("/test",function(){
echo("testing");
});
$app->run();
On IIS (running PHP 5.3) I've setup the url rewritting to send all requests to my index.php file and disabled directory browsing. This seems to work fine as going to localhost/books/123 produces "hello book 123!". But when I go to localhost/test I just get a 404 error from IIS! If add a trailing slash to that url my slim notFound handler is triggered instead of my route handler.
If i create a directory called "test" it stops the 404 response but triggers the slim notFound handler rather than the defined route handler as I would expect. This seems really weird as I've disabled directory browsing.
I know my slim notFound handler is working ok as trying localhost/abc/xyz triggers the handler and works as expected.
Could anybody explain what is going on and why? Have I overlooked some configuration?
Thanks.
It turns out this weird behaviour was caused by my url rewrite rule on IIS. Doh!
I had the regex rule /.* rewrite to my index.php file rather than use .* as the regex.
The first slash wasn't being included as part of the rewritten url which then caused the issue I described. Changing the regex to just be .* fixed everything.
If anyone else encounters an issue like this then double check your url rewrite rule even if it seems to be working ok!
My very simple web.config file is:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim catch all" enabled="true">
<match url=".*" />
<action type="Rewrite" url="/index.php" />
<conditions>
<add input="{URL}" pattern="/content/.*" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
Note: this is using URL Rewrite 2.0 on IIS
Index.php is the file which sets up all the Slim routing. The condition is stopping requests to the /content/ path from being routed through Slim - this makes it a good place to store things like images, css files and javascript as the responses should be faster as they are not processed by Slim.

IIS 7 Url Rewriting and two domains

I was writing up this question and in the process, it forced me to think a little harder and I answered it myself, though I still don't completely understand why it solved it.
I have an account on a shared host with 2 domains registered. I'm using the Asp.Net stack to run a few things like a blog and another site I am planning to kick off eventually. Both of my domains point to the root; the first is the original I used to signup, the second is a root domain pointer I added. Here is how I want it to behave:
Directory Structure:
Root (www.domain1.com)
Root --\ Blog (www.domain1.com/blog)
Root --\ Site2 (should be directed here if www.domain2.com)
Root --\ Site2 --\ Junk (www.domain2.com/junk)
Right now, if you type in www.domain1.com or www.domain1.com/blog, that behaves as expected and I am fine with that. For www.domain2.com, I have the rewrite rule configured like this(from the web.config):
<rule name="Domain2">
<match url="(.*)(/)?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="(www\.)?domain2\.com" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="/site2/{R:1}" />
</rule>
That rule is supposed to match any path if the host is domain2.com, pick off the path to the requested resource and format it properly. So when somebody types www.domain2.com/junk/default.aspx, in IIS, this resolves to www.domain2.com/site2/junk/default.aspx without the user ever knowing. This is mostly working as advertised except when the user does not type a trailing slash in a subfolder. IE:
www.domain2.com (works)
www.domain2.com/ (works)
www.domain2.com/junk/ (works)
www.domain2.com/junk (doesn't work!) IIS 7 looses its brain here and formats it out like www.domain2.com/site2/junk because a 2nd request is automatically issued for the trailing slash and a 404 happens.
So, I updated the action to be:
<action type="Rewrite" url="/site2/{R:1}/" />
This seems to have resolved it, but why doesn't IIS 7 now spit out www.domain2.com/junk2/default.aspx/ ? How does it know not to append a trailing slash to a document extension?
www.domain2.com/junk does not work because you added slash in match, but actual url to match does not contain it. It just contains "junk".
Also you need to add:
<rule name="Domain2" stopProcessing="true">
so it does not evaluate other rules if match is found. I suspect that you may see that what confuses you, is other rules you have setup.

Resources