I have a angular 1.x SPA app built with ASP Web API hosted in Azure as a Web App. When I deploy new code browsers such as Chrome (not edge or IE) fail to get the new code based on If-modified-since or ETAG. The current workaround is to have users do a CTRL + F5 to force a download. There are some differences in the request headers between Edge and Chrome that may explain this but I am not very familiar with the cache control mechanisms within HTTP.
My main question is this an expected behavior and I need to deliberately detect this in client side code and force a refresh or is this something IIS is expected to handle by default? Secondarily is this something I can solve through changes to web.config?
Edge
Accept: application/javascript, /; q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US
Connection: Keep-Alive
Cookie: ai_user=T9jXc|2016-08-08T05:44:23.776Z; ai_session=2GcvV|1470765398272|1470765399564
Host: app.somehost.com
If-Modified-Since: Mon, 08 Aug 2016 16:34:46 GMT
If-None-Match: "0172c692f1d11:0"
Referer: https://app.somehost.com/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393
Chrome
Accept:/
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:ai_user=WXgAN|2016-08-09T16:28:50.251Z; ai_session=nV7TD|1470765376324|1470765376960
Host:app.somehost.com
If-Modified-Since:Mon, 08 Aug 2016 16:34:46 GMT
If-None-Match:"0172c692f1d11:0"
Referer:https://app.somehost.com/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
The issue was resolved by optimizing bundles. I had optimizations off as it was breaking dependencies that didn't not support minification. To fix the issue I removed the offending .js files from the bundles and references them directly. Then enabled optimizations in BundleConfig.cs
BundleTable.EnableOptimizations = true
Related
How to perform button click, named: "confirm", using python 3.x and requests library? What parameters should be passed with POST request.
In general i am interested how to guess what settings are needed to achieve my point.
Here are headers information from the browser network graph (with slightly modified values):
General
Request URL:SOMEURL
Request Method:POST
Status Code:302 Found
Remote Address:SOMEADDR
Response Headers
Cache-Control:private
Content-Length:203
Content-Type:text/html; charset=utf-8
Date:Wed, 20 Apr 2016 05:54:51 GMT
Location:SOMELOCATION
MicrosoftSharePointTeamServices:14.0.0.6123
Server:Microsoft-IIS/7.5
SPRequestGuid:04e5403d-3170-4c1d-a5a3-441776ca4e57
X-AspNet-Version:2.0.50727
X-MS-InvokeApp:1; RequireReadOnly
X-Powered-By:ASP.NET
X-SharePointHealthScore:0
Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,ka;q=0.2
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:3836
Content-Type:application/x-www-form-urlencoded
Cookie:filterValue=f4298401-b95c-4f84-b127-c1237f65819d; ASP.NET_SessionId=t35zomew310lpn45bgy1kp55; SectionId=15; databaseBtnText=0; databaseBtnDesc=0; Ribbon.ListItem=1366667|-1|655|1597680975; stsSyncAppName=Client; stsSyncIconPath=; Ribbon.ListForm.Display=808667|-1|503|815204513
Host:HOST
Origin:ORIGIN
Referer:REFERER
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Query String Parameters
itemID:ID
List:LIST
activity:ACTION
workflowID:WFID
source:SOURCE
Form Data
MSOWebPartPage_PostbackSource:
MSOTlPn_SelectedWpId:
MSOTlPn_View:0
MSOTlPn_ShowSettings:False
MSOGallery_SelectedLibrary:
MSOGallery_FilterString:
MSOTlPn_Button:none
__EVENTTARGET:
__EVENTARGUMENT:
MSOSPWebPartManager_DisplayModeName:Browse
MSOSPWebPartManager_ExitingDesignMode:false
MSOWebPartPage_Shared:
MSOLayout_LayoutChanges:
MSOLayout_InDesignMode:
MSOSPWebPartManager_OldDisplayModeName:Browse
MSOSPWebPartManager_StartWebPartEditingName:false
MSOSPWebPartManager_EndWebPartEditing:false
_maintainWorkspaceScrollPosition:0
__REQUESTDIGEST:0x2D3C5B3A042C327D5B676EA782F2AB9623C1E03DD32F9884204134C32E8EB4287AB98B49EB235D3E27D0F8C0870E3F1CE69ABCDC2AB9C3797023D74CC1DC9AA9,20 Apr 2016 05:53:06 -0000
__VIEWSTATE:REMOVED
__VIEWSTATEGENERATOR:REMOVED
InputKeywords:Search this site...
ctl00$PlaceHolderSearchArea$ctl01$ctl03:0
ctl00$PlaceHolderMain$hiddRedirectURL:
ctl00$PlaceHolderMain$hidConfirm:checked
ctl00$PlaceHolderMain$hiddValidate:
ctl00$PlaceHolderMain$Button2:Confirm
__spText1:
__spText2:
I'm trying to do a simple HTTP POST on the following website:
https://oktap.tax.ok.gov/oktap/web/_/
(click on "Permits" in the bottom left hand side)
I simply want to post a number and get the results from the page returned. Looking at the page with chrome's web developer tools it looks like the POST goes to both
https://oktap.tax.ok.gov/oktap/web/_/Recalc
https://oktap.tax.ok.gov/oktap/web/_/EventOccurred
I'm not sure if it's one or the other, it looks like EventOccured takes a couple more parameters. However when I post to either one of them with the following code:
#!/usr/bin/env bash
wget --post-data="D0IHwpHb__0_0_Ful0QW=5&VIEW__=VS_PermitSearch&LASTFOCUSFIELD__=D0IHwpHb__0_0_Ful0QW&DOC_MODAL_ID__=0&EVENT__=D0IHwpHb__0_0_Ful0QW&DOC_ACTION__=false&TYPE__=1&CLOSECONFIRMED__=false&FAST_VERLAST__=9.CvUZWPROHiWR-EO6d9UAeHYv4m81" \
-U "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547 Safari/537.36" \
https://oktap.tax.ok.gov/oktap/web/_/EventOccurred
First I get 307 Temporary Redirect and then ERROR 405: Method Not Allowed.
I don't see how the a post is not allowed, when it's clearly being made from the browser just fine. Any Help?
Here's the headers:
Request URL:https://oktap.tax.ok.gov/oktap/web/_/Recalc
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:146
Content-Type:application/x-www-form-urlencoded
Cookie:wdc-session=w0srLHI6Tz9tDLtEDo0n33PNuXSFexxysEHBa9v5dtjXBt/X4cKb9zKdxoVrtyDKseewwZMbU41vn3DLmyf0QUUjtKwXdmEhHtS69aZf94Y26cqd95rsiCKg06SQVIm5p63me/C2chBBapoABa1lJ8lf4F3MbBIiBAnCnbKlgVfXtsjpijt9i2PMILjlAalr
Host:oktap.tax.ok.gov
Origin:https://oktap.tax.ok.gov
Referer:https://oktap.tax.ok.gov/oktap/web/_/
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/31.0.1650.4 Chrome/31.0.1650.4 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
D0IHwpHb__0_0_Ful0QW:5
VIEW__:VS_PermitSearch
LASTFOCUSFIELD__:D0IHwpHb__0_0_Ful0QW
DOC_MODAL_ID__:0
FAST_VERLAST__:3.2sMmdbnwgvAQF41H3c_2XHozyeA1
Response Headersview source
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Encoding:gzip
Content-Language:en, en-US
Content-Length:318
Content-Type:application/json; charset=utf-8
Date:Thu, 03 Oct 2013 19:52:52 GMT
Expires:Fri, 01 Jan 1990 00:00:00 GMT
Pragma:no-cache
Server:Microsoft-HTTPAPI/2.0
Set-Cookie:wdc-session=w0srLHI6Tz9tDLtEDo0n33PNuXSFexxysEHBa9v5dtjXBt/X4cKb9zKdxoVrtyDKseewwZMbU41vn3DLmyf0QUUjtKwXdmEhHtS69aZf94Y26cqd95rsiCKg06SQVIm5p63me/C2chBBapoABa1lJ8lf4F3MbBIiBAnCnbKlgVfXtsjpijt9i2PMILjlAalr; path=/oktap/web/; HttpOnly; Secure;
X-Frame-Options:DENY
and
Request URL:https://oktap.tax.ok.gov/oktap/web/_/EventOccurred
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:226
Content-Type:application/x-www-form-urlencoded
Cookie:wdc-session=w0srLHI6Tz9tDLtEDo0n33PNuXSFexxysEHBa9v5dtjXBt/X4cKb9zKdxoVrtyDKseewwZMbU41vn3DLmyf0QUUjtKwXdmEhHtS69aZf94Y26cqd95rsiCKg06SQVIm5p63me/C2chBBapoABa1lJ8lf4F3MbBIiBAnCnbKlgVfXtsjpijt9i2PMILjlAalr
Host:oktap.tax.ok.gov
Origin:https://oktap.tax.ok.gov
Referer:https://oktap.tax.ok.gov/oktap/web/_/
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/31.0.1650.4 Chrome/31.0.1650.4 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
D0IHwpHb__0_0_Ful0QW:5
VIEW__:VS_PermitSearch
LASTFOCUSFIELD__:D0IHwpHb__0_0_Ful0QW
DOC_MODAL_ID__:0
EVENT__:D0IHwpHb__0_0_Ful0QW
DOC_ACTION__:false
TYPE__:1
CLOSECONFIRMED__:false
FAST_VERLAST__:4.Ol_i_B9mDsWsP0Mg0e02_y7OZjM1
Response Headersview source
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Encoding:gzip
Content-Language:en, en-US
Content-Length:3711
Content-Type:application/json; charset=utf-8
Date:Thu, 03 Oct 2013 19:52:52 GMT
Expires:Fri, 01 Jan 1990 00:00:00 GMT
Pragma:no-cache
Server:Microsoft-HTTPAPI/2.0
Set-Cookie:wdc-session=w0srLHI6Tz9tDLtEDo0n33PNuXSFexxysEHBa9v5dtjXBt/X4cKb9zKdxoVrtyDKseewwZMbU41vn3DLmyf0QUUjtKwXdmEhHtS69aZf94Y26cqd95rsiCKg06SQVIm5p63me/C2chBBapoABa1lJ8lf4F3MbBIiBAnCnbKlgVfXtsjpijt9i2PMILjlAalr; path=/oktap/web/; HttpOnly; Secure;
X-Frame-Options:DENY
As a developer for that company, I would not recommend looking up permits that way. For $150 per year you can get a file with this information.
Contact the OTC. http://www.tax.ok.gov/rules/rule6507.pdf - 710:65-9-6. Subscription to sales tax permit list
I want to get the user locale when he lands in my website and then stick it to the user (also stick the new one if he wants to change the language).
Yet I don't want the locale to appear in the url.
I implemented the LocaleListener from the Symfony2 doc but I am enable to get the user default locale at the first request.
This requests are giving me nothing for a response:
$locale = $this->getRequest()->attributes->get('_locale');
$locale = $this->getRequest()->get('_locale');
While
$this->getRequest()
Sends effectively
GET /Twinkler1.2.3/web/app_dev.php/ HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4 Cache-Control: max-age=0 Connection: keep-alive Cookie: __uvt=; PHPSESSID=f28e3958ecab05fe97d6fc6950eb72ec; SQLiteManager_currentLangue=2 Host: localhost:8888 Referer: http://localhost:8888/Twinkler1.2.3/web/app_dev.php/login User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36 X-Php-Ob-Level: 0
So how can I get the locale of the request (French here)?
Thanks in advance
Jules
$language = $request->getPreferredLanguage();
$request->setLocale($language);
I have an ASP.NET website (.aspx) that I call from within an ASP.NET MVC 4 mobile website (.cshtml) to get its html response string. Both sites are hosted on a Windows Server 2008 R2 system. They are created and published with VS2010 Professional.
-If I go directly to the external site and view source then it is correct.
-If I use any of the below ways of getting the external html:
using (WebClient client = new WebClient())
{
html = client.DownloadString(strUrl);
}
or
using (WebClient client = new WebClient())
{
byte[] DataBuffer = client.DownloadData(strUrl);
html = Encoding.ASCII.GetString(DataBuffer);
}
or
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(strUrl);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
html = sr.ReadToEnd();
sr.Close();
}
then the html is changed from this ( where the font-family is set on a parent table ):
<td align="right" style="color:Red;background-color:White;width:4.375em;border-bottom:1px solid black;border-right:1px solid black;">-27.0%</td>
to this:
<td align="right" bgcolor="White" style="border-bottom:1px solid black;border-right:1px solid black;"><font face="Arial,sans-serif" color="Red">-27.0%</font></td>
I doesn't look like anything else has changed other than the font style is changed to a tag, the background color moved from a style to a tag attribute, and the width style being completely removed. This happens on the entire page.
If I put a break point on the html variable and view it then the html has already been changed by the time DownloadString is called.
Anyone know why this is happening?
Thanks in advance.
edit:
this link: WebClient.DownloadString() Not Producing Exact HTML
is not quite the same thing as I am not using Ajax or JavaScript on the external page.
edit:
here are the request headers from fiddler and the site that calls the other site (I used Chrome):
GET / HTTP/1.1
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: .ASPXBrowserOverride=Mozilla%2f4.0+(compatible%3b+MSIE+6.0%3b+Windows+CE%3b+IEMobile+8.12%3b+MSIEMobile+6.0);
going to the site directly I get this request header:
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: .ASPXBrowserOverride=Mozilla%2f4.0+(compatible%3b+MSIE+6.0%3b+Windows+CE%3b+IEMobile+8.12%3b+MSIEMobile+6.0);
edit:
If I look at the client object in debug mode client.Headers is empty before and after DownloadString is called.
Also, after DownloadString is called here are the client.ResponseHeaders:
{Content-Length: 267123
Cache-Control: private
Content-Type: text/html; charset=utf-8
Date: Tue, 27 Nov 2012 18:37:27 GMT
Set-Cookie: ASP.NET_SessionId=******; path=/; HttpOnly
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
}
Solution:
Unfortunately I cannot accept two answers. Both Icarus and James Lawruk's answers helped me to solve the problem. I am picking an answer based on what most recently lead me to the final solution. So thanks to you both!
So here is the solution in a nutshell:
Use fiddler to view the request headers and find the user-agent.
Modify the code as follows:
using (WebClient client = new WebClient())
{
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
html = client.DownloadString(strUrl);
}
Try setting the user-agent value and experiment with different browsers. This may prove the Web site is switching the HTML response based on the user-agent header.
webClient.Headers.Add("user-agent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5");
var iphoneHtml = webClient.DownloadString("http://www.yoursite.com");
webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
var safariHtml = webClient.DownloadString("http://www.yoursite.com");
Most likely Browser Sniffing as Dour pointed out on his comment because WebClient does not change the resulting HTML at all.
You can probably verify this if you use Fiddler and set up the request headers in exactly the same way WebClient does. I bet you you get the same HTML output.
When using client side XSLT in IE9 I noticed that IE sends different headers for requests that fetch the XSL and subsequent requests triggered via the document() method, than for requesting the original XML file. In particular the accept-language header is missing completely.
The bootstrap XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
<root/>
and the XSLT like this
...
<body>
<xsl:apply-templates select="document('section.xml')"/>
</body>
...
What I notice is that both the XSLT as well as the section.xml file are loaded with an HTTP request without an accept language header.
The request headers to fetch the XML file look like this:
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US,de-DE;q=0.5
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
whereas the other resources are loaded with
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: Keep-Alive
Is is a feature or a bug? Other browsers such as FF or Chrome send identical headers.
A working example can be found on my test server
This effect causes problems in a real life project, because the XML files are generated dynamically and contain end-user facing content that is negotiated based on the accept-language header. This fails because no header is sent by the transformer.
Any insight or suggestions for workarounds are welcome!
Thanks!
Carsten
I vote for "bug" since it seems more logical to repeat the accept-language header for the dependent requests (not sure if that would be specified anywhere). Could you carry the language preference information as a query parameter for the request fetching the XSL?