how do I get a page's meta tag contents?

  • Thread starter Thread starter PJ6
  • Start date Start date
P

PJ6

Can't find anywhere in the docs that mentions a way to programmatically get
a page's meta tag collection. Reflection finds nothing in attributes. Can't
find anything in a page instance, either. Are they not accessible?

Paul
 
this is how i did it

first make class that inherits from page
---------------------------------------------
using System.Text;
using System.Web.UI;
using System.IO;

namespace WebPageBase
{
public class PageBase : System.Web.UI.Page
{

protected System.Web.UI.HtmlControls.HtmlGenericControl alsideKeywords;


public string alsideKey
{
get
{
return alsideKeywords.Attributes["content"].ToString();
}
set
{
alsideKeywords.Attributes["content"] = value;
}
}


then make your meta tags "runat=server"
-------------------------------------------------


<meta name="keywords" id="alsideKeywords" content="Windows Siding"
runat="server"/>

make sure your page inherits from the new class and access like thi
-------------------------------------------------------------------------------

// dr is a datareader
//sets keywords
if(dr["keywords"] != DBNull.Value)
((WebPageBase.PageBase)Page).alsideKey = dr["keywords"].ToString();
else ((WebPageBase.PageBase)Page).alsideKey = "Alside - Windows and Siding";

HTH.......

Joe
 
there isn't one. unless your meta tags have a runat=server, they are just
generic html defined in a generic html control. all the html between
servercontrols is loaded in a single generic control and added to the
controls collection.

-- bruce (sqlwork.com)
 
Well that works but I think it's generally poor design to have any metadata
collection require instantiation. I know there is some hocus-pocus going on
in the background to build the temporary assemblies that support ASP.NET,
but I don't think it could have been too much of a stretch to have included
the meta tags as attributes in the created types that populate the ASP
namespace.

I was considering helping a client maintain their own metadata more easily
by just letting them alter meta tags on the pages themselves. But having to
instantiate each class to do something like collect metadata for all pages
just isn't going to fly. I'll have to use real attributes on the underlying
vb classes, and alteration of metadata will require editing the code itself
and a recompile, or perhaps I'll store it in SQL Server using a loose data
model if I don't consider that overkill for this particular project.

Paul

Joe said:
this is how i did it

first make class that inherits from page
---------------------------------------------
using System.Text;
using System.Web.UI;
using System.IO;

namespace WebPageBase
{
public class PageBase : System.Web.UI.Page
{

protected System.Web.UI.HtmlControls.HtmlGenericControl alsideKeywords;


public string alsideKey
{
get
{
return alsideKeywords.Attributes["content"].ToString();
}
set
{
alsideKeywords.Attributes["content"] = value;
}
}


then make your meta tags "runat=server"
-------------------------------------------------


<meta name="keywords" id="alsideKeywords" content="Windows Siding"
runat="server"/>

make sure your page inherits from the new class and access like this
-------------------------------------------------------------------------------

// dr is a datareader
//sets keywords
if(dr["keywords"] != DBNull.Value)
((WebPageBase.PageBase)Page).alsideKey = dr["keywords"].ToString();
else ((WebPageBase.PageBase)Page).alsideKey = "Alside - Windows and
Siding";

HTH.......

Joe



PJ6 said:
Can't find anywhere in the docs that mentions a way to programmatically
get
a page's meta tag collection. Reflection finds nothing in attributes.
Can't
find anything in a page instance, either. Are they not accessible?

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top