Page 1 of 1

MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 8:28 am
by AlanW
We've been using the MetaTags.aspx utility (code posted Aug 13, 2008 )

viewtopic.php?f=42&t=7875&hilit=metatags.aspx


Since we upgraded to 7.0.3 the page throws this error. What needs to change in the metatags.aspc code to patch up this page?

Code: Select all

Exception of type 'System.Web.HttpUnhandledException' was thrown.; Object reference not set to an instance of an object.
Best regards,
Alan

Re: MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 8:46 am
by mazhar
Could you post your page here in this post. I tried scotts code and its still working with 7.0.3. It seems either there is something custom in your page or I am missing something.

Re: MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 9:18 am
by AlanW
Here's the MetaTags.aspx code we've been using.

Code: Select all

<%@ Page Language="C#" MasterPageFile="Product.master" Title="Meta Tags" Inherits="CommerceBuilder.Web.UI.AbleCommerceAdminPage" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">

    int _ProductId;
    Product _Product;
    
    protected void Page_Load()
    {
        if (!Page.IsPostBack)
        {
            Populate();
        }
    }

    protected void SaveHeader(Object s, EventArgs e)
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        _Product.HtmlHead = HTMLBox.Text;
        _Product.Save();
        Populate();
    }

    protected void RegenerateHeader(Object s, EventArgs e)
    {
        String Header = "";
        Header += "<title>" + PageTitle.Text + "</title>" + Environment.NewLine;
        Header += "<meta name='description' content='" + MetaDescription.Text + "'>" + Environment.NewLine;
        Header += "<meta name='keywords' content='" + MetaKeywords.Text + "'>" + Environment.NewLine;
        HTMLBox.Text = Header;
    }

    protected void Populate()
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        int titleStart;
        int titleEnd;
        int descStart;
        int descEnd;
        int keyStart;
        int keyEnd;
        String Header = "";
        String TitleTag = "";
        String MetaDesc = "";
        String MetaKey = "";
        Header = _Product.HtmlHead;
        if (Header.Length > 0)
        {
            titleStart = Header.IndexOf("<title>") + 7;
            titleEnd = Header.IndexOf("</title>");
            if (titleStart > 0 && titleEnd > 0 && titleEnd > titleStart)
                TitleTag = Header.Substring(titleStart, titleEnd - titleStart);
            descStart = Header.IndexOf("<meta name='description' content='") + 34;
            descEnd = Header.IndexOf("'>", descStart);
            if (descStart > 0 && descEnd > 0 && descEnd > descStart)
                MetaDesc = Header.Substring(descStart, descEnd - descStart);
            keyStart = Header.IndexOf("<meta name='keywords' content='") + 31;
            keyEnd = Header.IndexOf("'>", keyStart);
            if (keyStart > 0 && keyEnd > 0 && keyEnd > keyStart)
                MetaKey = Header.Substring(keyStart, keyEnd - keyStart);
        }
        HTMLBox.Text = Header;
        PageTitle.Text = TitleTag;
        MetaDescription.Text = MetaDesc;
        MetaKeywords.Text = MetaKey; 
    }
    
    

</script>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="pageHeader">
    <div class="caption">
        <h1><asp:Localize ID="Localize1" runat="server" Text="Meta Tags"></asp:Localize></h1>
    </div>
<div class="Content" style="padding:40px; border:1px solid blue;">
    <table width="90%">
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="HTMLBoxLabel" runat="server" Text="HTML Header"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="HTMLBox" TextMode="MultiLine" runat="server" Columns="100" Height="100"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="TitleLabel" runat="server" Text="Title Tags"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="PageTitle" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="MetaDescriptionLabel" runat="server" Text="Meta Description"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="MetaDescription" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="MetaKeywordsLabel" runat="server" Text="Meta Keywords"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="MetaKeywords" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
    </table>
    <center>
        <asp:Button ID="Regenerate" Text="Regenerate Header" runat="server" OnClick="RegenerateHeader" />
        &nbsp;&nbsp;
        <asp:Button ID="SaveIt" Text="Save" runat="server" OnClick="SaveHeader" />
    </center>
</div>
  
</asp:Content>

Re: MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 9:34 am
by mazhar
Just tried your code and its working no null reference exception. Could provide some detailed information about reproduction case input values etc.

Re: MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 10:02 am
by AlanW
The file is located in Admin/Products/ folder

We had to enter a link to MetaTags.aspx again in menu.sitemap after update to 7.0.3
Here is code from menu.sitemap where we call MetaTags.aspx from Admin menu.

Code: Select all

 <siteMapNode title="Catalog" LookId="TopItemLook" roles="System,Admin,Jr. Admin,Manage Catalog">
      <siteMapNode title="Browse" url="~/Admin/Catalog/Browse.aspx" />
      <siteMapNode title="Search" url="~/Admin/Catalog/Search.aspx" />
      <siteMapNode title="Digital Goods" url="~/Admin/DigitalGoods/Default.aspx" Look-RightIconUrl="arrow.gif">
        <siteMapNode title="Manage Digital Goods" url="~/Admin/DigitalGoods/DigitalGoods.aspx" />
        <siteMapNode title="Digital Good Files" url="~/Admin/DigitalGoods/DigitalGoodFiles.aspx" />
        <siteMapNode title="Find Digital Goods" url="~/Admin/DigitalGoods/FindDigitalGoods.aspx" />
        <siteMapNode title="Readmes" url="~/Admin/DigitalGoods/Readmes.aspx" />
        <siteMapNode title="License Agreements" url="~/Admin/DigitalGoods/Agreements.aspx" />
      </siteMapNode>
      <siteMapNode title="Find Kits" url="~/Admin/Products/Kits/Search.aspx" />
      <siteMapNode title="Product Templates" url="~/Admin/Products/ProductTemplates/Default.aspx"></siteMapNode>
      <siteMapNode title="Gift Wrap" url="~/Admin/Products/GiftWrap/Default.aspx" />
      <siteMapNode title="MetaTags" url="~/Admin/Products/MetaTags.aspx" />
      <siteMapNode title="Orphaned Items" url="~/Admin/Catalog/OrphanedItems.aspx" />
    </siteMapNode>
When we click MetaTags link in Administration > Catalog Menu the page goes to our default error page. Error log show debug message..

Code: Select all

"Exception of type 'System.Web.HttpUnhandledException' was thrown.; Object reference not set to an instance of an object."

Re: MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 10:20 am
by mazhar
You are providing an invalid link containing no product id.
~/Admin/Products/MetaTags.aspx
that's why MetaTags tries to load product with id 0 and hence null reference exception.

Correct URL should be something like following
~/Admin/Products/MetaTags.aspx?ProductId=42

MetaTags page is with respect to each product so you must not hard code its link in menu control because that's something specific to product and its URL will depend upon product being edited. Best location for its link is the left navigation in Edit Product page. Download attached zip file extract it. It contains the modified left nav available on admin product pages with meta tags entry. If you haven't modified your Admin/Products/ProductMenu.ascx and Admin/Products/ProductMenu.ascx.cs files then you can just replace them with this one.

Re: MetaTags.aspx throws error in 7.0.3

Posted: Mon Jun 15, 2009 10:39 am
by AlanW
Thanks Mazhar,

OK, now I see how Admin menu choices were set up incorrectly.
Thanks for explanation and posted files.
MetaTags utility is working again.


Best regards,

Alan