如何隐藏使用后,重定向查询字符串参数,获取格局? [英] How can I hide query string parameters using the Post, Redirect, Get pattern?

查看:111
本文介绍了如何隐藏使用后,重定向查询字符串参数,获取格局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多步骤的数据输入表单在我的ASP.NET MVC应用程序。

I have a multi-step data entry form in my ASP.NET MVC application.

当的信息被发布时,输入值被检查,如果我确定一些相关的数据是必需的(例如,购买订单引用不存在的一个供应商)我重定向到另一个动作,使得用户可以输入额外数据。

When the information is posted, the input values are checked and if I determine that some related data is required (e.g. a purchase order references a supplier that does not exist) I redirect to another action so that the user can enter the extra data.

我不想要的网页,以便我传递这些使用一个ViewModel第二个动作方法之间丢失那些已经被用户输入的值。数据被包含在第二页上的隐藏的输入,使得用户不能看到它们。

I do not want the values that have already been entered by the user to be lost between pages so I am passing these to the second action method using a viewModel. The data is contained in hidden inputs on the second page so that the user can not see them.

这工作得很好,除了我结束了,看起来像这样的网址:

This works fine except I end up with a URL that looks something like this:

myDomain/RFQ/CreatePart?PartNumber=Skateboard&Supplier=Bobs%20skateboards&DateCreated=08%2F28%2F2012%2000%3A00%3A00&DateRequired=08%2F28%2F2012%2000%3A00%3A00&Quantities=1%2C%203%20%26%205%20off

myDomain/RFQ/CreatePart?PartNumber=Skateboard&Supplier=Bobs%20skateboards&DateCreated=08%2F28%2F2012%2000%3A00%3A00&DateRequired=08%2F28%2F2012%2000%3A00%3A00&Quantities=1%2C%203%20%26%205%20off

我试图简单地返回一个视图,而不是重定向这给我的网址如下:

I have tried simply returning a view instead of redirecting which gives me the URL Like this:

myDomain的/询价/ CreatePart

myDomain/RFQ/CreatePart

不过,这给我的用户能够通过刷新浏览器重新发布的价值观,我现在已经不再继后,重定向,获取模式的问题。

However, this gives me the problem of the user being able to repost the values by refreshing the browser as I am now no longer following the post, redirect, Get pattern.

有没有用正确的方式的后重定向-GET 的模式,同时保持清洁的网址?

Is there a way of properly using the Post-Redirect-Get pattern whilst maintaining the cleaner URL?

29日更新2012年9月

我调查的选项下面列出,并决定使用 SessionState会暂时,因为这让我来存储中间数据,直到用户完成他们的交易,而让我使用的重定向后获得的模式用干净的URL。

I investigated the options listed below and have decided on using SessionState for the time being as this allows me to store intermediate data until the user has finished their transaction whilst allowing me to use the post-redirect-get pattern with a clean URL.

我其实是知道的 SessionState会之前问这个问题,但遗憾的是一些信息我已经读到它使我相信这不是最好的解决办法(大多数文章援引表现不佳,但很少提供这种任何证据或解释原因)。

I was actually aware of SessionState prior to asking this question but unfortunately some of the information I had read about it had led me to believe this was not the best solution (most articles cite poor performance but rarely provide any evidence of this or explain why).

看了文章中,我现在明白了 SessionState会好多了。

Having read this article I now understand SessionState a lot better.

推荐答案

选项如下(顺序并不意味着好或坏)

Options are as follows (order does not imply better or worse)


  1. 添加值的TempData ,他们将一直持续到他们正在阅读该用户的下一个请求,然后自动清零。

  2. 保存中间步骤到数据库中。

  3. 保存中间步骤在缓存(如果数据的共享之间的用户)。

  4. 保存中间步骤的 SessionState会(如果数据是每 -user )。

  5. 谁在这种情况下关心,如果它是一个丑陋的中间网址?

  1. Add the values to TempData and they will be available until they are read on the next request by that user and then automatically cleared.
  2. Save the intermediate steps to the database.
  3. Save the intermediate steps In the Cache (if the data is shared amongst users).
  4. Save the intermediate steps to the SessionState (if the data is per-user).
  5. who cares in this case if it's an ugly intermediate URL?

这篇关于如何隐藏使用后,重定向查询字符串参数,获取格局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆