.net学习笔记(一)
2015-11-26 20:52
253 查看
B/S架构(Browser/Server(浏览器/服务器)结构)从浏览器到Server端的指令用Response.XXX,反过来用Request.XXX
Response.ContentType = "text/html";//当网页读取 Response.ContentType = "text/plain";//当文本读取
string content = System.IO.File.ReadAllText(context.Server.MapPath(@"~/HttpHandlerForLogin/Success.html"));//相对路径转化为物理路径,并读取文件
ConfigurationManager.AppSettings["uName"];//从web.config里面读取内容,.net连接数据库字符串一般存在web.config里面
context.Response.Write(@"<script type='text/javascript'>
alert('Please input correct pwd or username');location.href='Login.html'
</script>");
//context.Response.Write(Login);
//第二种页面跳转的方法通过客户端转向
// context.Response.Write(@"<script type='text/javascript'>location.href='Login.html'
// </script>");
//context.Response.Redirect("Login.html");Response.Redirect()转向会在客户端产生一次新的请求,这个重定向操作发生在客户端
/*连接sqlServer代码
*/
protected void Button1_Click(object sender, EventArgs e)
{
//虚拟路径
string path = Server.MapPath("~/App_Data/myDB1.mdf");
string conString=String.Format(@"Data Source=(LocalDB)\v11.0;AttachDbFilename={0};Integrated Security=True",path);
using (SqlConnection conn=new SqlConnection(conString))
{
conn.Open();
//Response.Write(conn.State);
SqlCommand comm = conn.CreateCommand();
comm.CommandType=CommandType.Text;
string newId = Guid.NewGuid().ToString();
comm.CommandText = "insert into[User](UserID,UserName,UserPassword) values('" + newId +
"','admin','12356')";
comm.ExecuteNonQuery();
}
}
.net连接数据库字符串一般存在web.config里面
ashx与aspx.cs区别//http://zhidao.baidu.com/link?url=zqswXtdo6ouq2zEpYrvFfQrqIBBXFGl9_rdI2mZ4IbctTm46ClTvT5G8BzEUkskD5Yds5Elhqw6pEwy6gVFKpdxgYd7ILRVMQYMcnJnzXX_
Response.ContentType = "text/html";//当网页读取 Response.ContentType = "text/plain";//当文本读取
string content = System.IO.File.ReadAllText(context.Server.MapPath(@"~/HttpHandlerForLogin/Success.html"));//相对路径转化为物理路径,并读取文件
ConfigurationManager.AppSettings["uName"];//从web.config里面读取内容,.net连接数据库字符串一般存在web.config里面
context.Response.Write(@"<script type='text/javascript'>
alert('Please input correct pwd or username');location.href='Login.html'
</script>");
//context.Response.Write(Login);
//第二种页面跳转的方法通过客户端转向
// context.Response.Write(@"<script type='text/javascript'>location.href='Login.html'
// </script>");
//context.Response.Redirect("Login.html");Response.Redirect()转向会在客户端产生一次新的请求,这个重定向操作发生在客户端
/*连接sqlServer代码
*/
protected void Button1_Click(object sender, EventArgs e)
{
//虚拟路径
string path = Server.MapPath("~/App_Data/myDB1.mdf");
string conString=String.Format(@"Data Source=(LocalDB)\v11.0;AttachDbFilename={0};Integrated Security=True",path);
using (SqlConnection conn=new SqlConnection(conString))
{
conn.Open();
//Response.Write(conn.State);
SqlCommand comm = conn.CreateCommand();
comm.CommandType=CommandType.Text;
string newId = Guid.NewGuid().ToString();
comm.CommandText = "insert into[User](UserID,UserName,UserPassword) values('" + newId +
"','admin','12356')";
comm.ExecuteNonQuery();
}
}
.net连接数据库字符串一般存在web.config里面
相关文章推荐
- 网络部分整理第二部分
- MySQL学习笔记(二)
- leetcode_Range Sum Query 2D - Immutable
- Smart原则
- 算法(三)粒子群算法之局部粒子
- 图像的直方图均衡化和比特平面分层
- oracle实现字符串截取,查找,替换
- 快速搭建一个成熟,强壮的App框架
- 一个页面跳转到另一个页面的导航的对应的标签下面
- Django POST CSRF verification failed. Request abor
- C#常用集合的使用
- HDOJ--2089--不要62
- hdoj Immediate Decodability 1305 (字典树判断前缀)
- 就在支付宝、美团把商家搞疯的时候 百度钱包干了件对的事!
- MySql,Trim函数使用
- HTTP协议之Content-Encoding
- perl 正则或匹配
- 进击的KFC:UI(十一)自定义Cell
- 用python简单处理图片(3):添加水印
- 实例变量可见度、方法、setter、getter