开发者

how to extract specific information in cookie in asp.net

开发者 https://www.devze.com 2023-03-03 16:42 出处:网络
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 acces

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开发者_Python百科 after he log in then please help me out.

Thanks to U.


To answer your literal question:

Response.Cookies("CookieName").Value

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:

Session["UserName"] = "Ani";

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() should give you Ani :)

0

精彩评论

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

关注公众号