解决的问题,加载数据库中的UI

public class Global : System.Web.HttpApplication
{

protected void Application_Start(object sender, EventArgs e)
{
DbPathProvider provider = new DbPathProvider();
HostingEnvironment.RegisterVirtualPathProvider(provider);

}

}

public class DbPathProvider : VirtualPathProvider
{
protected bo_view cbo_view = null;
Dictionary<string, FakeCacheDependency> dicFakeCacheDependencys = new Dictionary<string, FakeCacheDependency>();
public DbPathProvider() : base()
{

}

public override string GetCacheKey(string virtualPath)
{
string mvirtualPath = getmvirtual(virtualPath);
ICriteria<bo_view> wbo_view = CriteriaFactory.Create<bo_view>();
wbo_view = wbo_view.Where(q => q.pagename == mvirtualPath);
cbo_view = bo_view.Fetch(wbo_view);
if (!cbo_view.IsNew)
{
FakeCacheDependency fdc = null;
if (dicFakeCacheDependencys.TryGetValue(cbo_view.pagename, out fdc))
{
fdc.Clear(cbo_view.operdate);
}
}

return base.GetCacheKey(virtualPath);

}

public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
{

if (cbo_view.IsNew)
return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);

dicFakeCacheDependencys[cbo_view.pagename] = new FakeCacheDependency(cbo_view.operdate);
return dicFakeCacheDependencys[cbo_view.pagename];
}

public class FakeCacheDependency : System.Web.Caching.CacheDependency
{
public FakeCacheDependency(DateTime lastModified)
{
base.SetUtcLastModified(lastModified);
}
public FakeCacheDependency()
{
base.SetUtcLastModified(DateTime.UtcNow);
}

public void Clear(DateTime lastModified)
{
if (this.UtcLastModified != lastModified)
{
base.SetUtcLastModified(lastModified);
NotifyDependencyChanged(this, EventArgs.Empty);
}
}
}

public override bool DirectoryExists(string virtualDir)
{
if (cbo_view.IsNew)
base.DirectoryExists(virtualDir);
return true;
}

public override bool FileExists(string virtualPath)
{
if (cbo_view.IsNew)
base.FileExists(virtualPath);

return true;
}

public override VirtualFile GetFile(string virtualPath)
{
if (cbo_view.IsNew)
{
return this.Previous.GetFile(virtualPath);
}
return new DbVirtualFile(virtualPath, cbo_view);
}

private static string getmvirtual(string virtualPath)
{
string mvirtualPath = virtualPath;
int fileindex = virtualPath.LastIndexOf('/');
if (fileindex >= 0)
{
mvirtualPath = virtualPath.Substring(fileindex);
}

return mvirtualPath;
}
}

public class DBCacheDependency : CacheDependency
{
public DBCacheDependency(string path) : base(HttpRuntime.AppDomainAppPath.TrimEnd('\\') + "\\web.config")
{
FinishInit();
}

public new bool HasChanged
{
get { return true; }
}

static string GetDependKey()
{
return System.Guid.NewGuid().ToString();
}

}

public class DbVirtualFile : VirtualFile
{
private static string getmvirtual(string virtualPath)
{
string mvirtualPath = virtualPath;
int fileindex = virtualPath.LastIndexOf('/');
if (fileindex >= 0)
{
mvirtualPath = virtualPath.Substring(fileindex);
}

return mvirtualPath;
}
protected bo_view cbo_view = null;
public DbVirtualFile(string filename, bo_view mbo_view) : base(filename)
{
cbo_view = mbo_view;
}

public override Stream Open()
{
if (cbo_view.IsNew)
{
throw new Exception("此资源不存在");
}

byte[] bytes = System.Text.Encoding.Default.GetBytes(cbo_view.viewcontent);
return new System.IO.MemoryStream(bytes);
}
}

关键点:

在创建ui的时候,要注意@ page指令的写法

<%@ Page Title="" Language="C#" MasterPageFile="~/admin/Admin.Master" AutoEventWireup="true" CodeBehind="mm.aspx.cs" Inherits="MyBasePage" CompilationMode="Always" %> CodeBedhid可以是不存在的,YHWebCore.Business.MyBasePage如果没有后台代码,可以使用基页面。

VirtualPathProvider的使用的更多相关文章

  1. 9.2.2 .net framework下的MVC 控件的封装(下)

    控件封装的部分说明 可能有人觉得应该前后端分离,我也承认这是应该的方向,我们也在考虑使用ng2等简化前端.但是,我们封装控件还是因为如下原因综合考虑的: 我们这是个框架,上面支撑了许多个应用,包含几百 ...

  2. 《Pro ASP.NET MVC 4》异常整理

    最近在和同学一起研究毕业设计,准备模仿<Pro ASP.NET MVC 4>里面的SportsStore设计模式和测试驱动开发. 由于和书中VS版本不同,发现不少问题,在此总结. 用户代码 ...

  3. ASP.NET MVC 4 视图页去哪里儿

    这里特别感谢 swagon 提到了Displaymodeprovider,所以才有了本篇博客,也使我对[View的呈现]中寻找视图页的过程有了清晰的认识! 前戏 在MVC中,执行完Action之后,会 ...

  4. Mvc 模块化开发

    在Mvc中,标准的模块化开发方式是使用Areas,每一个Area都可以注册自己的路由,使用自己的控件器与视图.但是在具体使用上它有如下两个限制 1.必须把视图文件放到主项目的Areas文件夹下才能生效 ...

  5. [转]ASP.NET MVC Dynamic Themes

    本文转自:http://www.codeproject.com/Articles/32847/ASP-NET-MVC-Dynamic-Themes Download source code - 148 ...

  6. Orchard CMS中如何打包不带源码的模块

    在Orchard CMS的官网已经提供了文档说明如何打包,但是如果使用它的打包方式,打好的nuget包是带源代码的.如果是为开源系统写模块,不需要关注源代码是否可见.但是如果是用Orchard CMS ...

  7. 白话学习MVC(十)View的呈现二

    本节将接着<白话学习MVC(九)View的呈现一>来继续对ViewResult的详细执行过程进行分析! 9.ViewResult ViewResult将视图页的内容响应给客户端! 由于Vi ...

  8. NopCommerce使用Autofac实现依赖注入

    NopCommerce的依赖注入是用的AutoFac组件,这个组件在nuget可以获取,而IOC反转控制常见的实现手段之一就是DI依赖注入,而依赖注入的方式通常有:接口注入.Setter注入和构造函数 ...

  9. ASP.NET获取路径的方法

    原文:[转载]ASP.NET获取路径的方法 HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\p ...

随机推荐

  1. input事件与change事件

    输入框的change事件: 必须等到输入框失去焦点的时候才会触发,鼠标在空白的地方点一下: 输入框的input事件: 在输入内容变化的同时,实时的触发,不需要等到失去焦点.

  2. python基础八

    面向对象的好处 更容易扩展.提高代码使用效率,使你的代码组织性更强, 更清晰,更适合复杂项目的开发 封装 把功能的实现细节封装起来,只暴露调用接口 继承 多态 接口的继承 定义 类   ===> ...

  3. python基础七

    subprocess subprocess是专门用来替代os.system;os.spawn更加的先进. 但是subprocess.run()是在python3.5之后才出现的 实例 >> ...

  4. ListView加载性能优化---ViewHolder---分页

    ListView是Android中一个重要的组件,可以使用它加列表数据,用户可以自己定义列表数据,同时ListView的数据加载要借助Adapter,一般情况下要在Adapter类中重写getCoun ...

  5. JS客户端RSA加密,Java服务端解密

    常用语网页客户端对密码加密,在后端java解密还原 java代码依赖    <dependency>      <groupId>commons-codec</group ...

  6. ios 和安卓常用图标、启动图 尺寸

    ---------------------------------------------ios---------------------------------------------------- ...

  7. Qt json 数据处理

    用到的头文件 #include <QJsonArray> #include <QJsonDocument> #include <QJsonObject> json解 ...

  8. nginx配置返回文本或json

    有些时候请求某些接口的时候需要返回指定的文本字符串或者json字符串,如果逻辑非常简单或者干脆是固定的字符串,那么可以使用nginx快速实现,这样就不用编写程序响应请求了,可以减少服务器资源占用并且响 ...

  9. JavaCV配置

    下载javacv-1.2-bin.zip https://github.com/bytedeco/javacv 解压 在Eclipse项目 Referenced Libraries 中 Add Ext ...

  10. October 26th Week 44th Wednesday 2016

    No matter how far you may fly, never forget where you come from. 无论飞得多高,也不要忘记起飞的地方. I never forget w ...