用asp.net开发wap网站

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class viewBook : System.Web.UI.MobileControls.MobilePage
{
    public int dxClass;
    public int curpage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["menuID"] != null)
        {
            dxClass = Int32.Parse(Request.QueryString["menuID"].ToString());
        }

        if (!this.IsPostBack)
        {
            this.Bind();
        }

    }

    //获取目录
    private DataSet getMenuDs(int menuID)
    {
        OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("App_Data/dx.mdb"));
        con.Open();
        string strCmd = "select * from menu where from=" + menuID;
        OleDbDataAdapter da = new OleDbDataAdapter(strCmd, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        return ds;
    }

    //数据绑定
    private void Bind()
    {
        this.List1.Items.Clear();

        DataSet menuDs = getMenuDs(dxClass);

        this.Label3.Text = Convert.ToString(menuDs.Tables[0].Rows.Count / 10 + 1);

        curpage = Int32.Parse(this.Label2.Text);//当前页

        //如果当前页是第一页,并且只有一页面,那么不显示按钮
        if (this.Label2.Text == this.Label3.Text&&this.Label2.Text=="1")
        {
            this.Command1.Visible = false;
            this.Command2.Visible = false;
        }
        else if (this.Label2.Text =="1")//如果当前页是第一页,上一页按钮不显示
        {
            this.Command1.Visible = false;
            this.Command2.Visible = true;
        }
        else if (this.Label2.Text == this.Label3.Text)//当前页是最后一页,那么下一页按钮不显示
        {
            this.Command1.Visible = true;
            this.Command2.Visible = false;
        }
        else
        {
            this.Command1.Visible = true;
            this.Command2.Visible = true;
        }

        if (Convert.ToInt32(this.Label2.Text)  == Convert.ToInt32(this.Label3.Text))
        {
            for (int i = (curpage - 1) * 10; i < menuDs.Tables[0].Rows.Count; i++)
            {
                string dxShort = menuDs.Tables[0].Rows[i]["menuName"].ToString();
                MobileListItem item = new MobileListItem(dxShort, "viewList.aspx?bookID=" + menuDs.Tables[0].Rows[i]["menuID"].ToString());
                this.List1.Items.Add(item);
            }
        }
        else
        {
            for (int i = (curpage - 1) * 10; i < curpage * 10 - 1; i++)
            {
                string dxShort = menuDs.Tables[0].Rows[i]["menuName"].ToString();
                MobileListItem item = new MobileListItem(dxShort, "viewList.aspx?bookID=" + menuDs.Tables[0].Rows[i]["menuID"].ToString());
                this.List1.Items.Add(item);
            }
        }


    }
    //上一页
    protected void Command1_Click(object sender, EventArgs e)
    {
        this.Label2.Text = Convert.ToString(Int32.Parse(this.Label2.Text) - 1);
        this.Bind();
    }
    //下一页
    protected void Command2_Click(object sender, EventArgs e)
    {
        this.Label2.Text = Convert.ToString(Int32.Parse(this.Label2.Text) + 1);
        this.Bind();
    }
}

1,格式

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>document title</title>
</head>
<body>
</body>
</html>

 

拨打电话
<a href="wtai://wp/mc;13888888888">Call Me Now</a>

 

访问asp站点的时候会根据访问的设备,输出不同的内容,如果用IE访问就输出的是html,手机访问,输出就是WML。是什么让他这么智能化呢?关键之处就在配置文件的<browserCaps>节!

在webconfig中加上这个,他可以强制输出wml,还有其他的移动设置属性都在这。

<browserCaps>
            
<result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            
<use var="HTTP_USER_AGENT"/>

            browser=Unknown
            version=0.0
            majorversion=0
            minorversion=0
            frames=false
            tables=false
            cookies=false
            backgroundsounds=false
            vbscript=false
            javascript=false
            javaapplets=false
            activexcontrols=false
            win16=false
            win32=false
            beta=false
            ak=false
            sk=false
            aol=false
            crawler=false
            cdf=false
            gold=false
            authenticodeupdate=false
            tagwriter=System.Web.UI.Html32TextWriter
            ecmascriptversion=0.0
            msdomversion=0.0
            w3cdomversion=0.0
            platform=Unknown
            css1=false
            css2=false
            xml=false

            mobileDeviceManufacturer = "Unknown"
            mobileDeviceModel = "Unknown"

            gatewayVersion = "None"
            gatewayMajorVersion = "0"
            gatewayMinorVersion = "0"

           preferredRenderingType = "wml11"
           preferredRenderingMime = "text/vnd.wap.wml"
           preferredImageMime = "image/vnd.wap.wbmp"

            defaultScreenCharactersWidth = "12"
            defaultScreenCharactersHeight = "6"
            defaultScreenPixelsWidth = "96"
            defaultScreenPixelsHeight = "72"
            defaultCharacterWidth = "8"
            defaultCharacterHeight = "12"
            screenBitDepth = "1"
            isColor = "false"
            inputType = "telephoneKeypad"

            numberOfSoftkeys = "0"
            maximumSoftkeyLabelLength = "5"

            canInitiateVoiceCall = "false"

            canSendMail = "true"
            hasBackButton = "true"
            rendersWmlDoAcceptsInline = "true"
            rendersWmlSelectsAsMenuCards = "true"
            rendersBreaksAfterWmlAnchor = "false"
            rendersBreaksAfterWmlInput = "false"
            rendersBreakBeforeWmlSelectAndInput = "true"
            requiresAttributeColonSubstitution = "true"
            requiresPhoneNumbersAsPlainText = "false"
            requiresUrlEncodedPostfieldValues = "false"
            requiredMetaTagNameValue = ""
            rendersBreaksAfterHtmlLists = "true"
            requiresUniqueHtmlCheckboxNames = "true"
            requiresUniqueHtmlInputNames = "true"
            requiresUniqueFilePathSuffix = "true"
            supportsCss = "false"
            hidesRightAlignedMultiselectScrollbars = "false"
            canRenderAfterInputOrSelectElement = "true"
            canRenderInputAndSelectElementsTogether = "true"
            canRenderOneventAndPrevElementsTogether = "true"
            canCombineFormsInDeck = "true"
            canRenderMixedSelects = "true"
            canRenderPostBackCards = "true"
            canRenderSetvarZeroWithMultiSelectionList = "true"
            supportsImageSubmit = "true"
            supportsSelectMultiple = "true"
            requiresHtmlAdaptiveErrorReporting = "false"
            requiresContentTypeMetaTag = "false"
            requiresDBCSCharacter = "false"
            requiresOutputOptimization = "false"
            supportsAccesskeyAttribute = "false"
            supportsInputIStyle = "false"
            supportsInputMode = "false"
            supportsIModeSymbols = "false"
            supportsJPhoneSymbols = "false"
            supportsJPhoneMultiMediaAttributes = "false"
            maximumRenderedPageSize = "2000"
            requiresSpecialViewStateEncoding = "false"
            requiresNoBreakInFormatting = "false"
            requiresLeadingPageBreak = "false"
            supportsQueryStringInFormAction = "true"
            supportsCacheControlMetaTag = "true"
            supportsUncheck = "true"
            canRenderEmptySelects = "true"
            supportsRedirectWithCookie = "true"
            supportsEmptyStringInCookieValue = "true"
            cachesAllResponsesWithExpires = "false"
            requiresNoSoftkeyLabels = "false"
            defaultSubmitButtonLimit = "1"
            
            supportsBold = "false"
            supportsItalic = "false"
            supportsFontSize = "false"
            supportsFontName = "false"
            supportsFontColor = "true"
            supportsBodyColor = "true"
            supportsDivAlign = "true"
            supportsDivNoWrap = "false"
            supportsCharacterEntityEncoding = "true"

            isMobileDevice="false"
</browserCaps

另外通过设置
         Page.Response.Expires = -1;
   Response.CacheControl 
= "Public"; 
可以取消移动设备缓存,并通过RedirectToMobilePage函数进行重定向。

E缘导航程序 前台功能 1.添加网站 2.用户留言 3.网站搜索 4.最新链入、加盟网站分页展示 5.网站显示类型(首页顶部、首页推荐、分类页里面) 6.类别显示类型(首页、普通、子分类) 7.访问统计:单个IP日独立统计,一个IP一天进出都只算一次有效性 8.用户访问记录:访问时间、手机号、IP号、来源地址、来源网站;链出网站具有相同记录 9.二次点击:判断用户进入网站后是否有点击站内页面 10.自动控量:程序按网站进出所设比例自动控制进出流量(当用户重复点击某个站时,程序自动跳转到其他今日未访问且比例未达到标准的网站) 11.网站屏蔽:开启屏蔽后非手机用户禁止访问 12.HTML彩色版 13.识别用户手机是否支持WML版,不支持跳转到HTML版 14.用户收藏夹(开发中。。。) 后台功能 1.系统的基本配置 2.网站信息、分类信息、留言信息增删改查 3.访问详情多条件查询/删除(网站ID、时间段、进/出、有效性) 4.网站总体日访问统计(可按时间段查询/删除、单选多选删除) 5.单个网站日访问统计(可按时间查询/删除) 6.IP的总体统计查询/删除(统一IP的手机访问进/出总数、非手机进/出总数,所有总计) 6.页面的自定义内容修改 7.添加新页面(内容自定义,支持HTML及普通文本) 8.账号密码修改/注销退出 账号密码 后台地址:http://您的域名/admin 用户账号:admin 用户密码:123456
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值