I've got a bit of a weird issue that I'm trying to figure out how to get around. Basically, the company I work for uses a CMS that only allows inline code for ASP.net and uses a 'styles' system to do things like Header/Footer.
Now the issue I have is on a certain page that displays course information, we have some asp.net code that generates the page based on factors from the previous linking page I.E a course search page that then takes you to the course you have selected.
Now we've got terrible SEO and I need to be able to dynamically create the title/meta tags for the page based on the selections from the course search.
Problem is for SEO, I need the title tag to be in the header but the identifiable information for that page comes within the asp.net code that grabs the course information from a DB and this is run in the body of page.
Is there any way for me to grab information or run another block of asp.net code at the header to set up the tags I need?
I apologise if this doesn't make much sense but then our CMS system makes everything more difficult but I'm unable to remove it.
Thanks!
So if I understand you correctly, you want to add <title>
and <meta ...>
tags into your rendered pages' <head>
tag in your server-side code?
If you're using ASP.NET 2.0 or higher, you can change the <head>
element to be accessible to the server code by adding runat="server"
to the declaration. You can then set the title value through the Pages' Title
property.
To add <meta>
tags you'll need to be running ASP.NET 4.0, which adds MetaKeywords
and MetaDescription
properties to the Page object.
So to put this all together, your page markup should include:
<% Page ... %>
<html>
<head runat="server">
...
</head>
<body>
...
And then in your serverside code:
Page.Title = "My course page";
Page.MetaDescription = "My Page for Course x";
Page.MetaKeywords = "course, education, learning";
This should then render out as:
<html>
<head>
<title>My course page</title>
<meta name="description" content="My Page for Course X" />
<meta name="keywords" content="course, education, learning" />
....