On my IIS machine (Windows 10) its working, but not on the hosting server (Windows 2008R2, IIS 7.5).
Hosting server: Video is not showing in Chrome by directly opening it via url. I get the error in the console net::ERR_CONNECTION_RESET. But its working in IE. Strangely images are working in Chrome.
This happens since i implemented a security mechanism: A file call is now forced to go through the Framework routing. The route calls a controller, then after some security checks, returns the file as BinaryFileResponse.
I had to adjust the webconfig (htaccess on linux). The video file is under a data/content folder.
<rule name="ID:0001 Folder or File exists" enabled="true" stopProcessing="true">
<match url="^(?!data/content)[a-z].*$" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
<action type="None" />
</rule>
<rule name="ID:0002 Datafolder" enabled="true" stopProcessing="true">
<match url="^data/((?!content).)*$" />
<action type="None" />
</rule>
I was searching on the internet and all what i found were possible problems with network, firewall or caching. But i dont think its a problem of that, because its since i am returning the response with Symfony BinaryFileResponse.
$response = new BinaryFileResponse($webPath);
$response->setAutoEtag(true); // Needed for partial loading of video
$response->headers->set('Content-Type', 'video/mp4');
return $response;
Network headers:
General
Request URL:http://foo.....bar.mp4
Referrer Policy:no-referrer-when-downgrade
Request Headers
Provisional headers are shown
Accept-Encoding:identity;q=1, *;q=0
chrome-proxy:frfr
Range:bytes=0-
Referer:http://foo.....bar.mp4
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
The solution was for IIS 7.5 to return more informations in the response header. Read this.
Related
I try to install react(axios) in IIS and use node.js as server GET,POST work fine but PUT,DELETE (can use in internal) did not
I tested in Linux server node.js work fine, I try to solve for week such as ExtensionlessUrlHandler ,cors, etc. now I disable Request filter in IIS still did not work.
Failed to load resource: net::ERR_CONNECTION_RESET
(I can not upload picture.)
Common HTTP Features (4 of 6 installed)
Default Document
Directory Browsing
HTTP Errors
Static Content
Health and Diagnostics
HTTP Logging
Performance
Static Content Compression
Application Development
CGI
ISAPI Extensions
ISAPI Filters
WebSocket Protocol
Management Tools
IIS Management Console
web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This error may be caused by cookies and most often seen with chrome users.
You can try the following steps to solve your problem.
Go to Chrome settings > Privacy and security > Cookies and other site data > Cookie > All cookie and Site Data > Delete domain problem
Or you can refer to this link: Failed to load resource: net::ERR_CONNECTION_RESET
I have an ASP.NET site hosted on IIS.
I am using Application Request Routing proxy and url rewrite rules for some pages.
I add rewrite rule to proxy requests from http://example.com/my-url/ to http://other-server/my-url/.
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^my-url/.*" />
<action type="Rewrite" url="http://other-server/{R:0}" />
</rule>
The problem is that I want to implement condition that rewrites this page not for all users, but only for 10% or some other part of users.
For each user result of opening the page should be the same.
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^my-url/.*" />
<conditions>
<add input="Is it possible to write a rule that works only for 10% users?" />
</conditions>
<action type="Rewrite" url="http://other-server/{R:0}" />
</rule>
Is it possible?
According to your description, I suggest you could try to write hte logic in the codes to store some special data in the http cookie like "role=roleA", then you could try to write the url rewrite role accordign to the httpcookie condition.
Like below:
GET http://aaaaaaa.com/test.aspx HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0
Host: myserver.com
Cookie: role=roleA
Url rewrite rule:
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^my-url/.*" />
<conditions>
<add input="{HTTP_COOKIE}" pattern="rule=ruleA" />
</conditions>
<action type="Rewrite" url="http://other-server/{R:0}" />
</rule>
I am trying to enable http to https redirection in our Azure App Service using web.config rewrite rules. According to all documentation I can find, web config redirect using rewrite rules is the official way to get this feature. One of the features that I like and want to support is gzip as an Accepted-Encoding, this is enabled be default. But those two features seem to conflict. Is there another way to do the redirect? Do I have to disable compression?
Here is my redirect rule:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="Off"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
Curl command that responds with the content that I only want to be delivered over SSL:
curl "http://[MyUrl]/" -H "Accept-Encoding: gzip, deflate" --compressed
Curl command that executes as expected:
curl "http://[MyUrl]/"
Response:
HTTP/1.1 301 Moved Permanently
Content-Length: 154
Content-Type: text/html; charset=UTF-8
Location: https://[MyUrl]/
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Date: Tue, 29 Aug 2017 19:29:29 GMT
Thanks in advance.
In case this is valuable, requests outside of the root url seem to work as expected. Only the root url seems to return the content without the redirect.
Update
I think this might have to do with my SPA rewrite rule, although I am not sure of the interference as the first rule has stopProcessing on it. I was able to recreate the issue at cdwredirecttest.azurewebsites.net. If you hit the site, it will redirect you to https, but only the first time. Open another browser and try again, this time it will load the site over http. After the server caches the gzip response you no longer get redirected. Here is my full web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="Off" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
<rule name="Redirect all requests">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
According to your description, I followed your URL rewrite rule and tested on my azure web app. I specified the -L option in order to enable curl to follow HTTP redirects as follows:
curl "http://{your-webapp}.azurewebsites.net/" -L -H "Accept-Encoding: gzip, deflate" --compressed -v
curl "http://{your-webapp}.azurewebsites.net/home/index" -L -H "Accept-Encoding: gzip, deflate" --compressed -v
I could retrieved the response with the Content-Encoding: gzip header from the above commands as follows:
After digging around and recreating the issue, I opened a ticket with Microsoft. The issue is specifically around Single Page Applications and SSL redirecting using rewrite rules when compressed content is accepted. Apparently IIS is caching the gzip response so the SSL redirection never occurs. The solution is to disable caching:
<system.webServer>
...
<caching enabled="false" enableKernelCache="false"/>
...
</system.webServer>
These are the steps that I came up with to recreate the issue:
Create a new Azure App Service
Rename hostingstart.html to index.html (probably not necessary except the rewrite rule later uses it)
Add the following web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="Off" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
<rule name="Single Page App">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Load the http site in a curl. This will cause the redirect response to happen as expected.
curl "http://cdwredirecttest.azurewebsites.net" -H "Accept-Encoding: gzip, deflate" --compressed
Load the https site in curl. You will get the page content as expected (I believe IIS is caching this gzip response and using it later).
curl "https://cdwredirecttest.azurewebsites.net" -H "Accept-Encoding: gzip, deflate" --compressed
Load the http site in a curl. If you get a redirect response, you will need to repeat 5 and 6. Eventually the response will return the content.
curl "http://cdwredirecttest.azurewebsites.net" -H "Accept-Encoding: gzip, deflate" --compressed
Now load a web browser that has not cached the redirect response. You will load the site over http instead of redirecting to https.
As soon as IIS gives up the cached response, you can use curl to see the redirect and you can repeat 5 and 6 to get the app into the failing state again.
I created a rewrite rule in IIS because of some Russian spammers but the rule doesn't seem to work correctly because of a space between two parts to search and I was wondering how to overcome this
<rule name="Russian Referral Spam" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="Windows+2002|Windows+2003|Windows+2004|Windows+2005|Windows+2006|Windows+2007|Windows+2009" />
</conditions>
<action type="Redirect" url="https://stackoverflow.com" redirectType="Permanent" />
</rule>
Before, I never included the spaces between Windows and the fake version:
Windows 2002|Windows 2004...
and that would pickup on anyone with Windows in the useragent and redirect them. With adding the + to the rule even with backslash before it's not affecting the Russian spammers. How do I change the above rule so that it searches for 'Windows 2002|Windows 2004|Windows 2005|Windows 2006... If it was in a URL I could add %20
Here are a few real examples of the Russian Spam User Agents:
Mozilla/7.0 (compatible; MSIE2.00; Windows 2005)
Mozilla/8.0 (compatible; MSIE3.00; Windows 2006)
Mozilla/6.0 (compatible; MSIE7.00; Windows 2008)
Mozilla/4.0 (compatible; MSIE4.00; Windows 2005)
I am not using Apache but IIS so no mod-rewrite rules, please.
Thanks in advance
UPDATE:
On Expert Exchange it says try Windows\ 2006 or Windows\s2006. Will try these but I am waiting for the spammers to return to get the 100% answer but I know within IIS I can test the rules so I will try that also
You were correct. For space in regexp you can use \ or \s. Your rule can be something like that:
<rule name="Russian Referral Spam" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="Windows\s(2005|2008)" />
</conditions>
<action type="Redirect" url="https://stackoverflow.com" redirectType="Permanent" />
</rule>
i want to POST form data to the default page of a web-server, e.g.:
POST http://errorreporting.example.com/ HTTP/1.1
i want the server to be responsible for 302 redirecting the client to where the POST should go. The default.asp file on the server performs this task (which is the technique Microsoft recommends), by performing the Redirect:
default.asp:
<%
Response.Redirect "SubmitError.ashx"
%>
When i simply browse the server:
GET http://errorreporting.example.com/ HTTP/1.1
i get the expected response from the server:
HTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Location: SubmitError.ashx
...
But when i POST to the server:
POST http://errorreporting.example.com/ HTTP/1.1
The server gets very grumpy with me:
HTTP/1.1 405 Method not allowed
Connection: close
Allow: OPTIONS, TRACE, GET, HEAD
...
i want the server to be able to redirect the client to the appropriate submit URL, rather than hard-coding the client with the URL. This is, of course, because the URL could (i.e. has) changed:
http://errorreporting.example.com/SubmitError.asp
http://errorreporting.example.com/SubmitError.aspx
http://errorreporting.example.com/SubmitError.ashx
http://errorreporting.example.com/ErrorReporting/Submit.ashx
http://errorreporting.example.com/submiterror.php
http://errorreporting.example.com/submit/submiterror.ashx
etc.
Note: If i change the URL to include the document location:
/* SErrorReportingUrl = 'http://www.example.com:8088/ErrorReporting/SubmitError.ashx';
SErrorReportingUrl = 'http://www.example.com/ErrorReporting/SubmitError.ashx';
SErrorReportingUrl = 'http://errorreporting.example.com:8088/ErrorReporting/SubmitError.ashx';
SErrorReportingUrl = 'http://errorreporting.example.com/SubmitError.ashx';
SErrorReportingUrl = 'http://errorreporting.example.com';
SErrorReportingUrl = 'http://errorreporting.example.com/SubmitError.ashx';
*/
SErrorReportingUrl = 'http://errorreporting.example.com/submit/SubmitError.ashx';
It works fine:
HTTP/1.1 200 OK
Turns out getting IIS to support POST doesn't really help.
i'm using XMLHttpRequest to perform the POSTs. Nearly every implementation of XMLHttpRequest out there (e.g. Chrome, Internet Explorer, MSXML) has a bug where it performs a GET, instead of a POST, after following the redirect.
The W3C's XMLHttpReqest specification says that redirects should be followed and requests reissued:
If the response is an HTTP redirect:
If the redirect does not violate security
(it is same origin for instance),
infinite loop precautions, and the
scheme is supported, transparently
follow the redirect while observing
the same-origin request event rules.
Note: HTTP places requirements on the user
agent regarding the preservation of
the request method and request entity
body during redirects, and also
requires end users to be notified of
certain kinds of automatic
redirections.
And here's a site where you can test the bug in your browser's XmlHttpRequest implementation.
In the end, i'll work around an IIS bug, and an XMLHttpRequest bug, by having my "default" page do everything that a 302 redirect would, but return 200 OK instead:
HTTP/1.1200 OK
Connection: close
Date: Sun, 27 Jun 2010 13:28:14 GMT
Server: Microsoft-IIS/6.0
Location: http://errorreporting.example.com/submit/SubmitError.ashx
Content-Length: 92
Content-Type: text/html
Cache-control: private
<HTML><BODY>This content has moved here.</BODY></HTML>
i'm forcing the client to do two hits anyway - might as well have it work right.
I'm running Vue.js on Express/Node. The back-end is running on server port 3300, but we didn't want to expose that publicly.
I installed the requirements (Application Request Writing and URL Rewrite) and then added an Inbound Rule to rewrite the back-end requests to Express, but I kept getting 405 (Method not allowed).
Eventually I got it going by gleaning a few ideas from Stefano Scerra's Blog.
Here's my final web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="api" stopProcessing="true">
<match url="^api/(.*)$" />
<action type="Rewrite" url="http://10.1.1.217:3300/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Filter" verbosity="Verbose" />
</traceAreas>
<failureDefinitions timeTaken="00:00:00" statusCodes="100-999" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>