替代MVC2中的隐藏字段 [英] Alternatives to hidden fields in MVC2

查看:86
本文介绍了替代MVC2中的隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含的填充被传递到局部视图之前的字符串视图模型。我需要能够获得的数据传回当窗体发布。目前,我创建了一个隐藏字段,并绑定该数据给它。然后回发时,我可以从表单收集的数据。

I have a viewModel that contains a string that is populated before being passed to a partial view. I need to be able to get the data back when the form is posted. At the moment I have created a hidden field and bound the data to it. Then when posting back I can get the data from the form collection.

这不正是我想。我想preFER的数据将完全从视图中隐藏。使用会话不是真正的框架,我要坚持的一个选项。

This isn't exactly what I would like. I would prefer for the data to be entirely hidden from view. Using sessions aren't really an option for the framework I have to adhere to.

有没有替代的,我可以用?

Is there any alternative I can use?

感谢

推荐答案

澄清的一点是需要在这里:是最重要的事情是,数据不是的可见的用户,或者说,它是不是的访问的?

A bit of clarification is needed here: is the important thing that the data is not visible to the user, or that it is not accessible?

无形的,你可以将数据存储在cookie而不是隐藏字段。当你读它在服务器上,你也标志着该cookie为过期。这是一个黑客位,但它会做你问的是什么 - 在客户端而不是在标记存储数据。

If you want to make it invisible, you could store the data in a cookie instead of a hidden field. When you read it on the server, you also mark the cookie as expired. It's a bit of a hack, but it will do what you ask for - store data on client side but not in the markup.

如果你想它的无法访问的,你既可以混淆它(哈希或加密,例如),仍然将其存储在隐藏字段(或饼干,如上),但知道既然你还是给用户的信息的某一部分,它也不是完全不可能的访问数据。

If you want to make it inaccessible, you could either obfuscate it (hash or encrypt it, for example) and still store it in a hidden field (or cookie, as above), but knowing that since you still give the user some part of the information, it is not entirely impossible to access the data.

如果重要的是存储数据,用户不能以任何方式,访问它,但你不能这样做,在服务器端,你的运气了。任何你发送给客户端,一个足够聪明的用户都可以阅读。

If the important thing is to store data where the user cannot, in any way, access it, but you're unable to do so on the server side, you're out of luck. Anything you send to the client, a smart enough user can read.

这篇关于替代MVC2中的隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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