asp.net 生成验证码两个例子
#region 1
private void CreateCheckCodeImage()
{
//获取随即字符串
int number;
char code;
string checkCode = String.Empty;
System.Random random1 = new Random();
for (int i = 0; i < 5; i++)
{
number = random1.Next();
if (number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));
checkCode += code.ToString();
}
//画图
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 13.0)), 24);
Graphics g = Graphics.fromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = 0; i < 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Gray), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Verdana", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 2);
//画图片的前景噪音点
for (int i = 0; i < 80; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.fromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Colo
相关文档:
(1)asp.net 实现n秒后页面自动跳转
1.
<script type="text/javascript" language="javascript">
function reloadyemian()
{
window.location.href = "javascript:history.go(-1)";
}
window.setTimeout("reloadyemian();",5000);
</script> ......
//平常调用javascript方法
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert'Weclome!!!');</script>");
背景不为白色的方法:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加失败,请联系技术员!') ......
在ASP.NET2.0中,为我们提供了两种新功能,方便我们制作共同特征一致的页面和导航。这两种功能是母板页和网站导航。对于母板页大家很清楚了,不过在做母板页时,经常需要添加导航栏,对于此asp.net 2.0 使我们的工作大为简化。这便是站点地图的使用。
顾名思义,站点地图就是在站点 ......
1.获取图片宽度和高度
1.您可以使用 System.Drawing.Image 类
System.Drawing.Image img = System.Drawing.Image.fromFile(Server.MapPath("example.gif"));
int width = img.Width;
int height = img.Height;
img.Dispose();
但是这里我们却不能在导入名称空间后使用 Image& ......