龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

asp.net开发WAP网站及集成在线wap模拟器(4)

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
现在我们要实现可以用于wap的page类了,WapPage.cs C# Code [http://www.xueit.com] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; us

现在我们要实现可以用于wap的page类了,WapPage.cs

C# Code [http://www.xueit.com]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.IO;
// Author : Sonven
// Blog   : Sonven.cnblogs.com

namespace Rsion.Web
{
    public class WapPage:Page
    {
        public WapPage() : base() { }

        /// <summary>
        /// 绑定事件
        /// </summary>
        protected override void BindEvents()
        {

            Page.Load  = delegate(object s, EventArgs e)
            {
                HttpContext.Current.Response.Write("<?xml version="1.0"?>
"  
                    "<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
");
            };

            Page.LoadComplete  = delegate(object s, EventArgs e)
            {
                HttpContext.Current.Response.ContentType = "text/vnd.Web.wml";
            };

            //处理错误时候转向错误页面[仅在发布后]

            #if DEBUG
            #else
            Page.Error  = delegate(object s, EventArgs e)
            {
                Session["errormsg"] = HttpContext.Current.Error.Message   "<br />"  
                    "地址:"   HttpContext.Current.Request.RawUrl.ToString();
                HttpContext.Current.Response.Redirect("~/error.aspx");
            };
            #endif

            Page.PreRender  = delegate(object s, EventArgs e)
            {
            };
        }
    }
}

这样就差不多只要继承WapPage就可以实现wap网页开发了
接下来我们创建模板,并给模板加上缓存提高性能
Application.cs用于提供缓存时间

C# Code [http://www.xueit.com]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Rsion.Web;

namespace Rsion.Web
{
    public abstract class Application:System.Web.HttpApplication
    {
        public static Template Template;
        /// <summary>
        /// 模板缓存时间
        /// </summary>
        public static int TemplateCacheTime = 10;
        /// <summary>
        /// 重启Web进程
        /// </summary>
        public static void RestartWebProcess()
        {
            HttpRuntime.UnloadAppDomain();
        }
    }
}

接下来我们创建一个单独的Template项目先
在里面创建Template.cs,ParamRules


精彩图集

赞助商链接