Dynamic meta tags in ASP.NET

29 September 2007 - 09:14 AM by Chris

Rather than go into all the gory details of why I need to do this, let's just say I have a need to determine dynamically to what URL a page will redirect. I'm passing along the destination URL in the querystring, so capturing that is easy enough. But since this page must first display its HTML, I can't just use a Response.Redirect().

So, I decided to use the HTML-based <meta equiv="refresh"> tag. However, I couldn't seem to get ASP.NET to allow me to use inline code to grab the querystring parameter to insert into the content attribute.

What about making the meta tag an object? I slapped a runat="server" and an ID="metaTag" in the meta tag, then in the code behind I could do this:

string url = Request.Querystring["url"];
metaTag.Content = "15;url=" + url;

I still don't know why the inline code wouldn't work, but this way seems cleaner to me anyway. 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Categories: ASP.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Add comment


(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

17 November 2008 - 10:15 PM