ASP.NET原创框架十-应用模块开发之页面生成( 二 )


 
protected bool SaveUserShareCache<T>(string sKey, T m_T, bool bSlidTime=true)
 
protected bool SaveUserShareCache<T>(string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime=true)
 
protected bool ReadUserShareCache<T>(string sKey, out T m_T, int nDelayMinute = -1)
 
protected bool ClearUserShareCache<T>( string sKey)
 
protected bool SaveUserCache<T>(string sKey, T m_T, bool bSlidTime=true)
 
protected bool SaveUserCache<T>(string sKey, T m_T, TimeSpan m_nOverTime, bool bSlidTime=true)
 
protected bool ReadUserCache<T>(string sKey, out T m_T, int nDelayMinute = -1)
 
protected bool ClearUserCache<T>(string sKey)
读取key
static protected string GetConfigKeyString(string sKeyName)
获得资源url
static protected string GetResourceUrl(HttpContext ctx)
获得页面前缀
static protected string GetUrlBefore(HttpContext ctx)
protected static string GetUrlHead(HttpContext ctx)
判断是否是PC端
protected bool IsPCClient()
判断是否HTTPS
protected bool IsHTTPS()
 
以上函数在页面里都可调用
常用功能及函数为
1.获得页面数据
<script language="C# " runat="server">
public Object getModel()
{
return this.Model;
}
</script>
<%
Hashtable m_HH=(Hashtable)getModel();
%>
2.权限判断
<%
string sError;
if (HavePower("CodeFactory_0_base", "Addcode_adcodes", false, out sError))
{
}
%>
3.获得当前登录信息
<%
SessionLink m_SessionLink = GetSessionLink();
%>
 
4.获得应用模块的view Url路径
<%
string ModeUrl = urlBefore + MainViewPath;
%>
<script src=https://www.isolves.com/it/cxkf/yy/net/2022-11-21/"amazeui/public/js/clipboard.min.js" type="text/JAVAscript">
 
5.获得资源的URL路径
<%
GetResourceUrl(HttpContext.Current);
%>
//应用例子
<script src=https://www.isolves.com/it/cxkf/yy/net/2022-11-21/"/public/amazeui/amazeui/js/jquery.min.js">
 
6.获得页面前缀
<%
GetHeadUrl(HttpContext.Current);
%>
//应用例子
ar options = {
iniUrl: "<%=GetUrlHead(HttpContext.Current)%>
weixin/initLayUI_RawJson.ajax", // 初始化接口
clearUrl: "<%=GetUrlHead(HttpContext.Current)%>
weixin/clearLayUI_RawJson.ajax", // 缓存清理接口
renderPageVersion: true, // 初始化页面是否加版本号
bgColorDefault: false, // 主题默认配置
multiModule: true, // 是否开启多模块
menuChildOpen: false, // 是否默认展开菜单
loadingTime: 0, // 初始化加载时间
pageAnim: true, // 切换菜单动画
};
 
页面渲染函数的内部实现
static protected string RenderPageView(HttpContext m_ctx, string m_ModePath, string m_TamplateCTL, Object m_Model)
该页面渲染函数支持对aspx的渲染和shtml采用开源JNTemplate渲染
aspx页面渲染核心代码
//构建Page pageVirtualPath:aspx文件路径
Page handler = BuildManager.CreateInstanceFromVirtualPath(pageVirtualPath, typeof(System.Web.UI.Page)) as Page;
//设置页面数据
SetPageModel(handler, m_Model, ViewPath);
StringWriter output = new StringWriter();
//执行输出页面
m_ctx.Server.Execute(handler, output, false);
//返回页面字符串
return output.ToString();
 
shtml页面JNTemplate渲染核心代码
string output="";
using (JNTemplateEngine m_JNTemplateEngine = new JNTemplateEngine(m_ctx, m_ModePath, FName, m_Model, true))
{
m_JNTemplateEngine.Render(out output);
}
对于开源JNTemplate的使用可查阅相关资料
其中JNTemplateEngine封装的渲染引擎代码如下
class JNTemplateEngine: IDisposable
{
JinianNet.JNTemplate.ITemplate ITemplate = null;
HttpContext ctx = null;
PageEngine m_PageEngine = null;
public JNTemplateEngine(HttpContext ctx, string m_ModePath, string src, Object m_Model, bool bFile = true)
{
this.ctx = ctx;
if (bFile)
ITemplate = Engine.LoadTemplate(src);
else
{
ITemplate = Engine.CreateTemplate(src);
}
ITemplate.Set("model", m_Model);
m_PageEngine = new PageEngine(ctx, m_ModePath);
ITemplate.Set("engine", m_PageEngine);
 
}
public JNTemplateEngine(HttpContext ctx, string m_ModePath, string src, Object m_Model, Type m_Type,bool bFile = true)


推荐阅读