1. 程式人生 > >用asp.net開發wap網站

用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函式進行重定向。

相關推薦

asp.net開發wap網站

using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web

ASP.NET Web API技術開發HTTP接口(一)

ble 身份驗證 刪除 發現 bapi try prot 好用 get 開發工具 Visual Studio 2013 SQL Server 2008 R2 準備工作 啟動Visual Studio 2013,新建一個ASP.NET Web應用程序,命名為SimpleAPI

ASP.NET Web API技術開發HTTP介面

開發工具 Visual Studio 2013 SQL Server 2008 R2 準備工作 啟動Visual Studio 2013,新建一個ASP.NET Web應用程式,命名為SimpleAPI。選擇Empty模板,並勾選“Web API”,無身份驗證,不新增單元測試。 準備用SQL S

解決Asp.net Mvc 開發時出現glyphicons-halflings-regular.woff2 not found的問題

這個問題要特別說明一點:不要用MVC中的捆綁(bundle)CSS檔案操作,否則,即使作一下配置,也沒有效果。 用Asp.net Mvc開發時,CSS用bootstrap的話,在引用字型時,會出現glyphicons-halflings-regular.woff2 not

一個簡單的ASP.NET/C#開發的元件化Web應用程式(附原始碼)

==============================================================================1)建立一個類來處理使用者登入,將該類編譯成一個裝配件(assembly),併發布到站點的bin目錄下。========

ASP.NET開發中修改程式碼而不重啟網站

我們在做網站開發的時候,通常是寫好了一個功能就要進行測試,Visual Studio上點“Start Debugging”(快捷鍵是F5),這是除錯模式,也有直接執行模式,“Start Without Debugging”(快捷鍵是Ctrl+F5),網站啟動,並且預設會開啟一個瀏覽器視窗讓你看到結果,假如這個

網站二級域名asp.net 2.0的實現方案

基本思路:1. 域名支援泛解析,即是指:把A記錄 *.域名.com  解析到伺服器IP,伺服器IIS中做繫結,繫結時主機頭為空;2. 為了實現完全的二級域,建兩個站點,一個為主站用,一個為使用者用,兩個站點目錄都指到一個同一網站目錄3. 在Web程式中或取URL來源中的二級域名主機頭,比如:abc.域名.co

【.Net碼農】asp.net實現遠端獲取其他網站頁面指定內容

遠端獲取網頁內容.經過一定的處理和靈活應用,可以開發成成體系網站內容採集系統.通常也叫做"新聞小偷"一般來說.做內容採集分為如下幾個大致的步驟:   1.遠端獲取頁面的全部Html源文字.   2.通過過濾處理,分析有效內容文字.(通常用正則表示式來擷取有效資料)   3.將格式有效的資料,根據自己的資料庫結

請推薦幾個asp.net下做網站的好的開源框架

b- 開發 開放源代碼 ces dex 生產 推薦 面向對象 塑造 1.We7 CMSWe7 CMS是由西部動力開發的一款充分發掘互聯網Web2.0(如博客、RSS等)的信息組織優勢,將其理念利用到政府企事業網站的構建、組織、管理中的網站建設和管理方面的產品。系統目標:叫創

在Docker上運行Asp.Net Core示例網站

ner -1 例子 none 阿裏 clas block idt netcore dotnet的鏡像:https://hub.docker.com/r/microsoft/dotnet/,如下圖: 下面就演示一下怎麽跑一下示例程序,用意是拋磚引玉。 1.首先拉一下鏡

關於AJAX跨域調ASP.NET MVC或者WebAPI服務的問題及解決方案

-h protocol silver 我們 rem 做了 mode edm run 問題描述 當跨域(cross domain)調用ASP.NET MVC或者ASP.NET Web API編寫的服務時,會發生無法訪問的情況。 重現方式

ASP.NET Core 2.0 建立規範的 REST API -- GET 和 POST

前綴 cat 編輯 derby 發生 就是 media 展現 targe 本文轉自:https://www.cnblogs.com/cgzl/archive/2018/05/23/9047626.html 本文所需的一些預備知識可以看這裏: http://www.cnblo

ASP.Net Core MVC 網站在Windows服務器跑步起來

tin 2.0.8 ack ica 圖片 排查 所有 comm cal 1.vs遠程發布到服務器,瀏覽器訪問,報錯502 2.打開錯誤提示提供的網址參考 3.安裝runtime,sdk,Hosting Bundle Installer,其他操作 .....發現並沒有什麽用(

ASP.NET Core 2.1 建立規範的 REST API -- HATEOAS

enume edi count DC tutorial 不知道 客戶 自適應 獨立 本文所需的一些預備知識可以看這裏: http://www.cnblogs.com/cgzl/p/9010978.html 和 http://www.cnblogs.com/cgzl/p/90

ASP.NET Core MVC 和 EF Core 構建Web應用 (二)

work nal nta 多個 包括 catch web 應用 自動 選項卡 本節學習如何執行基本的 CRUD (創建、 讀取、 更新、 刪除) 操作。 自定義“詳細信息”頁 學生索引頁的基架代碼省略了 Enrollments 屬性,因為該屬性包含一個集合。 在“詳細信息”

ASP.NET Core MVC 和 EF Core 構建Web應用 (九)

fix pro school time lap namespace 繼承映射 數據庫表 eas 在上一節中,已經處理了並發異常。 本節將演示如何在數據模型中實現繼承。 在面向對象的編程中,可以使用繼承以便於重用代碼。 在本教程中,將更改 Instructor和 Studen

ASP.NET Core MVC 和 EF Core 構建Web應用 (十)

pan 信息 expr dispose writing AS das ech 任務欄 之前的學習中,已經以每個類一張表的方式實現了繼承。 本節將會介紹在掌握開發基礎 ASP.NET Core web 應用程序之後使用 Entity Framework Core 開發時需要註

asp.net開發分享,learun framework工作流審批設計

  對於企業應用系統來說,工作流可以說是其核心和靈魂,而審批流程則是比較重要的基礎應用場景,一個良好的審批設計可以有效的提高公司運轉效率,提升管理規範。 接下來,我們從角色、內容、流程、動作、許可權、配置、效率這幾個方面,瞭解一下learun framework審批工作流的產品設計。

asp.net開發分享,learun framework工作流審批設計

分配 含義 電商 修改 便在 快速 只讀 部門主管 onf 對於企業應用系統來說,工作流可以說是其核心和靈魂,而審批流程則是比較重要的基礎應用場景,一個良好的審批設計可以有效的提高公司運轉效率,提升管理規範。 接下來,我們從角色、內容、流程、動作、權限、配置、效率這幾個方面

ASP.NET 訪問專案網站以外的目錄檔案

簡單的說,可以通過在 IIS 新增虛擬目錄的方法做到,獲取訪問路徑的時候就用 HttpContext.Current.Server.MapPath("~/xxx"); 的方式。 下面詳細講一下具體怎麼做…… 首先看 IIS 上部署的專案網站結構: 有兩個專案網站,