且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是显示在ASP.NET中的随机图像的***方式?

更新时间:2023-02-16 11:02:57

您提到不使用随机的一组图片的网站。他们是coded到aspx页面的HTML端。

The site you mentioned is not using a random set of images. They are coded into the html side of the aspx page.

您可以将网页上的ASP Image控件。然后在该页面的Page_Load中函数图像设置为您一套随机的图片。

You could place an asp Image control on your page. Then on the page's Page_Load function set the image to a random picture of your set.

protected void Page_Load(object sender, EventArgs e)
        {

            this.Image1.ImageUrl = "~/images/random3.jpg";
        }

您在哪里存储图像数据集不同的选择。你可以使用一个数据库和网址存储在表中。这将允许使用内置的随机在SQL中的函数。或者你也可以保存一个XML文件到服务器,加载然后用随机.NET类来接你的XML节点之一。

You have different options on where to store the image set data. You could use a database and store the urls in a table. This would allow to use the built-in Random function found in SQL. Or you can save a XML file to the server, load that then use the Random .Net class to pick one of your xml nodes.

我个人建议的数据库解决方案。

Personally i would recommend the Database solution.

编辑:由于服务器会话20分钟后销毁你可能想看看使用cookie,所以你可以看到他们最后看到的随机图像

Because the server session is destroyed after 20mins you may want to look at using cookies so you can see the last random image they saw.