做软件工程探索的C#网站架构方案-总结
来源:互联网 发布:死神觉醒辅助软件 编辑:程序博客网 时间:2024/05/16 12:46
1.没有MVC实现控制跳转(可用于权限管理)
注:大体就是每个页面继承这个类
public class BasePage : System.Web.UI.Page{ //pageunload事件,并不是指浏览器关闭,而是指页面关闭,所以刷新的时候,依然会执行以下事件 protected void Page_Unload(object sender, EventArgs e) { } public static Func<Object, string> isLogin = session => session as string ?? string.Empty; protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); //自己定义的session类 //也可以装一个对象 if (isLogin(Session["islogin"])!="yes") {//这里写 跳转到登陆页面:例如: //Response.Redirect("Default3.aspx"); //Response.Redirect(string.Format("~/ReLogin.aspx?Page={0}", Request.Path)); //Response.Redirect(string.Format("~/Default2.aspx?Page={0}", Request.Path)); Session["islogin"] = "yes"; Response.Redirect("Default.aspx"); } else { } } }
2.关于页面与后台ajax传参的总结。
html部分
<input type="button" size="12" value="练习1" onclick="a1()"/> <input type="button" size="12" value="练习2" onclick="a2()"/> <input type="button" size="12" value="练习3" onclick="a3()"/> <input type="button" size="12" value="练习4" onclick="a4()"/> <input type="button" size="12" value="练习5" onclick="a5()"/> <input type="button" size="12" value="练习6" onclick="a6()"/> <br /> <div id="dataShow"></div> <script type="text/javascript" > function a1() { //alert($("#form1").html()); $.ajax({ type: "Post", url: "Default2.aspx", // data: "{'token':'ajax'}",// 使用这种方式竟然无法传递参数,各位有知道原因的告诉一下啊。 //dataType为text或者html data: "token=ajax", success: function (data) { $("#dataShow").text(data); } }); } function a2() { $.ajax({ type: "Post", url: "Default2.aspx", // data: "{'token':'ajax'}",// 使用这种方式竟然无法传递参数,各位有知道原因的告诉一下啊。 data: "token=ajaxXml", // 不需要指定contentType,因为指定后返回的是整个页面的html,不知道为啥,请求解答啊。 dataType: "xml", success: function (data) { alert(data); }, error: function (d, c, e) { alert("err: "+d+ " "+c ); } }); } function a3() { $.ajax({ type: "Post", url: "Default2.aspx", // data: "{'token':'ajax'}",// data必须是一个{key:value}的形式,这是一个字符串,是不行的。 // data:{token:"ajax"},// 这种方式也可行。 data: "token=ajaxJson", /* 记录:如果直接请求一个页面,如果data使用"{'token':'ajax'}"这种字符串的形式,jquery是无法转换为token=ajax的形式 jquery 文档中说,可以使用{key:value}形式的data请求页面,此时jquery会自动添加contentType=“application/x-www-form-urlencode”,使传入的data自动转换为key=value的形式。 */ // 不需要指定contentType,因为jquery会自动添加contentType=“application/x-www-form-urlencode”。 dataType: "json", success: function (data) { alert(data); }, error: function (d, c, e) { alert(e); } }); } function a4() { $.ajax({ type: "post", url: "Default2.aspx/RequestedMethod1", contentType: "application/json;charset=utf-8", //必须 dataType: "json", success: function (res) { alert("success:" + res.d); // 注意这点后面要加个d才能获取字符串信息,至于为什么要加个d,你通过chrome看看返回的响应就知道了,O(∩_∩)O }, error: function (xmlReq, err, c) { alert("error:" + xmlReq + err); } }); } function a5() { $.ajax({ type: "Post", url: "Default2.aspx/RequestedMethod2", data: "{msg:'hello'}",//"{'msg':'hello'}", contentType: "application/json;charset=utf-8",// 这句可不要忘了。 dataType: "json", success: function (res) { $("#dataShow").text("success:" + res.d); // 注意有个d,至于为什么通过chrome看响应吧,O(∩_∩)O。 }, error: function (xmlReq, err, c) { $("#dataShow").text("error:" + err); } }) } </script>后台部分
public partial class Default2 : BasePage{ protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { //双问号的作用 y = x, if x is not NULL; otherwise y = -1. int y = x ?? -1; if ((Request["token"] ?? "") == "ajax") { // 下面这些内从可以放在一个方法里,然后通过“token”标记去判断执行哪个方法。 Response.Write("我是直接请求aspx页面返回的文字!"); Response.End(); } else if ((Request["token"] ?? "") == "ajaxXml") { Response.ContentType = "application/xml"; string wtstr = "<my>123</my>"; Response.Write(wtstr); Response.End(); }else if ((Request["token"] ?? "") == "ajaxJson") { // 如果要是返回的响应为xml,则必须这样设置 Response.ContentType = "application/json"; // 如果要是返回的响应为xml,返回的字符串必须是可以被解析的xml文档格式。 Response.Write("[123]"); Response.End(); } } }//Page_Load end //要写这个 [WebMethod] public static string RequestedMethod1() //如果没有传参就不能加参数 { return "aaa"; } [WebMethod] public static string RequestedMethod2(string msg) //如果没有传参就不能加参数 { return msg; }}
0 0
- 做软件工程探索的C#网站架构方案-总结
- 总结:如何做一份高质量的网站策划方案?
- 软件工程 之 学习C#前的总结~
- 大型视频网站的技术架构方案
- 网站架构策划方案
- 网站架构探索(1)---序言
- 网站架构探索(1)---序言
- 网站架构探索(3)---负载均衡的方式
- 如何做一份高质量的网站策划方案呢?
- 一套网站架构完整方案
- 一套网站架构完整方案
- 一套网站架构完整方案
- LAMP网站架构方案分析
- LAMP网站架构方案分析
- 一套网站架构完整方案
- LAMP网站架构方案分析
- LAMP网站架构方案分析
- LAMP网站架构方案分析
- 执行一个查询返回新的datatable或dataset
- POJ 3646 Dragon of Loowater
- ORACLE 11G 如何修改 awr 的保留期限小于8天
- 浅析人脸检测之Haar分类器方法
- perl 最新源码 windows下编译
- 做软件工程探索的C#网站架构方案-总结
- 推荐一些Eclipse 插件
- BNUOJ 34978 汉诺塔
- PostgreSQL学习手册(角色和权限)
- xml publisher根据条件显示或隐藏列
- egit 中配置merge
- SQL的四种连接:内连接 左外连接 右外连接 全连接
- 项目中的成长
- 黑马程序员_Java基础[16]_多态1