zoukankan      html  css  js  c++  java
  • aspx工作原理 天高地厚

    asp.net是什么?

    asp.net是一种动态网页技术,在服务器端运行.net代码,动态生成HTML,可以使用javascript,DOM在浏览器端完成很多工作,但是很多工作无法在浏览器端完成,比如:存储数据,访问数据库,复杂的业务逻辑运算,安全性较高的逻辑运算等等

    webApplication(web应用程序)和webSite(网站)的区别:
    website是为了兼容从ASP转过来的开发人员的习惯而存在的,用起来简单,比如不需要创建命名空间,CS代码修改后不需要重启就能看到变化(无论是website还是webApplication,修改aspx都不需要重启),但是不利于工程化开发,比如代码出错不易发现,代码不分命名空间,开发技术上没有任何区别,只是开发,调试习惯不同而已。

    aspx的工作原理:
    客户端向服务器发出请求,提交数据到服务器的处理程序,服务器的处理程序经过处理后把返回的结果发回客户端,是一个“请求-响应”的过程。

    在客户端使用表单提交请求到服务器处理程序:
    <form action="hello1.ashx">
    姓名:<input type="text" name="userName" /><input type="submit" value="提交" />//一定要指定name属性
    </form>
    在服务器端处理客户端的请求:
    public class hello1 : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "text/html";
    string userName = context.Request["userName"];
    context.Response.Write(@"<form action='hello1.ashx'>
    姓名:<input type='text' name='userName' value='" + userName + @"'/><input type='submit' value='提交' />
    </form>");
    context.Response.Write("Hello World");
    context.Response.Write(userName);
    }

    public bool IsReusable {
    get {
    return false;
    }
    }

    }

    使用模板时:
    在客户端使用表单提交请求到服务器处理程序:
    <form action="hello2.ashx">
    <input type="hidden" name="ispostback" value="ture"/>
    姓名:<input type="text" name="userName" value="@value" /><input type="submit" value="提交" />
    @msg

    在服务器端处理客户端的请求:

    public class hello2 : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "text/plain";
    string username = context.Request["userName"];
    string msg = "";
    string ispostback = context.Request["ispostback"];
    if (ispostback=="ture")
    {
    context.Response.Write("提交打开");
    msg =username +"您好";
    }
    else
    {
    context .Response .Write ("直接打开");
    username = "";
    msg ="";
    }
    string fullpath = context.Server.MapPath("hello2.htm");
    string content = System.IO.File.ReadAllText(fullpath);
    content = content.Replace("@value", username);
    content = content.Replace("@msg", msg);
    context.Response.Write(content);
    }

    public bool IsReusable {
    get {
    return false;
    }
    }

    }

  • 相关阅读:
    android部分控件应用解析
    CodeForces Round #179 (295A)
    面试题27:连续子数组的最大和
    java写文件时,输出不完整的原因以及解决方法
    序列化和反序列化--转
    Java多线程编程那些事:volatile解惑--转
    转变--一个平凡人的2017年总结及2018年展望
    系列文章--批处理学习
    set命令
    bat计算两个时间差
  • 原文地址:https://www.cnblogs.com/net2012/p/2875174.html
Copyright © 2011-2022 走看看