Community Server - Title and Keywords Editing by using Response.Filter() Method
How to Edit Title and Keywords in Community Server by using Response.Filter() Method
One of the most well known ASP.NET Forms and CMS application which can be freely used for web publishing is Community Server by Telligent.
The Community Server is very successfull to manage forms, form members, photo galleries, file download and upload sections and blog posts.
But one major aspect is not well covered in the design of the application.
That missing point is defining different page titles for each page and keyword meta tags specific for each different .aspx web page.
This point is important for especially SEO (Search Engine Optimization) fans, because keywords and page titles are important for a web page to be in the top results in web searches using search engines.
Of course if page title and keywords are not used approtiately this may be considered as a negative point by search engines and this is dissapointing for web masters who cares SEO.
In the administration pages of Community Server application, you can define a page title to be used for every page within the community web site.
Keywords are also defined in the same manner. They are used constantly in every web page within the web site.
So, if you are a web master or a web developer that takes SEO (Search Engine Optimization) techniques into consideration, you will probably want to use different sets of page title and keywords and description meta tags for every page in your web application.
There was not a way known and implemented for the Community Server as far as I known in order to define title and meta tags for everypage.
I have implemented a way by using the Response.Filter() method to over come this cons of the Community Server.
Use MS SQL Server 2005 Database to Implement the Solution
In order to apply different sets of meta tags for every page, these pre-defined sets should be stored in a database.
For my case, I chosed a Microsoft SQL Server database to keep page url, page title, keywords meta tag, etc. in a MS SQL Server database table.
This sql database table is very simple in structure. A table column named "page_url" to keep the unique url address of each page.
And then a title column named "title" which will be storing the title of the page whose web address is kept in the page_url column.
Then the "page_keywords" column which will keep the keywords list with related to the web page. All three table columns are sharing the same sql database type nvarchar(max) since I'm using a MS SQL Server 2005 instance database.
Here is the table creation sql script that you can use for your tests:
Create Table MyCSPages (
page_url nvarchar(max) not null
And I insert page url, title and keyword attributes by using t-sql INSERT statements as below:
After data related with pages that we want to handle title and meta tags we should create a stored procedure to select data related with a specific page url.
Create PROC ReadPageData
@URL as nvarchar(4000)
SELECT * FROM MyCSPages (NoLock) WHERE LOWER(page_url) = LOWER(@URL)
You see we have completed the database implementation for our task. It is so easy till here. What is time consuming is determining the title and the keywords.
You can use Google's Keyword Tool in order to guide you and suggest keywords considering your page's content.
Now it is time to implement the .NET code part for completing the solution.
Create an Assembly File which Inherits from System.IO.Stream Class and Call it using Response.Filter in the Community Server Pages
.NET related codes we will implement is formed of an assembly which we will build soon and place it in the bin folder of the Community Server web site application and also a a few lines of code block which we will place into the main master page of the application.
Because it is easy to explain and display how it is implemented in the master page, I'll try to note here the code block.
Open master file Master.ascx which can be found at "\Themes\default\Masters" folder.
After you open master file for editing using an editor, add the below Import directive at the top of the page where the other Import directives are placed
<%@ Import Namespace="HTMLMetaFilter" %>
And add the below VB.NET code script into the end of the master.ascx file.
protected void Page_Load(object sender, EventArgs e)
string pageURL = Page.Request.Url.ToString();
Response.Filter = new HTMLMetaFilter(Response.Filter, pageURL);
Now it is time for implementing Response.Filter() method. Create a new class project using Microsoft Visual Studio.NET 2003 or Visual Studio 2005 or VS2008.
It is actually up to your application Microsoft .NET Framework version. I created my assembly using VS2005 since I'm running the .NET Framework 2.0 I guess.
I named my project HTMLMetaFilter. And the project actually consists of an app.config configuration file and a class file HTMLMetaFilter.vb which actually keeps the necessary .NET codes.
app.config file keeps the database connection string in it.
<setting name="DBConnectionString" serializeAs="String">
The HTMLMetaFilter class should inherit from System.IO.Stream class. You can find the HTMLMetaFilter.vb for download from Files section.
All the methods should be left unchanged except the Write sub-routine. You can alter the codes and methodology here in this sub in order to serve for reaching your target.
Public Overrides Sub Write(ByVal buffer() As Byte, ByVal offset As Integer, ByVal count As Integer)
' Retrieve HTML Code
Dim HTML As String = System.Text.Encoding.UTF8.GetString(buffer, offset, count)
' Define Parameters
' You can add more or also read this values from database
Dim strTitleToBeReplaced As String = "<title>Community Server</title>"
Dim strToBeReplaced As String = "<meta name=""GENERATOR"" content=""CommunityServer 2.0 (Build: 60217.2664)"" />"
Dim strToReplace As String = String.Empty
Dim strTitleToReplace As String = String.Empty
' Connect to Database in order to Read Page Title and Keywords, etc we have defined earlier
Dim rd As SqlDataReader
Dim sqlConn As SqlConnection = New SqlConnection(My.Settings.DBConnectionString.ToString)
Dim sqlCmd As SqlCommand = New SqlCommand("ReadPageData", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add("@URL", SqlDbType.NVarChar, 4000).Value = Path
rd = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If rd.Read Then
strToReplace = rd("page_keywords").ToString
strTitleToReplace = rd("title").ToString
' Replace unwanted title and meta tags with values read from database specific to the current page
HTML = HTML.Replace(strToBeReplaced, strToReplace).Replace(strTitleToBeReplaced, strTitleToReplace)
If Not rd.IsClosed Then
rd = Nothing
sqlConn = Nothing
sqlCmd = Nothing
' End of Database Operations
' Return updated HTML codes
buffer = System.Text.Encoding.UTF8.GetBytes(HTML)
Me.Base.Write(buffer, 0, buffer.Length)
As I have commented in the above code block which forms the HTMLMetaFilter class Write method, first we retrieve HTML code prepared.
Then connect to database and read desired values using stored procedure named ReadPageData and pass the page url as parameter to the SQL Server sp.
Then just using String.Replace method, we replace current title with title column value from database table. Same also true for the meta tags, just replace them with values from sql db table.
Last step is just returning back the altered HTML codes for response to the client.
So, as a summary Response.Filter() method can be helpful as you have seen for Kodyaz.com case to define page titles and specific keywords and meta tags related to the content of each page.
I believe according to your needs, you can implement similar methods to overcome this SEO problem in Community Server web sites.
The sample codes and the sample project files can be downloaded from Change Community Server Page Title and Keywords Files download section of Kodyaz.com.