#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2007
    Posts
    1
    Rep Power
    0

    Error with install of asp.net advertising code on asp.net coded web pages


    I'm trying to install ads from Text Link Ads on my site's homepage (malluspace.com) and on one interior page. My site is coded in ASP.net. I've included screenshots of the install instructions from Text Link Ads as well as the error I get on my site when I install their code.

    I've followed the instructions as best as I know how. I created the 'Controls' directory and inserted the 2 files they provided. I uploaded the xml file they specified and had my host give it write access.

    http://www.malluspace.com/tla_install_instructions.JPG

    http://www.malluspace.com/malluspace_tla_error.JPG

    Below is provided the contents of the 2 files they provide (*.ascx and *.ascx.cs)

    Can anyone figure it out?


    textLinkAds.ascx
    Code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="textLinkAds.ascx.cs" Inherits="textLinkAds" %>
    <asp:Literal runat="server" ID="litTextLinkAds" Visible="true" />

    textLinkAds.ascx.cs
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;
    
    public partial class textLinkAds : System.Web.UI.UserControl
    {
    	// these values may be overridden with the control tag, e.g.:
    	//
    	private string strTextLinkAdsID = "128725"; //usually a 5-digit string
    	private string strTextLinkAdsInventoryKey = "FRFZ3CZD9UEAWC6W0X92"; //long alphanumeric string
    	private bool bDebuggingOn = false; // set to false to suppress error messages
    
    
    	// do not edit below this point
    
    	public string textLinkAdsID
    	{
    		get { return strTextLinkAdsID; }
    		set { strTextLinkAdsID = value; }
    	}
    
    	public string textLinkAdsInventoryKey
    	{
    		get { return strTextLinkAdsInventoryKey; }
    		set { strTextLinkAdsInventoryKey = value; }
    	}
    
    	private StringBuilder sb = new StringBuilder();
    	private bool bLinksPresent = false;
    
    	protected void Page_Load(object sender, EventArgs e)
    	{
    		try
    		{
    			string LOCAL_XML_FILENAME = Server.MapPath("local_"+strTextLinkAdsID+".xml");
    			string sourceFile = @"http://www.text-link-ads.com/xml.php?inventory_key="+strTextLinkAdsInventoryKey+@"&referer=" + Server.UrlEncode(Request.ServerVariables["HTTP_REFERER"]) + "&user_agent=" + Server.UrlEncode(Request.ServerVariables["HTTP_USER_AGENT"]);
    			System.IO.FileInfo fi = new System.IO.FileInfo(LOCAL_XML_FILENAME);
    
    			System.DateTime DateMod = System.IO.File.GetLastWriteTime(LOCAL_XML_FILENAME);
    			System.DateTime DateNow = System.DateTime.Now;
    
    			string Contents = System.IO.File.ReadAllText(LOCAL_XML_FILENAME);
    
    			if (DateMod < DateNow.AddHours(-1) || fi.Length < 20)
    			{
    				System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sourceFile);
    				req.Timeout = 10000;
    
    				System.Net.WebResponse resp = req.GetResponse();
    				System.IO.Stream stream = resp.GetResponseStream();
    
    				System.Xml.XmlTextReader remoteReader = new System.Xml.XmlTextReader(stream);
    
    				System.Text.StringBuilder sb = new System.Text.StringBuilder();
    				sb.Append(@"<?xml version=""1.0"" encoding=""utf-8""?>");
    				sb.Insert(sb.Length, System.Environment.NewLine);
    				while (remoteReader.Read())
    				{
    					sb.Append(remoteReader.ReadOuterXml());
    				}
    				remoteReader.Close();
    
    				string Result = sb.ToString();
    
    				if (Result != "")
    					Contents = Result;
    
    				System.IO.File.WriteAllText(LOCAL_XML_FILENAME, Contents);
    
    				remoteReader.Close();
    			}
    
    			System.Xml.XmlTextReader reader = GetXML(LOCAL_XML_FILENAME);
    			try
    			{
    				System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    
    				doc.Load(reader);
    				System.Xml.XmlElement root = doc.DocumentElement;
    
    				sb.Append(@"<ul style=""border: 1px solid #FF0000; border-spacing: 0px; background-color: #FFFFFF; overflow: hidden; margin: 0; width: 100%; list-style: none; padding: 0;"">");
    
    				if (root.HasChildNodes)
    				{
    					for (int i = 0; i < root.ChildNodes.Count; i++)
    					{
    						string sURL = "";
    						string sText = "";
    						string sBeforeText = "";
    						string sAfterText = "";
    
    						System.Xml.XmlNode xnNodeTop = root.ChildNodes[i];
    
    						if (xnNodeTop.HasChildNodes)
    						{
    							bLinksPresent = true;
    							for (int z = 0; z < xnNodeTop.ChildNodes.Count; z++)
    							{
    								System.Xml.XmlNode xnNodeChild = xnNodeTop.ChildNodes[z];
    
    								if (xnNodeChild.Name == "URL")
    									sURL = xnNodeChild.InnerXml;
    								if (xnNodeChild.Name == "Text")
    									sText = xnNodeChild.InnerXml;
    								if (xnNodeChild.Name == "BeforeText")
    									sBeforeText = xnNodeChild.InnerXml;
    								if (xnNodeChild.Name == "AfterText")
    									sAfterText = xnNodeChild.InnerXml;
    							}
    						}
    						sb.Append(@"<li style=""padding: 0; float: left; display: inline; clear: none; margin: 0; width: 13%;""><span style=""color: #000000; font-size: 12px; display: block; width: 100%; padding: 3px; margin: 0;"">" + sBeforeText + @" <a style=""font-size: 12px; color: #FF0000;"" href=""" + sURL + @""">" + sText + "</a> " + sAfterText + "</span></li>");
    					}
    				}
    
    				sb.Append("</ul>");
    			}
    			catch (Exception ex)
    			{
    				if (bDebuggingOn)
    					sb.Append("Error displaying xml file:<p>" + ex.Message + "</p><p>" + ex.Source + "</p><p>" + ex.StackTrace + "</p>");
    			}
    			finally
    			{
    				reader.Close();
    			}
    		}
    		catch (Exception ex)
    		{
    			if (bDebuggingOn)
    				sb.Append("Error displaying xml file:<p>" + ex.Message + "</p><p>" + ex.Source + "</p><p>" + ex.StackTrace + "</p>");
    		}
    
    		litTextLinkAds.Text = sb.ToString();
    		if (!bDebuggingOn && !bLinksPresent)
    			litTextLinkAds.Visible = false;
    	}
    
    	private System.Xml.XmlTextReader GetXML(string Path)
    	{
    		System.Xml.XmlTextReader reader = null;
    
    		if (System.IO.File.Exists(Path))
    		{
    			try
    			{
    				reader = new System.Xml.XmlTextReader(Path);
    			}
    			catch (Exception e)
    			{
    				if (bDebuggingOn)
    					sb.Append("Error displaying xml file - GetXML function:<p>" + e.Message + "</p><p>" + e.Source + "</p><p>" + e.StackTrace + "</p>");
    			}
    		}
    		return reader;
    	}
    }
  2. #2
  3. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925

Similar Threads

  1. Global code and functions in ASP.net
    By Jelly2003 in forum .NET Development
    Replies: 3
    Last Post: April 23rd, 2004, 03:56 AM
  2. Using ASP.NET in Visual Studio.NET
    By Red in forum ASP Development
    Replies: 6
    Last Post: April 7th, 2004, 03:30 PM
  3. Running asp.net pages (aspx)
    By Mosha in forum .NET Development
    Replies: 6
    Last Post: April 6th, 2004, 06:15 AM
  4. Common Banner/Navigation bar in several ASP.NET pages
    By jveron23 in forum .NET Development
    Replies: 0
    Last Post: February 7th, 2004, 09:57 AM
  5. Problem passing a value to an asp.net page
    By PalmDrac in forum .NET Development
    Replies: 4
    Last Post: March 5th, 2003, 03:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo