ASP.NET C# 动态设置网页标题、关键字、描述

ASP.NET C# 动态设置网页标题、关键字、描述

一。在后台直接设置

if (!IsPostBack)
{
            //Page title网页标题
            Page.Title = “我的网站标题”;//须将网页head标签设成服务器控件模式,即<head runat="server">,否则无效

            //Description网页描述
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = "我的网站描述";
            Page.Header.Controls.Add(desc);

            //Keyword网页关键字
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = “我的网站关键字";
            Page.Header.Controls.Add(keywords);

}


二。在后台定义一个公共变量后,在前台进行调用

aspx.cs

 public string title = "";

protected void Page_Load(object sender, EventArgs e)

    {
        if (!IsPostBack)
        {
            int ID = int.Parse(Request.QueryString["ID"].ToString());
            dt = safeaccidentinfoservice.SelectSafeAccidentInfor(ID);
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    fi = new FileInfo(Server.MapPath(dr["FilePath"].ToString()));
                    title = fi.Name;
                    FileUrl = dr["FilePath"].ToString();
                }
            }
        }

    }

aspx

    <title>文件在线浏览-[<%=title%>]</title>


你可能感兴趣的:(ASP.NET C# 动态设置网页标题、关键字、描述)