Home > Backend Development > C#.Net Tutorial > Introduction to C# Web Applications Classic Notes (Volume 1)

Introduction to C# Web Applications Classic Notes (Volume 1)

Y2J
Release: 2017-04-26 10:45:23
Original
1466 people have browsed it

I recently read "Beginning C# Web Applications Wtith Visual Studio .Net". I feel that this book is well written in some details, so I took notes to provide some things that may be useful to those who come after me. I’ll write some down today and finish them correctly before the year.

Current date:

Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;

Determine user authorization:

Context.User.Identity.IsAuthenticated;

Form related:

1. Create a new image img
2. Add img to cell
3. Add cell to row
4. Row added to Table
5. Table added to 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);
Copy after login

Redirect authenticated users back to the originally requested URL

public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
Copy after login

Parameters
userName
User name used for cookie authentication. This does not need to be mapped to an account name and will be used by URL authentication
createPersistentCookie
Specifies whether persistent cookies should be issued (cross-browsing). Cookie saved by the server session)

Standard database operation 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();
Copy after login

Standard database operation 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();
Copy after login

Can be judged by the reader's Read() method. Whether the value is really returned

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”);
Copy after login

The above is the detailed content of Introduction to C# Web Applications Classic Notes (Volume 1). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template