Clear-Site-Data header error in Chrome console - c#

I'm trying to implement a cache clearing button for our website that will append the Clear-Site-Data header on a specific route so we can be relatively sure that the users are getting the latest javascript, css, etc. after a release. I'm assigning the header in my ActionMethod like so:
According to developer tools, I'm getting the header on the client:
So, Chrome is trying to do what I'm asking but it's throwing an error saying the types I'm passing it are unrecognized:
Am I missing something with how I'm creating the header? Is this a bug?

Ok, so here we are a few months down the road and I finally remembered to come back and post the working solution. What I didn't understand at the time I asked the question was that the quotes are expected to be treated as literal in the response header examples I found. So the code I posted in my question was missing a few \ characters in the strings. What ended up working was this:
The headers on the client now look like this (note the quotes around cache and storage):
And the cache and localStorage are cleared as desired. Hope this helps someone else as well!

Related

It is possible to utilize google search engine directly in C#

I've been trying to see all day if it's possible to write a web app in C#/asp.net that uses the google search engine. I've been googling about it all day. I don't want the custom search api because I'm not looking to have a search engine search through a site. I want to have my web app pass input to the basic google web search that search the entire net not a particular site so I can then parse through the first page of the search results. I put that in bold because it seems like the custom search api is for searching a particular site (my own site) which is not what I want to do and yet the only thing I could find. (well for the most part at least) The closest answer I found to my question is this https://stackoverflow.com/a/4082976/5607333 Which might do the trick for me but I don't know how to do that. How do I send search input to google search and get results using html? (or in my case asp.net) If you think it's the answer to my question can you please post an example of how it's done? I say "think" because I'm not sure it's the answer to what I'm asking.
I hope this question isn't considered a dupe to the question I linked to as I have been way more specific than it.
Also if this task isn't possible in C#/asp.net but possible in another language can someone please post an example of how it's done in that language or a link to it?
Update: I figured out what an easy solution is to this it hit while I was looking at another question similar to my problem. The solution is to edit the url and then i assume you could just concatenate it in C# with the + sign.
Update: 2 Even though I figured what I specifically was having trouble with at the moment of writing this question I still doesn't why I can't find a google equivalent of this https://msdn.microsoft.com/en-us/library/dd251020.aspx that's not depreciated. I read an answer to another question on here where someone said it's because that's how they make their money off the ad results but if that's true it still surprises me.
Look this question:
Adding Google's standard search (not custom) to my website
you can use your own XML parser to customize the display for your search users.
with an http request like this:
GET /search?q=bill+material&output=xml&client=test&site=operations
But it has a limitation on number of requests per day, 500 or 1000 I guess

Requests via Sense chrome extension to elasticsearch breaks when ID contains #

Trying to add documents to an elasticsearch index using Sense. eg:
POST productmarket/ppt/joe#broker.com_Index_withNewGuid_233df4
{
"hash" : "cake"
}
and I get back"
Request failed to get to the server (status code: 0):
Now if I change the # to something else it works fine.
Now we already have items in the index that have #'s in the id's. If I update them in a frontend APP we have that uses the API's to post it breaks as well eg.
BUT When I use our C# app to index a json document that has # in its id using NEST it works. And when I try and update this document again in the frontend app (where it just broke) it works as well.
Now I have tried indexing plain document and complex documents. Nothing changes. I've tried different indexes. Still the same problem.
Any idea what is wrong?
Figured it out. Pretty stupid.
Nest URL encodes the request.
Sense does not. Using the URL encoded value for # it works fine.

Is there a way to detect 404 pages using HtmlAgilityPack?

I am parsing a forum where some threads are already deleted. So opening them still shows a page but with a message that says "Thread no longer exists". Is there a way to query this using the HtmlAgilityPack in a special way?
Or do I have to compare the InnerHtml or something along those lines?
a 404 is not actually being returned. If it was, you could just look at the headers.
That said, you are getting a 200 response with an error in the html, therefore you will have to parse the html, traverse the DOM, whatever you want to call it and determine if it failed.
It appears that there could potentially be several different error messages, so I would try to make your comparison generic by looking for the "notify administrator" link or perhaps the class="blockrow restore" is only used on the error page.
Hope that helps.

Inconsistent POSTing between Web Browser and HttpWebRequest

I’m working on Web Scraping using C# HttpWebRequest/HttpWebResponse. For the most part this process has gone smoothly. But after POSTing my way through several pages, I have gotten stuck with what seems to be an inconsistency between testing with the Web Browser and the HttpWebRequest/HttpWebResponse calls.
The problem occurs when I land on a page containing an input element that has a name similar to this: “RidiculouslyLongInputName.RidiculouslyLongInputName.RidiculouslyLongInputName.#RidiculouslyLong”
POSTing a value for this input element causes a 500 error when using HttpWebRequest but works fine when POSTing through the browser. If I remove this input value from the post data the the HttpWebRequest will not get the 500 error. But then I'm stuck with a data validate issue from the website.
Any idea on why HttpWebRequest is failing?
It's times like these when packet sniffers come in extremely useful for seeing exactly what kind of data is flowing through and what the difference is.
http://www.wireshark.org/
Is a great tool for things like this.
Filter down to only the domains you're interested in, then send off the packet with HttpWebRequest. Save the packet data somewhere. Repeat but do the request through the browser. Check the difference.
If it is indeed an issue with POST variables, it should be evident in the HTTP payload.
Not sure why you are running into the problem, but I would recommend grabbing a copy of Fiddler and taking a look at what the browser is sending in the POST request. It is possible there is something less than obvious going on.
You can also use Firebug extension with Firefox. With this extension installed and enabled, go through the entire scenario in Firefox. FIrebug will tell you the exact request/response sent by the browser. You can then duplicate that as much as possible using HttpWebRequest
First thanks for MEF response. That case was a personal mistake so I deleted the question.
I think best tool for your case is Fiddler but I guess there are other JavaScript attached to that button or something like that you are missing to mimic. WebRequest cannot do that for you and WebBrowser can do since it's working on DOM.
In order to use WebRequest correctly you highly need to reverse engineer every request by something like Fiddler. It's very hard to find what's exactly going on by looking at the page's source (and it's referenced Javascripts/CSS...).

Filtering fiddler to only capture requests for a certain domain

I'm not sure how to modify the CustomRules.js file to only show requests for a certain domain.
Does anyone know how to accomplish this?
This is easy to do.
On the filters tab, click "show only if the filter contains, and then key in your domain.
edit
Turns out it is quite easy; edit OnBeforeRequest to add:
if (!oSession.HostnameIs("www.google.com")) {oSession["ui-hide"] = "yup";}
filters to google, for example.
(original answer)
I honestly don't know if this is something that Fiddler has built in (I've never tried), but it is certainly something that Wireshark will do pretty easily - of course, you get different data (in particular for SSL) - so YMMV.
My answer is somewhat similar to #Marc Gravels, however I prefer to filter it by url containing some specific string.
You will need fiddler script - it's an add-on to fiddler.
When installed go to fiddler script tag and paste following into OnBeforeRequest function. (Screenshot below)
if (oSession.url.Contains("ruby:8080") || oSession.url.Contains("localhost:53929")) { oSession["ui-hide"] = "yup"; }
This way you can filter by any part of url be it port hostname or whatever.
Hope this saves you some time.
You can filter the requests using the filter tab in fiddler. Please see screenshots below. If you are using google chrome, be sure to use the correct process id in fiddler(from google chrome).
The Fiddler site has a cookbook of a whole bunch of things that you can do with CustomRules.js, including how to do exactly this :)

Categories