A special text on a web site
Assume that there is a web site which includes 3 different pages.
I want to show a text one of the pages randomly, with is formatted with css.
For instance the pages are below:
hello-world.aspx
hi-sun.aspx
good-night-moon.aspx
* When John enters to the site, the text will appear on hi-sun.aspx,
* When Elmander enters to the site, the text will appear on hello-world.aspx
And when one enters the page which includes a special text, even if come again, it shouldn't appear.
Psedue Code:
if(Session["first"] == "1")
{
//show the text in a random page
}
else
{
//text.visible = false
}
in the if block how can I supply the text开发者_JS百科 in a random page. (it shouldn't appear in every page, should appear only one page)
How can I do? Are there any suggestions?
Thank you.I don't fully understand what you want to do, but I think it's something like this:
You have a couple of different sites (3), and you have a text (welcome or something) you only want to show once. But after typing in your url the user should see one of the sites randomly.
For the first (if you don't want the user to log in) you can either save some flag in the Session object or create a cookie for the user (saying he has seen the text) and check this every time you want to show it. The session will on the server but will be lost so the user might see the same message later again if he revisits your site. But while staying he will see it only once. The second is on the client. If he accepts the cookie he will never see the message again if not he might see it everytime because you cannot know. Maybe you want some combination of these both.
For the second you will have to send a redirect if you don't want to get fancy with a deep dive into System.Web.
In the case above you can just do:
if(Session["first"] == null)
{
Session["first"] = true;
//show the text in a random page
}
else
{
text.Visible = false
}
but note that the session will not stay forever for the current user.
精彩评论