.主控前台页面
<%@ 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版部分视图与请求拦截的更多相关文章

  1. axios源码解析 - 请求拦截器

    axios请求拦截器,也就是在请求发送之前执行自定义的函数. axios源码版本 - ^0.27.2 (源码是精简版) 平时在业务中会这样去写请求拦截器,代码如下: // 创建一个新的实例 var s ...

  2. RDIFramework.NET -.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(WebForm版)

    RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(WebForm版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之 ...

  3. angularjs http 请求拦截器

    /** * Created by oy on 2016/11/29. */ (function() { 'use strict'; // 创建angular模块 angular .module('ap ...

  4. 浏览器助手,请求拦截,后台模拟键鼠操作,页内嵌入JS

    http://www.cnblogs.com/ /// <summary>        /// 网页浏览器助手        /// 请求拦截,后台模拟键鼠操作,页内嵌入JS       ...

  5. 5.前端基于react,后端基于.net core2.0的开发之路(5) 配置node层,session设置、获取,请求拦截

    1.总结一下 今年,2月份从深圳来到广州,工作到现在,回头看,完成的项目4-5个,公司基本没有懂技术的领导,所以在技术选型上,我们非常的自由,所以内心一直都不满足现状,加上一起工作的小伙伴给力(哈哈哈 ...

  6. 基于 HTTP 请求拦截,快速解决跨域和代理 Mock

    近几年,随着 Web 开发逐渐成熟,前后端分离的架构设计越来越被众多开发者认可,使得前端和后端可以专注各自的职能,降低沟通成本,提高开发效率. 在前后端分离的开发模式下,前端和后端工程师得以并行工作. ...

  7. axios设置请求拦截和响应拦截

    首先我们先创建axios实例 const service = axios.create({ baseURL: url, //是用于请求的服务器 URL timeout: 5000, // 请求超时时间 ...

  8. Vue添加请求拦截器

    一.现象 统一处理错误及配置请求信息 二.解决 1.安装 axios  , 命令: npm install axios --save-dev 2.在根目录的config目录下新建文件 axios.js ...

  9. token回话保持,axios请求拦截和导航守卫以及token过期处理

    1:了解token:有时候大家又说token令牌.整个机制是前端第一次登陆发送请求,后端会根据前端的用户名和密码, 通过一些列的算法的到一个token令牌, 这个令牌是独一无二的,前端每次发送请求都需 ...

随机推荐

  1. python3 tkinter 桌面软件教程

    效果图 """"brid布局""" from tkinter import * import tkinter.filedialog ...

  2. MyBatis_Study_002(进阶,增删改查)

    源码:https://github.com/carryLess/mbtsstd-002.git 1.主配置文件 <?xml version="1.0" encoding=&q ...

  3. Programming Languages: Application and Interpretation

    http://cs.brown.edu/courses/cs173/2012/book/ 1 Introduction 1.1 Our Philosophy 1.2 The Structure of ...

  4. PHP安全性漫谈

    最近刚做完两个PHP的网站项目,客户虽然没有安全性的相关需求,但是自己不能放过对自己的要求,何况对以后做电子商务的项目相当有帮助,呵呵,早准备早超生,经过查看PHP 帮助和相关资料~~~~       ...

  5. The type org.springframework.context.support.AbstractApplicationContext cannot be resolved

    在 myeclipse中,使用 jdk6和7,并使用 spring-framework-5.0.2.RELEASE 时,编写代码: import org.springframework.context ...

  6. vim之vundle

    git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle,下载到本地 gvim ~/.vimrc set nocompat ...

  7. JWPlayer快速入门指南(中文)

    将JW Player嵌入到网页中非常的简单,只需要进行如下3个步骤: 1.解压mediaplayer-viral.zip文件,将jwplayer.js和player.swf文件拷贝到工程中: 2.在页 ...

  8. Eclipse Android 代码自动提示功能 +导入 epf

    1.设置 java 文件的代码提示功能 打 开 Eclipse 依次选择 Window > Preferences > Java > Editor - Content Assist ...

  9. ubantu环境下fidder安装

    转自:http://www.cnblogs.com/jcli/p/4474332.html Linux(Ubuntu)环境下使用Fiddler 自己的开发环境是Ubuntu, 对于很多优秀的软件但是又 ...

  10. 错误:HttpServlet was not found on the Java

    我们在用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not found on t ...