'+newDate().getTime();returnfalse;"">看不清楚
-->
ButtonID="Button1"runat="server"Text="登陆"onclick="Button1_Click"/>
LabelID="Label1"runat="server">
Label>
Content>
登陆cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.OleDb;
publicpartialclasslogin:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!
Page.IsPostBack)
{
Label6.Text=CheckCode();
}
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
//首先验证用户输入的验证码?
if(CheckCodeTextBox.Text!
=Session["cc"].ToString())
{
Label8.Text="";
Label7.Text="验证码输入错误!
";
//重新生成验证码?
return;
}
else
{
Label8.Text="";
Label7.Text="验证通过";
stringUsername=UsernameTextBox.Text.ToString();
stringPassword=PasswordTextBox.Text.ToString();
stringyid;
using(OleDbConnectionconn=newOleDbConnection())
{
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=H:
\schoolwork\ASP.NET\大二下\陈历生第十一周\App_Data\weibo.mdb";
conn.Open();
using(OleDbCommandcmd=newOleDbCommand())
{
cmd.CommandText="selectyidfromyonghuwhereyonghu='"+Username+"'andPassword='"+Password+"'";
cmd.Connection=conn;
yid=cmd.ExecuteScalar()==null?
"":
cmd.ExecuteScalar().ToString();
//判断id没有情况下还回为空,有就还回cmd.ExecuteScalar().ToString();
}
}
if(yid==null||yid=="")
{
Label7.Text="";
Label8.Text="用户或密码错误!
请重新输入!
";
}
else
{
Session["yid"]=yid;
Session["yonghu"]=Username;
Label7.Text="";
Label8.Text="用户登录成功?
";
}
return;
}
}
//生成新的验证码
protectedstringCheckCode()
{
char[]ss={'a','b','c','d','e','f','0','1','g','h','i','j','k','l','m','n','v','z','f','s','p','u','y','t','r','3','4','5','6','7','8','9'};
Randomrnd=newRandom();
stringcc="";
for(inti=0;i<4;i++)
{
//cc+=rnd.Next(10);
//cc=cc+rnd.Next(10);
cc+=ss[rnd.Next(ss.Length)];
}
Session["cc"]=cc;
returncc;
}
protectedvoidLinkButton2_Click(objectsender,EventArgse)
{
//看不清点击重新生成验证码?
Label6.Text=CheckCode();
}
}
显示图片代码
imageWidth="30px"Height="30px"ID="touxiangimage"runat="server"imageurl='<%#Eval("touxiang")%>'/>
Web.config文件修改
xmlversion="1.0"?
>
--
有关如¨何配置ASP.NET应用程序¨的详细信息,请访问º
-->
浏览器上出现ICO图标
--浏览器上出现ICO图标-->
上传文件aspx
FileUploadID="FileUpload1"runat="server"/>
ButtonID="Button1"runat="server"Text="文件上传"onclick="Button1_Click"/>
LabelID="Label2"runat="server"Text="Labe2">
Label>
上传文件cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
publicpartialclass_Default:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
if(FileUpload1.HasFile)
{
stringfileName=FileUpload1.FileName;
//定义上传文件的扩展名
stringfileExtent=System.IO.Path.GetExtension(fileName);
//重新命名文件
fileName=DateTime.Now.ToString("yyyyMMddhhmmss")+fileExtent;
stringfx=".jpg,.jpeg,.gif,.bmp,.png";
if(fx.IndexOf(fileExtent)==-1)
{
Label2.Text="你上传的不是图片文件";
return;
}
//限制图片大小
intfileSize=FileUpload1.PostedFile.ContentLength;
if(fileSize>102400)
{
Label2.Text="图片文件太大,不能超过100KB";
return;
}
stringfilePath=Server.MapPath("up/");
FileUpload1.SaveAs(filePath+fileName);
//得到url的地址
stringstrurl=Request.Url.ToString();
stringstrFileDownloadPath=strurl.Substring(0,strurl.LastIndexOf('/'))+"/Upload/"+fileName;
Label2.Text=strFileDownloadPath;
}
}
}
展开阅读全文
相关搜索