使用masterpage
新建一个site
添加一个新的masterpage,the_one.master
打开 the_one.master
添加 默认title,meta
添加 全局控件 sitemap
添加 ContentPlaceHolder
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="The_One.master.cs" Inherits="The_One_Master" %>
<!DOCTYPE html PUBLIC "-//W 3C //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
<?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>
<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=b 03f 5f 7f 11d 50a 3a "
siteMapFile="feedsky.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
选择 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 会在用户浏览时自动根据用户浏览器的首选语言进行匹配
添加全局资源文件支持
添加字段 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 文件
asp.net 2.0 会自动加载 App_Themes/the_one 下的 .css 文件 和 the_one.skin