开发者

What kind of encoding is neccessary for cookies?

开发者 https://www.devze.com 2023-01-25 09:36 出处:网络
For cookie what kind of encoding should be performed (converting a byte array to t开发者_如何学Cext) ?

For cookie what kind of encoding should be performed (converting a byte array to t开发者_如何学Cext) ?

Base64 ?
UrlEncode ?
...


You don't need any encoding. To prevent user tampering, the simplest solution is to use sessions (which typically uses ASP.NET_SessionId behind the scenes), rather than making custom cookies.

EDIT: If you really need to store an arbitrary byte array, base 64 will work. But you should explain why you want to do this.


I personally will MD5 encode an ID and store just about everything in a DB or if i can change the db use a GUID instead of a incrementing ID


Base64-encoded strings are not valid for URLs or cookies. There are a number of variations on base64 encoding that avoid the forbidden characters. In .NET, you can use HttpServerUtility.UrlTokenEncode() and .UrlTokenDecode().

See https://stackoverflow.com/a/1789179/24315

0

精彩评论

暂无评论...
验证码 换一张
取 消