什么是显示在ASP.NET中的随机图像的最佳方式? [英] What's the best way to show a random image in ASP.NET?

查看:122
本文介绍了什么是显示在ASP.NET中的随机图像的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说的是这样的网站:
http://www.ernesthemingwaycollection.com

What I am talking about is like this website : http://www.ernesthemingwaycollection.com

它有一个静态墙纸和一组图片,从页面切换到页面,我想实现从一组使用ASP.NET图像显示随机图像的方式类似。

It has a static wallpaper and a set of images that change from page to page, I want to implement a similar way of displaying random images from a set of images using ASP.NET.

修改:我想要的图像远离会话的会话一样的,换到别的

EDIT : I want the image to stay the same in a session, and change from a session to another.

推荐答案

您提到不使用随机的一组图片的网站。他们是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.

这篇关于什么是显示在ASP.NET中的随机图像的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆