Better control of SEO and Sections

Developer
Dec 3, 2009 at 6:15 PM

Hi fellows of MWPSK contrib project

I will suggest a small change of the rewrite engine in Global.asax, that can be added without disturbing other Sections.
Below is a snippet of how we can catch the url from web.config and forward it to the wanted Section. If no match is found, the original rewrite get's the request.
In this way we can use an url like : domain.com/news/my-news.aspx where my-news.aspx is a virtual page from the News Section.
Each news item will have it's own page with Title , description, keywords, page name etc.
It doesn't affect the performance of the website.

When we build a new section, we can have in mind that we can use this new rewrite in for eg. News, Forum, Products etc.
I can make a post with complete implementation if this sounds interresting.

Below in Global.asax  in Application_AuthorizeRequest

        string currentURL = base.Request.Path.ToLower();
        
        NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("rewrite/sections");
        string[] keys = config.AllKeys;
        string val = null;
        string id = null, pg = null;
        
        foreach (string key in keys)
        {
            if (currentURL.Contains(key))
            {
                val = config[key];

                List<ISection> sections = SectionLoader.GetInstance().LoadSections(val);
                
                foreach (ISection section in sections)
                {
                    if (section.GetType().Name.Equals(val))
                    {
                        foreach (System.Data.DataRow row in section.Entries.Rows)
                        {
                            if (row["RewriteUrl"].ToString().ToLower() == currentURL.Replace(key, ""))
                            {
                                id = row["Guid"].ToString();
                                pg = row["PageID"].ToString();
                                
                                Context.RewritePath(string.Format("/default.aspx?pg={0}&details={1}", pg, id), rebase);
                                break;
                            }
                        }
                    }
                }
            }
        }

if(val==null){//original rewrite}
In web.config:

The key is the url to catch, the value is the Section class to send the rewrite to.
<rewrite>
    <sections>
      <add key="/news/" value="News"/>
      <add key="/products/" value="Product"/>
    </sections>
  </rewrite>
Only requirement is that this Section can return a DataTable "Entries". that must contain a "RewriteUrl" and "PageID".
 
In ISection interface add:
 
DataTable Entries{ get; }
In Section class add:
 
public virtual DataTable Entries 
{ 
            get{
                return null; //This has to be overidden in Section that will use the rewrite.
        } 
} 
The sectionLoader also need to return a list of ISection.
 
Tell me what you think.
Regards //Rickard