您好,欢迎访问一九零五行业门户网

C#Web应用程序入门经典笔记(上册)

最近看了《beginning c# web applications wtith visual studio .net 》。感觉这本书在一些细节方面写的不错,特做笔记,为后来者提供一些或许有用的东东。今天先写出来一些,年前正确整理完。
当前日期:
lbll.text = datetime.now.tolongdatastring();
this.controls.add(lbl);
url:
hyperlink reg = new hyperlink();
reg.text = “register;
reg.navigateurl = context.request.applicationpath + “myfirst.aspx”;
判断用户授权:
context.user.identity.isauthenticated;
表格相关:
1.       新建一图片img
2.       img添加到cell
3.       cell添加到row
4.       row添加到table
5.       table添加到placeholder
table tb = new table(); tablerow row = new tablerow(); image img = new image(); img.imageurl = "images/winbook.gif"; img.imagealign = imagealign.middle; img.width = new unit(24, unittype.pixel); img.height = new unit(24, unittype.pixel); cell = new tablecell(); cell.controls.add(img); row.cells.add(cell); hyperlink lnk = new hyperlink(); lnk.text = "news"; lnk.navigateurl = "news.aspx"; row.cells.add(cell); tb.rows.add(row); phnav.controls.add(tb);
将已验证身份的用户重定向回最初请求的url
public static void redirectfromloginpage(string username,bool createpersistentcookie);
参数
username
用于 cookie 身份验证的用户名称。这不需要映射到帐户名称,并将由 url 身份验证使用。
createpersistentcookie
指定是否应当发出持久性 cookie(跨浏览器会话保存的 cookie)。
标准数据库操作1
string sql; sqlcommand cmd; sqlconnection conn; sql = “insert into …”; conn = new sqlconnection (“data source = (local); initial catalog = caoxicao;userid = sa”); cmd = new sqlcommand (sql,conn); conn.open(); cmd.executenonquery();
标准数据库操作2
sqlconnection conn; sqlcommand cmd; sqldatareader reader; string sql; sql = “select * from tablename”; conn = new sqlconnection (“data source = (local); initial catalog = caoxicao;userid = sa”) cmd = new sqlcommand(sql,conn); conn.open(); reader = cmd.executereader();
可以用reader的read()方法判断是否真的返回了值
if (reader.read()) ...{ this.email.text = reader[“email”].tostring(); } dataset 基本操作 dataset dscaoxicao; string sql; sqlconnection conn; sqldataadapter adplaces; conn = new sqlconnection (“data source = (local); initial catalog = caoxicao;userid = sa”) adplaces = new sqldataadapter(sql,conn); dscaoxicao = new dataset(); conn.open(); adplaces.fill(dscaoxicao,”places”);
以上就是c#web应用程序入门经典笔记(上册)的详细内容。
其它类似信息

推荐信息