将字符串值转换回 GUID 值
我有一个 guid 值,存储在隐藏变量中。 例如 (303427ca-2a5c-df11-a391-005056b73dd7)
现在我如何将这个隐藏字段的值转换回 GUID 值(因为我要调用的方法需要 GUID 值)。
谢谢。
i have a guid value that i store in my hidden variable.
say for eg (303427ca-2a5c-df11-a391-005056b73dd7)
now how do i convert the value from this hidden field back to GUID value (because the method i would be calling expects a GUID value).
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只需使用重载的构造函数:
Just use the overloaded constructor:
通过将 Guid 存储在字符串中,可以让攻击者变得非常容易。比如说,在分页文件中查找起来很简单。将其存放在Guid中,并用一石杀死两只鸟。
You are making it pretty easy on an attacker by storing the Guid in a string. Trivial to find back in, say, the paging file. Store it in a Guid and kill two birds with one stone.
有关详细信息,MSDN
For more info, MSDN
Guid 有一个字符串 Guid 的构造函数。
Guid has a constructor for string Guids.
新的 Guid(myHiddenFieldString)
new Guid(myHiddenFieldString)
我认为可以简单地按如下方式完成:
I think it can be done simply as following:
在 .NET4 及以上版本中,您还可以使用:
只是编码偏好的问题,但有些人发现这更直观。
In .NET4 onwards you can also use:
Just a matter of coding preference, but some people find this more intuitive.