Adding Meta Tags In aspx Page and Content Pages of MasterPage In Asp.Net Using C# And VB Dynamically.
We can write code mentioned below in Page_Load Event to add dynamic tags.
C# CODE
VB.NET CODE
To add Meta Tags in site using Master Page we need to add tags in HTML source of content pages as mentioned below.
Head ContentPlaceHolder of content page.
HTML SOURCE OF CONTENT PAGE
We can write code mentioned below in Page_Load Event to add dynamic tags.
C# CODE
01
protected
void
Page_Load(
object
sender, EventArgs e)
02
{
//Add Description
03
HtmlMeta desc =
new
HtmlMeta();
04
desc.Name =
"Description"
;
05
desc.Content =
"Your page description"
;
06
Header.Controls.Add(desc);
07
08
// Add Keywords
09
HtmlMeta keywords =
new
HtmlMeta();
10
keywords.Name =
"Keywords"
;
11
keywords.Content =
"Your comma separated keywords"
;
12
Header.Controls.Add(keywords);
13
}
VB.NET CODE
01
Protected
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
02
'Add Description
03
Dim
desc
As
New
HtmlMeta()
04
desc.Name =
"Description"
05
desc.Content =
"Your page description"
06
Header.Controls.Add(desc)
07
08
' Add Keywords
09
Dim
keywords
As
New
HtmlMeta()
10
keywords.Name =
"Keywords"
11
keywords.Content =
"Your comma separated keywords"
12
Header.Controls.Add(keywords)
13
End
Sub
To add Meta Tags in site using Master Page we need to add tags in HTML source of content pages as mentioned below.
Head ContentPlaceHolder of content page.
HTML SOURCE OF CONTENT PAGE
1: <asp:Content ID="Content1" ContentPlaceHolderID="head"
2: Runat="Server">
3: <meta name="Description" content="Your page description"/>
4: </asp:Content>
If you like this post than join us or share
0 comments:
Post a Comment