zoukankan      html  css  js  c++  java
  • 使用ASP.net 2.0 的一些新特性

     by:(fallseir.lee) 飞扬轻狂


    使用masterpage

    新建一个site
    添加一个新的masterpagethe_one.master
    打开 the_one.master
    添加 默认titlemeta
    添加 全局控件 sitemap
    添加 ContentPlaceHolder

    <%@ Master Language="C#" AutoEventWireup="true"

     CodeFile="The_One.master.cs" Inherits="The_One_Master" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

        <title>FeedSky</title>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

       

    </head>

    <body>

        <form id="form_one" runat="server">

        <div>

            <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em"

                PathSeparator=">" PathDirection="RootToCurrent" SiteMapProvider="XmlSiteMapProvider" SkipLinkText="<%$ Resources:SiteMap_LinkText %>" meta:resourcekey="SiteMapPath1Resource1">

                <PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />

                <CurrentNodeStyle ForeColor="#FF8000" />

                <NodeStyle Font-Bold="True" ForeColor="#507CD1" />

                <RootNodeStyle Font-Bold="True" ForeColor="#284E98" />

              </asp:SiteMapPath>

            <asp:ContentPlaceHolder ID="Content_Header" runat="server">         

            </asp:ContentPlaceHolder>

            <asp:contentplaceholder id="Content_Main" runat="server">

            </asp:contentplaceholder>

            <asp:ContentPlaceHolder ID="Content_Footer" runat="server"></asp:ContentPlaceHolder>

        </div>

        </form>

    </body>

    </html> 


    添加额外的头信息


    在页面中使用

    HtmlGenericControl c=new System.Web.UI.HtmlControls.HtmlGenericControl("meta");

        c.Attributes["name"]="keywords";

        c.Attributes["content"]="feedsky";

        Master.Page.Header.AddParsedSubObject(c);


    方式加入

    创建测试页
    新建 aspx页面 并选择使用marsterpage

    <%@ Page Language="C#" MasterPageFile="~/Templates/The_One.master"

    AutoEventWireup="true" CodeFile="thetwo.aspx.cs"

    Inherits="thetwo" Title="Untitled Page" Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="Content_Header" Runat="Server">

    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="Content_Main" Runat="Server">

     

    <asp:Label ID="Label1" runat="server" meta:resourcekey="Label1Resource1" Text="Label"></asp:Label><asp:Button

      ID="Button1" runat="server" meta:resourcekey="Button1Resource1" OnClick="Button1_Click"

      Text="Button" /><br />

      <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Global,Content2_content %>"></asp:Literal></asp:Content>

    <asp:Content ID="Content3" ContentPlaceHolderID="Content_Footer" Runat="Server">

    </asp:Content>


    设置 sitemap

    添加 sitemap

    <?xml version="1.0" encoding="utf-8" ?>

    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"

                                enableLocalization="true">

        <siteMapNode url="~/Default.aspx" title="$Resources:global,FeedSky.com"  description="Feedsky.com's home page">

            <siteMapNode url="~/theone.aspx" title="$Resources:global,one"  description="1" />

            <siteMapNode url="~/thetwo.aspx" title="$Resources:global,two"  description="2" />

        </siteMapNode>

    </siteMap>


    设置 web.config 关联 sitemap

     

    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">

                        <providers>

                               <add name="XmlSiteMapProvider" description="SiteMap provider which reads in .sitemap XML files."

                                      type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

                                      siteMapFile="feedsky.sitemap" securityTrimmingEnabled="true"/>

                        </providers>

                  </siteMap>


    添加局部资源文件支持


    打开 thetwo.aspx
    选择tools/Generate Local Resource
    vs
    将在thetwo.aspx所在的目录下创建App_LocalResources文件夹 并生成the_two.aspx.resx文件
    vs
    会修改thetwo.aspx文件 加入meta:resourcekey="xxxx" the_two.aspx.resx文件中的字段对应

    copy .resx
    文件 the_two.aspx.en-us.resx 并修改里面的字段为英文 (添加页面的英文支持)
    asp.net2
    会在用户浏览时自动根据用户浏览器的首选语言进行匹配

    添加全局资源文件支持


    新建 资源文件 global.resx
    添加字段Content2_content 并设置其值为 测试
    copy global.resx
    global.en-us.resx
    修改 Content2_content 的值为 test
    the_two.aspx中添加

    <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Global,Content2_content %>"></asp:Literal>


    以测试全局资源是否可用

    $ Resources:Global,Content2_content

    $Resources
    为获取资源文件中的内容

    Global
    为资源文件名,Content2_content为使用的键值

    sitemap 中使用本地化资源

    添加 enableLocalization="true"

    设置文本获取方式为"$Resources:global,one"

    使用theme

    添加skin文件 the_one
    the_one.skin文件的文件夹用添加css文件


    设置web.config


    加入 <pages theme="the_one" styleSheetTheme="the_one"/>
    asp.net 2.0
    会自动加载 App_Themes/the_one下的.css文件 the_one.skin

  • 相关阅读:
    Memcache 缓存系统
    galera-cluster 集群
    CentOS 文件中行内容操作
    快速查找日志文件最后一行及某个时间段的日志
    CentOS 下生成随机颜色
    Linux 下紧急删除大文件不能及时释放空间应急处理办法
    Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*'
    Ant design vue 引入echarts
    .net core 发布时 IIS 站点 提示:文件名 web.config 错误:配置文件的 xml 格式不正确
    远程连接MySQL出现1130错误
  • 原文地址:https://www.cnblogs.com/net66/p/275192.html
Copyright © 2011-2022 走看看