不使用HTTPS并直接将表单提交到站点B的任何原因?
<form action="https://siteb/someaction" method="POST">
<input type="text" name="key1" value="value1" />
<input type="text" name="key2" value="value2" />
<input type="text" name="key3" value="value3" />
<input type="submit" value="Go ahead" />
</form>
如果有任何理由在您要加密的值到一个单一隐藏的输入并提交包含使用JavaScript这个隐藏字段形式的情况下,唯一的隐藏字段的值将被发送到网站B.因此,举例来说,如果你有以下形式:
<form action="http://siteb/someaction" method="POST">
<input type="hidden" name="encrypted" value="some encrypted value" />
</form>
在站点B,你会取这样的加密值(不使用的FormCollection,相比视图模型它有点丑陋):
[HttpPost]
public ActionResult SomeAction(string encrypted)
{
// TODO: decrypt the encrypted value here to get the orginal string
...
}
而且一个更优雅的方式将是对站点B和这种模式,会做解密的自定义模型绑定定义的视图模式,使动作看起来简直像这样:
[HttpPost]
public ActionResult SomeAction(SomeViewModel model)
{
// Directly use the model with all the fields in it.
// The custom model binder will take care of the creating it
// from the encrypted request string
...
}
数据如何被加密/解密?你真的需要提交数据客户端,因此重定向用户,或者你可以使用Web服务并将其称为服务器端? – roryf 2011-05-10 20:38:48
@ roryf使用非对称加密。它需要提交给一个网页,而不是一个web服务。 – 2011-05-10 20:40:51