您的位置:首页 > 其它

.net学习笔记(一)

2015-11-26 20:52 253 查看
B/S架构(Browser/Server(浏览器/服务器)结构)从浏览器到Server端的指令用Response.XXX,反过来用Request.XXX

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里面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: