Damir
Damir

Reputation: 56199

Redirect problem in ASP.NET

I have one question about redirecting in ASP.NET. I know how to redirect with Redirect function on other ASP.NET page and read parameters from URL from Request, but I don't want GET, I need POST, I am sending IDs over URL, so user doesn't need to see that. How to redirect with POST method and read parameters in ASP.NET ?

Upvotes: 3

Views: 430

Answers (4)

Sency
Sency

Reputation: 2878

you have to use sessions to transfer variables between two pages. if you are having multiple parameters, think about a Class with these parameters. you can keep an object in Session. So In the second page, check that specific session contains the specific object. otherwise, parameters are not specified.

In first page you can save your object in Session like this.

Session["yourSessionName"]=new Class1()
                               {
                                 variable1=...
                                 variable2=...
                               };

then

Response.Redirect("/yourSecoundPage.apsx");

In second page you can check it like this

    if (Session["yourSessionName"] is Class1)
    { 
         //Accept parameters 
    }
    else
         // Parameters not specified

Upvotes: 0

Guffa
Guffa

Reputation: 700262

It's not possible to make a POST request using a redirect. It would be possible by using Javascript in a redirection page, but that would make it less robust than a regular redirect.

Consider if a Server.Transfer would serve your purpose. It would not change the URL of the page in the browser, but it would keep the data that you send in the query string to leave the server.

Upvotes: 3

Brian Ball
Brian Ball

Reputation: 12596

A redirect, by definition, is a GET, you can't do a 301 or 302 redirect with a POST. If you are trying to prevent the user from seeing a value, then you can store that value in the session, then retrieve it after the redirect. Though I have found in the past that trying to protect something by not allowing the users to see it is not the best approach (security through obscurity). You should put other measures into place to protect users from doing something they shouldn't, even if they know the value.

Even if I'm wrong and it is possible that you can redirect with POST, then the value would need to be part of the redirect, and therefore the user does have a chance to learn about it if they are using something to monitor HTTP traffic.

Upvotes: 3

gbs
gbs

Reputation: 7266

You have several other ways and one of them is storing values in session. Also check this : Cross-Page-Posting

Upvotes: 1

Related Questions