如何在asp.net中提取cookie中的特定信息
我是一个初学者,正在使用 Visual Studio 2008 在 asp.net 平台上构建网站。我创建了一个基本的登录系统。现在我使用 cookie 来存储用户名,以便我可以使用它来访问相应的数据库。
例如。用户名 abc 登录。它被重定向到个人资料页面。现在我想在列表视图中显示他的个人资料详细信息,但无法做到。所以我想到使用存储在cookie中的用户名来填充SQL WHERE条件来搜索该人的表详细信息并将其填充到LIST VIEW中。
那么如何获取cookie信息呢?正如我所尝试的,但我立即访问它的所有信息,例如“2011年5月9日12:22:20 uid=abc”
如果有另一种方式在登录后显示特定注册用户的信息,请帮助我出去。
感谢U。
I am a beginner and working on building websites on asp.net platform in visual studio 2008. I have created a basic login system. Now I used cookie to store username in it so that I can use it to access the respective database.
For example. a person with username abc logins. It is redirected to profile page. Now here I want to show his profile details in a list view but could not do. So I thought to use username stored in the cookie to fill the SQL WHERE condition to search the table details of that person and fill it in the LIST VIEW.
So how can I get the cookie information. As I have tried but I access all the information of it at once like "9 may 2011 12:22:20 uid=abc"
If there is another way of showing the information of a particular registered user after he log in then please help me out.
Thanks to U.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答您的字面问题:
请记住,客户可以根据自己的喜好设置 cookie,因此这不是很安全。一个简单的解决方法是让 ASP.NET 处理 cookie 详细信息。如果您在 Session 上设置一个变量,例如:
ASP.NET 将向客户端发送一个“会话 id”cookie,这是安全的。用户无法更改他的用户名:它仅存储在服务器上。
To answer your literal question:
Remember that the customer can set his cookie as he likes, so this isn't very secure. An easy fix is to let ASP.NET handle the cookie details. If you set a variable on the Sesssion, like:
ASP.NET will send a "session id" cookie to the client, which is secure. And the user can't change his UserName: it's stored on the server only.
Session["UserName"].ToString() 应该给你 Ani :)
Session["UserName"].ToString() should give you Ani :)