Reading PUT HTTP method from Page object - asp.net

I have a System.Web.UI.Page page which receive both POST and PUT HTTP requests.
Reading a POST data through the Request.Form field is fine.
But how can i get PUT data? Request.Form field is empty.
Is there a way to access the raw request? or better: The PUT data?

I found the solution,
I was not using the good Field as Put data are contained in the body.
To access put data use:
Request.InputStream;

Related

How to get url data of form using post method

In wordpress, I'm using a template, which is used to store url data from sender page in database. This task is completed well when I use GET method for submitting the form, but when I use POST, then the whole $_POST array is empty in my template. What is the reason for that and how can I solve it?

Previous page title in asp.net

I am trying to get previous page title in my asp.net application.
My attempt :
string previousPageTitle = this.Page.PreviousPage.Title;
I am getting "NullReferenceException" as Object reference not set to an instance of an object.
I do not want to use session or query string to get previous page title.
See this SO question.
Is the reference to this.Page returning null? You could try accessing it through the HttpContext object:
((Page)HttpContext.Current.Handler).PreviousPage.Title
I believe you are going to the page directly, thus resulting in PreviousPage being null.
See Page.PreviousPage property
When you use the Transfer method or use cross-page posting to transfer
processing from one ASP.NET page to another, the originating page
contains request information that might be required for the
destination page. You can use the PreviousPage property to access that
information. If the current page is being rendered as a result of a
direct request (not a transfer or cross-post from another page), the
PreviousPage property contains null.

using WebMethod to read cookie but no Request.Cookies collection

I am trying to read cookie without post back. I used WebMethod to save the cookie, but cannot find way to retrieve it. For some reason, I cannot find Request.Cookies collection so that I can retrieve the value of it. Any help will be appreciated!
use this in your web method
HttpContext.Current.Request.Cookies

Is there a way to return a value in the Response?

The problem is I redirect to a sub page from the main page by passing a few values in Request.
I need to get back the value I got from manipulating values I sent in request and I don't need to store value in Session.
You can use the PreviousPage property, depending on how you got to the new page.
There are a number of things you can do:
Page.Request["ID_Of_Control_You_Are_Interested_In"] will get you a value that you need.
If you Server.Transfer to the page you can call Context.Handler, cast it to the page you come from and traverse the controls collection to get your value.... (similar to PreviousPage property)
You can also inspect the Query string parameters sent in the request too:
Page.Request.QueryString("Param_To_Inspect")
you can return your values as JSON as the response and then using a jquery to get the data
You have three options: Query String Parameters, Cookies and Session State
Query String Parameters: http://www.aspnet101.com/2007/11/using-the-querystringparameter/
This is a good way to pass data between pages. It's the most commonly used and is limited to the max length of the url.
Cookies : http://msdn.microsoft.com/en-us/library/ms178194.aspx
This is a good method. It also has a size limitation. The advantage of cookies is you can persist data that can span visits to your site.
Session State : http://msdn.microsoft.com/en-us/library/ms178581.aspx
This an ok method, I'd use the two methods above before I would use session state. In my experience you can get into trouble very fast with Session state.
To answer your question: You can take the value from the request and load it into a TextBox. Then on the web page, the user edits the value and clicks a save button, which posts the changed value back to the server.
Or you could use javascript to post the value back to the server.

Custom HttpHandlers and different handler types

All literature I see on creating custom handlers deals with associating an extension with a handler, e.g. if I wanted a handler for Ajax requests, I could implement the IHttpHandler interface in an AjaxHandler class.
Now, to have individual instances of AjaxHandlers, e.g. DocAjaxHander, PersonAjaxHandler etc. how would I derive the base AJAX handling of my AjaxHandler class without registering each individual *.ajax page?
It sounds like your assuming 1 HttpHandler = 1 Page or 1 Control, but as I understand, 1 HttpHandler can handle all pages of a certain file extension.
Your Question is not very clear, and your reponse to another answerer makes no sense...
"In fact, it seemed, to me, a lot like I was asking Http handlers, using a .ajax handler as an example."
But I shall assume you are thinking "DocAjaxHander" and "PersonAjaxHandler" should each be created for a "DocAjaxControl" and "PersonAjaxControl" respectively. I dont think that would be neccesary, 1 handler should be able to handle all your ajax requests if you choose to do it that way, but it doesn't feel like the most intuitive solution to me (using HttpHandlers), anyway, onto the details...
every IHttpHandler object needs to implement :
public void ProcessRequest(HttpContext context)
which allows :
context.Response.Write("Your JSON Response in here");
but at the level of 'ProcessRequest()', you have no access to the instance of the control which created the ajax call, or to the 'System.Web.UI.Page' object that holds the control, or anything.
context.Request
to the rescue! With the Request object above you can read QueryStrings, Sessions, an you can determine the path of the original HttpRequest (i.e. PersonAjaxObject may make an ajax call to 'myPersonobjPage.ajax' for its JSON data, but the '.ajax' extention lands the request at your custom http handler and it's ProcessRequest method.)
If I was you, and I was going to use an HttpHandler for my ajax calls, I'd use query string data to provide enough info for my handler to know 'what type of object am I responding too' as well as 'what data is that object requesting'.
Hope that helps.
You can automatically handle AJAX request in a number of ways. Here's how to do it with a web service:
http://www.asp.net/AJAX/Documentation/Live/Tutorials/ConsumingWebServicesWithAJAXTutorial.aspx
Well, one way to do it would be via query string params...

Resources