1

I have a text to be displayed to user only once per session i.e. only the first time they try to open a page. If they try to open again they are not supposed to see that text.

If they close the browser and open it again they should be able to see the text again. I wanted to use session, but I am not sure how to use it.

I tried to use cookie which worked, but what if cookie is disabled, I guess this wont work. so I decided to go with Sessions.

4

1 回答 1

3

定义OnSessionStart事件Global.asax...像这样...

 void Session_OnStart(object sender, EventArgs e) 
    {
       Session["showmessage"]="Show";
        }

pageLoad或您要检查的事件...检查会话...如果您想在标签中显示您的文本,请这样做...

 protected void Page_Load(object sender, EventArgs e)
    {
if(Session["showmessage"].ToString()=="Show")
{
Label1.Text="Message";//i Supposed you wana Show Message in Label.You Can Write your Code to Show Message wherever you wnat show.
Session["showmessage"]=Not Show";//To Display Message Only One Time.
}

注意-:每次会话过期时都会显示消息。

于 2013-06-10T04:43:47.680 回答