一个小但烦人的问题 - 为什么 ASP.Net 将 SQL Server Guid 设置为小写?
我正在使用 Javascript/JQuery 和 .Net 控件做一些客户端工作,这些控件在前端公开它们的 GUID/UniqueIdentifier ID,以允许对它们进行操作。在调试过程中,有些事情让我发疯:数据库中的 GUID 以大写形式存储,但是当它们到达前端时,它们就以小写形式存储。
这意味着我无法快速将 ID 复制并粘贴到浏览器的控制台中,以便在开发/调试时动态执行 JS。我找到了一种几乎可行的方法来做到这一点,但我想知道是否有人知道为什么会出现这种行为,以及是否有任何方法可以强制 GUID 保持大写。
I'm doing some client-side stuff with Javascript/JQuery with .Net controls which expose their GUID/UniqueIdentifier IDs on the front end to allow them to be manipulated. During debugging something is driving me crazy: The GUIDs in the db are stored in uppercase, however by the time they make it to the front end they're in lowercase.
This means I can't quickly copy and paste IDs into the browser's console to execute JS on the fly when devving/debugging. I have found a just-about-workable way of doing this but I was wondering if anyone knew why this behaviour is the case and whether there is any way of forcing GUIDs to stay uppercase.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 MSDN 文档 Guid.ToString() 方法将产生小写细绳。
至于为什么这样做 - 显然 RFC 4122 指出应该是这样。
另请检查此问题 - net-guid-uppercase-string-format。
因此,您可以做的最好的事情是在 GUID 字符串上调用 ToUpper() ,并添加扩展方法,如其他答案中所示。
According to MSDN docs the Guid.ToString() method will produce lowercase string.
As to why it does that - apparently RFC 4122 states it should be this way.
Also check this question on SO - net-guid-uppercase-string-format.
So the best thing you can do is to call ToUpper() on your GUID strings, and add extension method as showed in the other answer.
如果您使用 Eval 模板,那么我会看看您是否可以通过扩展方法来执行此操作。
类似于
然后在您的 Eval 块中,
或者您需要它的外观。
我现在在我的 Mac 上,所以我无法测试它,但如果你有正确的 .Net 版本,它应该可以工作。
If you're using an Eval template, then I'd see if you can do this via an Extension method.
something like
And then in your Eval block,
Or however you need it to look.
I'm on my Mac at the moment so I can't test that, but it should work if you've got the right .Net version.