GET request updating 'seen' status - http

First of all, I am aware of the details mentioned in the HTTP 1.1 specification saying GET requests should be idempotent, and it all makes total sense to me. I'm always using POST requests for login/logout, form updates and everything that changes the state of my web app, but I have a problem with one particular scenario.
Imagine you're displaying a list of user's notifications, and you want to update the seen status once they've been rendered into html. The simplest solution is to perform an update of the model instances during the GET request, but that's where it would break HTTP 1.1 specs. Not only it would not follow the specs, but I'm also concerned about url prefetching and automatic GET request retry in some browsers, and maybe other possible scenarios.
Doing it using AJAX also doesn't seem like a good enough solution to me, because I would like the web to also work correctly with JS disabled.
The site also has an API for iOS/Android, but there it can be easily solved in multiple ways which seem right to me, so that's not a problem.
Did you guys come across any similar problem to this and found a way to handle it? I can't seem to find a good solution to this problem. Any help is appreciated.

Ok, so I think I found a solution which makes sense. I'm going to implement the AJAX solution (POST) + a 'Mark all as read' button (POST) as a fallback for the edge case.

Related

Fetching data from API for ReasonReact app

I'm learning ReasonReact and I would like to fetch data from a API, that I'm going to use on my component. However, on the official website about Reason or ReasonReact there's nothing about this, neither I found something searching on Google. How can I do it?
You can use the existing bindings to HTTP client libraries, e.g.:
https://redex.github.io/package/bs-fetch
https://redex.github.io/package/bs-axios
The former works in browser only, the latter works in both browser and Node.
In general, if you're looking for a way to do something, Redex is a great place to look.

Hide the part of site address in toolbar browser in asp.net

I want to hide part of the address in the browser toolbar in asp.net.
For example, if it's http://mysite.com/News/Shownews.aspx?ID=-1&Num=20, it should change to http://mysite.com/ on every page.
I visit some websites that do exactly like this. Can anybody help me?
You probably want UrlRewrite.
Or, you can use asp.net mvc, it has routing feature.
No idea why you would do such a thing, but some hacky solution comes to mind:
http://mysite.com/News/Shownews.aspx?ID=-1&Num=20 will respond with a redirect to http://mysite.com/ and stashes whatever information is necessary in cookie/session state/... (like ie. the complete original request URL)
The controller handling http://mysite.com/ grabs the state and renders the appropriate output
Of course this might introduce some race conditions dependent on the exact method used to store the relevant state.
All in all that whole undertaking is a pretty bad idea thinking of principles like REST...but since you asked for it...
Yep, URL rewriting is what you're looking for most likely: http://msdn.microsoft.com/en-us/library/ms972974.aspx is a broad overview of the topic.

Gridviews/Tables paging. POST, GET or AJAX?

I am building my own GridView in an ASP.NET project
I am drawing out my plans and I was wondering what the best solution is to a simple problem, paging and sorting.
The fast and easy way is using submit buttons (or similar) and POSTING the form back. That's also how the ASP.NET gridview works.
pro:
less overhead
con:
backbuttons
The second method is using links and the URL with GET requests.
pro:
backbuttons work just fine
direct link to certain position
con:
less reusable because of the dependence on url
The third method is AJAX
pro:
little overhead
con:
harder to implement
What design/solution would you pick and why?
Am i overlooking some pros and cons?
I add some extra comments to think about.
-The second method is using links and the URL with GET requests.
This is the one that you need to use, if your need web spiders (google) knows all the pages of your site, and be SEO friendly. This method have the problem that you can not have viewstate and each time you must render the page that you see on the url parameters with out knowing anything else.
With this case you probably have more problems if you wish to make edit on one line
-The fast and easy way is using submit buttons (or similar) and POSTING the form back
This is the method if you won to have many functionality on code behind because with the post back you have all the previous action that you have done, and the viewstate is working and can be used for that. Is not SEO friendly and if you like to make it you need extra code to write on the url just the page that you are now and need to land.
-The third method is AJAX
This is the method that must co-exist with the previous and not alone for the case that the browser fails to run javascript for any reason. If you do not care about that, the rest is that this method is also not SEO friendly and you need to make it, is cool, modern, and is a must for modern site, but if you going to make difficult things then you may end up with many issues that must be solved.
To summarize:
More than show data ? Post Request : Get Request ; // ToDo: make it ajax

Need to disable an array of ctrl keys for my site

Especially Ctrl+I , which is "mail this page". I'm using wordpress self hosted. So far I've found this code, not sure how to implement it or if it's old.
Please no plethora of reasons as to why you find this attempt pointless.
Really, shouldn't answer, but:
There's no reason for this, because there's always a very easy way around it. It'll probably take a lot more work than whatever you end up with's worth. If somebody has half of a computer literate mind, they probably can get past this without a problem at all.
Summary:
Don't bother
Disabling hotkeys won't stop anyone from just selecting that option from the File menu.
People will always find ways around these kinds of hacks. Turning off JavaScript, hacking the source with Firebug, Option+Click on a Mac, taking a screenshot, etc. They are completely ineffective against anyone even slightly determined to do what you don't want them to do.
You can't really do that. See this page for really good information on the portability of various key events in JavaScript across multiple browsers. You will see for one that each browser handles/responds to various key events in many different ways.
Also, most of the default browser actions (e.g. Ctrl-F, Ctrl-S) cannot be canceled if you are capturing key events. You can still detect some of them and respond, but you can't actually stop the browser from displaying the search dialog or whatever specific action is to be performed by the key combination.
Also, if someone really wants to take your page's HTML/JavaScript code or content, these methods won't stop them. The disable right click code from the link you referenced can prevent right click, but all someone has to do is disable javascript and it no longer works.

Writing a replacement asp/html form for a legacy system

Quick question.
There is a legacy website (that is not under my control and cannot be modified), that gives users a form to fill in data and then the user 'submits' the form for processing. There is virtually no error checking on this form, and very little help for the user (i.e. it was very poorly designed about 12 years ago and hasn't been updated since).
None-the-less, the back-end of this application performs a critical function.
My question is, is it possible (without having any ability to modify the legacy website), to write my own new front-end in asp.net (with proper pre-submit validation) living on a different server & domain, and then simulate the 'submit' to another webserver as long as I reproduce the form/data that is being sent?
The key question here I guess, is it possible to submit a form produce on one website, to another, and can this be done with ANY changes to the legacy site?
Comments appreciated.
The key question here I guess, is it possible to submit a form produce on one website, to another, and can this be done with ANY changes to the legacy site?
Yes, I've done this before - provided that the target site doesn't do any referer checking. A POST request is a POST request, no matter where it originates from.
You just need to make sure that all the fields are exactly the same in your request as they would be coming from the original page, i.e. - same field names, same encoding etc.
The short answer is "yes", the long answer is "it depends". The basics of HTML and HTTP allow for it, but without knowing a little more about the implementation of the legacy site you can't know for sure that it will work.
In theory you just need to make sure that the name of the fields are the same and set the target of the form to the legacy site's page URL.
In practice the legacy site could be doing various things that make it difficult or impossible to achieve (it could require cookies set correctly or hold internal state for example).
The best thing would be just to try it. It shouldn't take long just to mock up the basic fields and post the form to see if it works. Once you know it works then you can worry about adding your extra validation etc
Beware that if the existing site is authenticating users you'll need to find a way to also collect and pass that info along. Otherwise, though, Phill's point is spot-on.

Resources