I have a situation whereby I need to redirect a user from a page on my server to a page on another server. In this redirect I need to also send some xml to the server I am redirecting to. This xml file could be quite long so just sending it in the querystring isn't an option.
I have tried attaching the xml in a header but the header doesn't seem to make it to the other end.
I know how to programmatically create requests to send xml and how to redirect, just not sure how to do both at the same time.
In short, I need the xml to piggy-back on the redirect. This redirect will be done from within an MVC Action.
Thanks in advance.
Edit
I have come up with the following potential solution to my problem. Unfortunately it does utilise two requests which I had hoped to avoid.
Basically I send the xml file as a header of a post request which also contains a session id. This is sent asynchronously.
I then redirect the user, passing the same sessionid in the querystring. This acts as a token to link one request to the other. I just need to wait now and find out if the other party are willing to work using two requests.
I also looked in to using an additional page that I could redirect the user to which could contain Javascript to perform an additional form post to the other server with a form that would contain just a single field containing the xml fragment, but this was excluded as a possibility by my boss (rightly so as it seems like a bit of a hack).
Are there any obvious or non-obvious drawbacks to my proposed method, other than the obvious possibility of a race condition between the 2 requests?
You could redirect to http://otherServer/handlerPage.aspx?xmlSource=http%3A%2F%2FfirstServer%2FxmlSource.aspx%3FparameterForXml1%3Dfoo%26parameterForXml2%3Dbar
Then at http://otherServer/handlerPage.aspx the xmlSource parameter is http://firstServer/xmlSource.aspx?parameterForXml1=foo¶meterForXml2=bar which can be used to obtain the XML.
Related
When a user has completed a form the user is redirected to the thank you page. The thank you page shall render it's view, but also download a file (pdf / a stream).
I would prefer to do this without using javascript like this
return both a file and a rendered view in an MVC3 Controller action and I would prefer to get the Save As dialog.
Has MVC any conventions that can handle this?
As #BenRobinson pointed out, you can't return two responses from a single request. No, MVC doesn't have any conventions to handle this because it's a fundamental limitation of the platform you're developing on, the Internet, and specifically the TCP/IP and HTTP protocols.
Fundamentally, the web revolves around what's called the request-response cycle. A client (usually a web browser) issues a request to a server, and that server responds with the requested resource. What you're talking about would be akin to request-response-response, which is not possible. The server cannot just up and send a response to a client without first receiving a request.
As a result, your options are:
Use JavaScript to programmatically issue another request, such as by setting location.href as the accepted answer on your linked question suggests.
Provide a link/button/whatever to allow the user to initiate a request for the file manually.
That's it. Either way, you need a new request, either initiated by JavaScript or the end user to get the file.
Did you tried meta refresh Trick.
<META HTTP-EQUIV='REFRESH' CONTENT='5;URL=http://www.example.com/test.txt'>
Remember to set the header Content-Disposition: attachment for the file that you want to download in browser.
Recently I've made an application in which I've made a stupid mistake by hard cording the url I want to post data to instead of using a proxy such as no-ip.
In short words, this app is sending requests regularly to my site which ended up in consuming lots of resources to my site. The request are sent to a PHP page which doesn't exist on my site:
http://www.example.com/non-existing-page.php
I suspect that it's impossible to prevent the distributed app from sending requests to my site without changing the url of my website.
The thing is that I cannot change the url and transfer my site to different URL, So what I need to know now is what should I do in order to make this stupid mistake less resource consuming.
1- Keep things as it is
or
2- Creating a blank php with the name of the called script..
Here is the short question:
When I call a page on a remote server through WebClient, which thing consume more server resources, calling a blank php page or calling an inexisting php page..
Thanks in advance
In a general broad sense whether the 404 page will be displayed or not depends on the browser.
IE doesn't show a custom 404 page unless it's larger than 512 bytes.
See here
Same deal with chrome too.
If you do want to put a custom 404 page make sure you include a favicon in it. Otherwise it leads to really long loading times. Discussed at length here
I have a ActionResult in Asp.net mvc website. it's read a lot of data when request made and show them on page.
Now I thing their is a problem. If the person make ajax request using Firebug and make loop of the request then my server got enough workload.
What I means is suppose I write a loop and make 1000 Fake ajax request then my server have run 1000 time sql queries and all the workload is useless.
how i can track it. Do someone have any help regarding this.
MVC's Anti-Forgery Token support writes a unique value to an HTTP-only cookie and then the same value is written to the form. When the page is submitted, an error is raised if the cookie value doesn't match the form value.
It's important to note that the feature prevents cross site request forgeries. That is, a form from another site that posts to your site in an attempt to submit hidden content using an authenticated user's credentials. The attack involves tricking the logged in user into submitting a form.
The feature doesn't prevent any other type of data forgery or tampering based attacks.
To use it, decorate the action method or controller with the ValidateAntiForgeryToken attribute.
I found that information from question answered by Richard Szalay :
ValidateAntiForgeryToken purpose, explanation and example
For blocking multiple requests from same Ip/ DDOS, please check the question's answers:
How to block multiple requests coming from same IP
I am wondering if it is possible to send POST data with the default browser of a computer in C#.
Here is the situation. My client would like the ability to have their C# application open their browser and send client information to a webform. This webform would be behind a login screen. The assumption from the application side is that once the client data is sent to the login screen, the login screen would pass that information onto the webform to prepopulate it. This would be done over HTTPS and the client would like this to be done with a POST and not a GET as client information would be sent as plain text.
I have found some wonderful solutions that do POSTS and handle the requests. As an example
http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx
So the TL;DR version of this would be
1) Open Browser
2) Open some URL with POST data
Thanks for your help,
Paul
I've handled a similar situation once by generating an HTML page on the fly with a form setup with hidden values for everything. There was a bit of Javascript on the page so that when it loaded, it would submit the form, therefore posting the data as necessary.
I suspect this method would work for you.
Generate a dictionary of fields and values
Generate an HTML page with the Javascript to automatically submit when page is loaded
Write page to a temp location on disk
Launch default browser with that page
Remember though that POST data is sent plaintext as well. POST is generally the way to go for more than a couple fields, as you can fit in more data (2048 byte limit on URLs) and that your user has a friendly URL to see in their browser.
Nothing is sent as plain text when you use SSL, it is encrypted. Unless you set what the default browser is (IE, Firefox, Chrome, etc), then you'll have to figure out what the default browser is and use its API to do this work (if it's possible).
What would probably be must faster and more efficient would be to open the default browser by invoking a URL with Start Process and pass the information on the query string (this is doing a GET instead of a POST, which I know isn't what you're asking for).
The response from the server could be a redirect, and the redirect could send down the filled-out form (storing the values in session or something similar).
That way the complexity is pushed to the website and not the windows application, which should be easier to update if something goes wrong.
HTH
Can you compile your logic in C# and then call it from PowerShell? From PowerShell you can very easily automate Internet Explorer. This is IE only but you might be able to also use WaitnN.
Anything you put at the end of the URL counts as the querystring, which is what GET fills. It is more visible than the POSTed data in the body, but no more secure with regard to a sniffer.
So, in short, no.
I want to write a custom HTTP Handler in ASP.Net (I'm using C# currently) that filters all requests to, say, .aspx files, and then, depending on the page name that comes with the requests, I redirect the user to a page.
So far, I've written a handler that filter "*", that is, everything. Let's say I receive a request for "Page.aspx", and want to send the user to "AnotherPage.aspx". So I call Redirect on that response and pass "AnotherPage.aspx" as the new page. The problem is that this will once more trigger my handler, which will do nothing. This will leave the user without any response.
So, is there a way to send the request to the other handlers (cascade the message) once I've dealt with it?
Thanks,
Bruno
Page.PreviousPage or Page.IsCrossPagePostBack should let you know.
Since Mark hasn't provided a full anwer containing the advice on MVC, here it goes what I learned:
ASP.Net MVC can do that. In fact, ASP.Net MVC was designed for that purpose: with MVC you can map different sub-links in your website to the same Controller, which will then process the request and send a view (page) back to the user. This technique is called Url Routing and is explained in ScottGu's blog quite well.
Scott's also have other articles describing MVC, which are worth checking out.