When to use GET and when POST. I want to hide my query string on code like :
protected void LinkButton1_Click(object sender, EventArgs e)
I don't want to show Create word in query string . What i have to do. And how to implement
the Post/Redirect/Get pattern .Please send me code for this if possible.
Thanks for reading. please help I m too confuse
GET is intended for retrieval of a resource without making any modifications or incurring any side effects, and
POST is intended for adding information to a resource (but not creating a new resource, that would be a
PUT). These are just guidelines and are not functionally enforced; you can use a
POST request to retrieve a resource, and
GET requests can have side effects.
So, you could put the mode information into the body of a
POST request; you could also do something simpler and assign numerical values to your modes, such that you had
and only the server would know that mode 2 is "Create".
If you want to prevent the user from (easily) being able to modify the
mode value directly, then the
POST body would be a better solution than the query string.
GET HTTP method keeps its variables in its querystring. That's just the way it was designed. Hence, if you don't want variables in the query string and you would like to send these variables to the server then you would have to use something other than GET.
Now I am guessing that you're asking how do you remove the variables from the query string after a request but before a redirect?
See http://www.west-wind.com/weblog/posts/132081.aspx This page has a list of ASP.Net properties that expose various path and URL information.
So for example if you're doing a GET after POST, then it's assumed that you shouldn't really have querystring variables that you need to get rid of. And thereforee
can do the trick.
But Request.RawUrl would include a querystring if there was one. So, for access to a path without a querystring try 'Request.FilePath' or Request.CurrentExecutionFilePath with your Response.Redirect call at the end of your Postback handling.