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

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

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
gobal.asax Code [http://www.xueit.com] using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; using Rsion.Web; u

gobal.asax

 

Code [http://www.xueit.com]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Rsion.Web;
using c=Rsion.Web.Config;

namespace Rsion.Wap
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            InitTemplate();//初始化模板数据,只针对那些不经常变化的数据
        }
        # region events
        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
        #endregion

        private void InitTemplate()
        {
            global::Rsion.Web.Template t = Template.CreateInstance();
            //添加模板数据规则,只用于不常更新的数据  如key=webname 则替换成value
            t.Rules.Add("webname",c.Web.Current.WebName);
            t.Rules.Add("weburi", c.Web.Current.WebUri);
            t.Rules.Add("sysname", "sonven's wap develop framework!");
            Rsion.Web.Application.Template = t;

            //模板缓存过期时间(分钟)(默认10分钟)
            Rsion.Web.Application.TemplateCacheTime = 0;
        }
    }
}

然后着手开发wap项目了
首先新建一个default.aspx,default.aspx.cs
 两文件如下

Code [http://www.xueit.com]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rsion.Web.Config;

using Rsion.Web;

namespace Rsion.Wap
{
    public partial class Default:WapPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                TempData.Add("webname", Gobal.Web.WebName);
                TempData.Add("webUri", Gobal.Web.WebUri);
            }
        }
    }
}

default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Rsion.Wap.Default" %>
<wml>
<head></head>
<card title="<%=TempData["webname"] %>">
    <%Html.RenderPartial("top"); %>
    <%Html.RenderPartial("index"); %>
    数据绑定用&lt;%=TempData[id] %&gt;<br /><br />调用显示模板&lt;% Html.RenderPartial(&quot;<br />模板在Templates下的路径不包括.tpl)<br />
    模板中用:${templateId}代替符号<br />
    然后在使用Rsion.Web.Application.<br />Template.Rules.Add(templateID,value)<br />
    就可以调出value值了!
   
    <%Html.RenderPartial("bottom"); %>
</card>
</wml>怎么样呢是不是很简单,接着创建模板
文件放在/Templates/下哦,文件扩展为.tpl
bottom.tpl

<br />
<href="/">首页</a> | 
<href="http://www.cnyolee.com">有理网</a> |
<href="http://sonven.cnblogs.com">博客园</a> |
<href="http://www.rsion.com">联系我</a>
<br />
 ${webname} ${weburi}

同理创建其他的模板

我们在Page类里面实现了友好的自定义错误页,我们创建显示这个页面的error.aspx
error.aspx

Code [http://www.xueit.com]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Error.aspx.cs" Inherits="Rsion.Wap.Error" %>
<wml>
<card title="对不起出错了!">
    手机锐讯网 Web.rsion.com <br />
    错误信息:<br />
    <%=TempData["errormsg"]%>
</card>
</wml>

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Rsion.Web;

namespace Rsion.Wap
{
    public partial class Error:WapPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
               this.TempData["errormsg"] = Session["errormsg"] ?? "系统执行出错!";
            }
        }
    }
}

Ok了接下来就该验收结果了,达开/moni在里面输入你的地址就可以看到wap已经可以正常在浏览器中显示了
关于模拟器的实现请看我的另篇文章
点此下载该项目代码


精彩图集

赞助商链接