简体   繁体   中英

ASP.NET MVC Preserve Post Data After Authorize

I have an action handling a form post, but I want to make sure they are authenticated before the action. The problem is that the post data is lost because they user is redirected to the login page, and then back.

    [AcceptVerbs(HttpVerbs.Post)]
    [Authorize]
    public ActionResult AskQuestion(string question)
    {
       ....
    }

Any ideas?

Cheers

A POST is usually used for an add, update, or delete of data. By the time the user is doing this, if authentication is needed, you should have already authenticated them. So I would suggest that you change the flow of your app to authenticate before the POST.

You need to serialize your form values and a RedirectUrl to a hidden field.

After authentication deserialize the data in your hidden field and redirect based on the value of the RedirectUrl.

You will need a custom Authorize class to handle this.

您还可以使用会话保存信息......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM