webform版部分视图与请求拦截
.主控前台页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %> <%@ Import Namespace="WebApplication4" %>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.8.1.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="rskbook" name="rskbook" value="风险计量" partialview="~/Views/HtmlPage1.html" class="qie" />
<input type="button" id="rskfactor" name="rskfactor" value="风险因子" partialview="~/Views/HtmlPage2.html" class="qie" />
<div id="contents"> </div>
</form>
<script type="text/javascript">
$(function () {
$(".qie").on("click", function () {
var url = $(this).attr("partialview");
alert(url+"!!!")
$.post("webform1.aspx?_method=gethtml&url=" + url, function (data) {
data = JSON.parse(data);
$("#contents").html(data.html);
}); });
var url = "webform1.aspx?controller=Person&action=GetAge";
$.post(url, function (data) {
data = JSON.parse(data);
alert("成功");
});
});
</script>
</body>
</html> .主控后台
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Linq; namespace WebApplication4
{
public class aaAttribute : Attribute
{ }
public class ControllerBase
{ }
public class Person : ControllerBase
{
[aaAttribute]
public string GetAge()
{
return "我3岁了";
}
}
public static class Html
{
public static XmlNode getNode(string xmlPath,string url)
{
return getNode(xmlPath, AppDomain.CurrentDomain.BaseDirectory + url.Replace("~",""),);
}
public static XmlNode getNode(string xmlPath, string fileName,int i)
{ XmlNode node = null;
string root = xmlPath;
if (node == null)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
node = xmlDoc.SelectSingleNode(xmlPath); }
return node;
}
public static string GetFilePath(string filePath)
{
return AppDomain.CurrentDomain.BaseDirectory + filePath.Replace("~/", "").Replace("/", @"\"); }
public static string PartialView(string url)
{ string script = getNode("//html//head//script",url).OuterXml;
string body = getNode("//html//body",url).InnerXml;
string content = body.ToString() + "\r\n" +script.ToString();
return content;
}
}
public partial class BasePage : System.Web.UI.Page
{
public object GetObject(Type t)
{
return new Person();
}
protected virtual void Page_Load(object sender, EventArgs e)
{ string controller = Request["controller"];
string action = Request["action"];
if (!string.IsNullOrEmpty(controller))
{
var types = typeof(BasePage).Assembly.GetTypes();
Dictionary<Type, List<MethodInfo>> controllerActionHt = new Dictionary<Type, List<MethodInfo>>();
MethodInfo[] methods = null;
foreach (Type type in types)
{
//初始化controller
if (!controllerActionHt.ContainsKey(type))
{
controllerActionHt.Add(type, new List<MethodInfo>());
}
//添加action
methods = type.GetMethods();
foreach (MethodInfo m in methods)
{
(controllerActionHt[type]).Add(m);
}
}
var ct = (from c in controllerActionHt
where c.Key.Name == controller
&& c.Value.Any(x => x.Name == action)
select new { controller = c.Key, action = c.Value.FirstOrDefault() }).FirstOrDefault();
MethodInfo method = ct.action;
IEnumerable<Attribute> attrs = method.GetCustomAttributes();
object result = null;
foreach (var attr in attrs)
{
string name = attr.GetType().Name;
result=method?.Invoke(GetObject(ct.controller), null); }
Response.Write();
Response.End(); } }
}
public partial class WebForm1 : BasePage
{
protected override void Page_Load(object sender, EventArgs e)
{
switch (Request["_method"])
{
case "gethtml":
string url = Request["url"];
var html = Html.PartialView(url);
var json = Newtonsoft.Json.JsonConvert.SerializeObject(new { html = html });
Response.Write(json);
Response.End();
break;
default:
break;
}
base.Page_Load(sender, e);
} }
}
.相应的部分视图HtmlPage1
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<script type="text/javascript"> var Init=function() {
$("#btn").on("click", function () {
$("#sub").html('<div>我们都是好孩子11世</div>');
});
}()
</script>
</head> <body>
<div id='content'>
<input type='button' id='btn' name='btn' value='刷新11' />
<div id="sub">我们都是好孩子1世</div>
</div>
</body> </html> .部分视图HtmlPage2
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<script type="text/javascript"> var Init = function () {
$("#btn").unbind();
$("#btn").on("click", function () {
$("#sub").html('<div>我是超人马苏丹22世</div>');
});
}()
</script>
</head> <body>
<div id='content'>
<input type='button' id='btn' name='btn' value='刷新22' />
<div id="sub">我们都是好孩子2世</div>
</div>
</body> </html>
webform版部分视图与请求拦截的更多相关文章
- axios源码解析 - 请求拦截器
axios请求拦截器,也就是在请求发送之前执行自定义的函数. axios源码版本 - ^0.27.2 (源码是精简版) 平时在业务中会这样去写请求拦截器,代码如下: // 创建一个新的实例 var s ...
- RDIFramework.NET -.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(WebForm版)
RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(WebForm版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之 ...
- angularjs http 请求拦截器
/** * Created by oy on 2016/11/29. */ (function() { 'use strict'; // 创建angular模块 angular .module('ap ...
- 浏览器助手,请求拦截,后台模拟键鼠操作,页内嵌入JS
http://www.cnblogs.com/ /// <summary> /// 网页浏览器助手 /// 请求拦截,后台模拟键鼠操作,页内嵌入JS ...
- 5.前端基于react,后端基于.net core2.0的开发之路(5) 配置node层,session设置、获取,请求拦截
1.总结一下 今年,2月份从深圳来到广州,工作到现在,回头看,完成的项目4-5个,公司基本没有懂技术的领导,所以在技术选型上,我们非常的自由,所以内心一直都不满足现状,加上一起工作的小伙伴给力(哈哈哈 ...
- 基于 HTTP 请求拦截,快速解决跨域和代理 Mock
近几年,随着 Web 开发逐渐成熟,前后端分离的架构设计越来越被众多开发者认可,使得前端和后端可以专注各自的职能,降低沟通成本,提高开发效率. 在前后端分离的开发模式下,前端和后端工程师得以并行工作. ...
- axios设置请求拦截和响应拦截
首先我们先创建axios实例 const service = axios.create({ baseURL: url, //是用于请求的服务器 URL timeout: 5000, // 请求超时时间 ...
- Vue添加请求拦截器
一.现象 统一处理错误及配置请求信息 二.解决 1.安装 axios , 命令: npm install axios --save-dev 2.在根目录的config目录下新建文件 axios.js ...
- token回话保持,axios请求拦截和导航守卫以及token过期处理
1:了解token:有时候大家又说token令牌.整个机制是前端第一次登陆发送请求,后端会根据前端的用户名和密码, 通过一些列的算法的到一个token令牌, 这个令牌是独一无二的,前端每次发送请求都需 ...
随机推荐
- Codeforces 1009C: Annoying Present
C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- django-redis 中文文档
Andrey Antukh, niwi@niwi.be 4.7.0 翻译: RaPoSpectre 1. 介绍 django-redis 基于 BSD 许可, 是一个使 Django 支持 Redis ...
- 【转】ubuntu 12.04 下 Vim 插件 YouCompleteMe 的安装
原文网址:http://www.cnblogs.com/jostree/p/4137402.html 作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree ...
- 洛谷4294 [WC2008]游览计划——斯坦纳树
题目:https://www.luogu.org/problemnew/show/P4294 大概是状压.两种转移,一个是以同一个点为中心,S由自己的子集拼起来:一个是S相同.中心不同的同层转移. 注 ...
- 使用SharpZip压缩与解压缩
使用SharpZip压缩与解压缩 编写人:左丘文 2015-4-11 大家在做项目时,相信会经常性的会遇到要对数据流或dataset byte[] 或文件进行压缩和解压缩,比如:利用webservic ...
- MariaDB Galera Cluster的配置测试
参考的https://fykuan.hsnuer.net/blog/2015/01/23/debian-%E4%B8%8A%E5%AE%89%E8%A3%9D-mariadb-galera-clust ...
- 0908期 HTML Frameset框架和选择器
frameset框架 frameset与body没法同时使用,frameset用来分割页面,frame在frameset用于引用其他网页 <frameset rows="100,*&q ...
- C++11新特性介绍 01
阅读目录 1. 概述 2. long long 类型 3. 列表初始化 4. nullptr 空指针 5. constexpr变量 6. constexpr函数 7. using类型别名 8. aut ...
- jemalloc内存分配器详解
前言 C 中动态内存分配malloc 函数的背后实现有诸派:dlmalloc 之于 bionic:ptmalloc 之于 glibc:allocation zones 之于 mac os x/ios: ...
- nodejs连接mongodb
一.安装 a.访问mongodb官网下载https://www.mongodb.com/,有zip或者msi版本,zip解压缩就可以用,msi需要安装后使用 b.安装,指定好安装路径,一路下一步 c. ...