1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Validating on .NET

Discussion in 'Co-op Advertising Network' started by rdouglass, Oct 16, 2008.

  1. #1
    Hi Folks,

    Anyone have any hints as to validating on ASP.NET sites? I have code that validates on some of my PHP sites and my ASP sites but I cannot get any ASP.NET sites to validate.

    I am using ASP code to grab the ads and displaying them using a HttpWebRequest object.

    I can see the ads just fine on the page and an example of the displayed code looks like:

            <span id="ctl00_lblSubAd"><img src="http://ads.digitalpoint.com/t-148043-20438-148043-134387-134387.gif" width="1" height="1"><a href="http://www.moneyextra.com" />Credit</a> | <a href="http://www.supersizeme.com/" />McDonalds</a> | <a href="http://www.moneyextra.com" />Credit</a> | <a href="http://www.moneyexpert.com/Compare-Credit-Cards.aspx" />Credit Cards UK</a> | <a href="http://www.moneyexpert.com/Compare-Credit-Cards.aspx" />Credit Cards UK</a></span>
    
    Code (markup):
    That looks just fine to me. The HttpWebRequest .NET code goes like this:

                Dim myRequest As HttpWebRequest = CType(WebRequest.Create("http://www.servicefinders.net/ad_network_360.asp"), HttpWebRequest)
    
                myRequest.MaximumAutomaticRedirections = 10
                myRequest.MaximumResponseHeadersLength = 10
    
                Dim myResponse As HttpWebResponse = CType(myRequest.GetResponse(), HttpWebResponse)
    
                Dim receiveStream As Stream = myResponse.GetResponseStream()
    
                Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)
    
                 Dim myTempStr As String = readStream.ReadToEnd.ToString
     
                myResponse.Close()
                readStream.Close()
    
                lblSubAd.Text = myTempStr
    
    Code (markup):
    And the lblSubAd is the .NET label where the ads are actually written on the .ASPX page.

    The ASP page looks like this:

    <%
    dim ad_params
    
    'Set num_ads to the number of ads you want to display.
    'Set ad_separator to the separator you want between ads.
    const num_ads = 5
    const ad_separator = " | "
    
    Function ad_network()
    	dim ad_ids()
    	dim ad_type, ad_url, ad_file, AllLinks, NewTextLinks, objTextStreamR, objTextStreamW, newlink, spParam, LinksDate, i, NewTextLink, attempt, r, j
    	dim objFSO, fso, stream, displayAds(), data
    	'on error resume next
    
    	Randomize()
    
    	Const root_path="\" 'the (writable) path to ad_network_ads.txt
    
    	ad_type = "text" '"link" for text link | "text" for text banner | "" (empty) for graphical banner
    	ad_url = "http://ads.digitalpoint.com/network.php?c=" & Request.ServerVariables("SERVER_NAME") & "&type=" & ad_type
    	ad_file = Server.MapPath("/") & root_path & "ad_network_ads_412.txt" 'it must be a path with write privileges
    
    	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    	Set objTextStreamR = objFSO.OpenTextFile(ad_file,1,true)
    
    	If objTextStreamR.AtEndOfStream Then
    		'First Creation of cache file (5 ads)
    		NewTextLinks = GetNewLink(ad_url)
    		if NewTextLinks <> "" then NewTextLinks = "<ad_break>" & NewTextLinks
    
    		Application.Lock 'prevents other processes from changing file while writing
    		set fso = server.createobject("Scripting.FileSystemObject")
    		set stream = fso.opentextfile(ad_file,2,true)
    		stream.write ad_params & NewTextLinks
    		stream.close
    		set fso=nothing
    		Application.UnLock
    
    		spParam = split(ad_params,"|",-1,vbTextCompare)
    		if Request.ServerVariables("REMOTE_ADDR") = spParam(1) or Request.ServerVariables("SERVER_ADDR") = Request.ServerVariables("REMOTE_ADDR") then
    			NewTextLinks = Replace(NewTextLinks,""" />",""" class=""" & spParam(2) & """ />")
    		end if
    		displayAds = split(NewTextLinks,"<ad_break>")
    		redim preserve displayAds(num_ads - 1)
    	Else
    		AllLinks = split(objTextStreamR.ReadAll,"<ad_break>")
    		if instr(1,AllLinks(0),"|",vbTextCompare) = 0 then
    			newlink = GetNewLink(ad_url)
    			spParam = split(ad_params,"|",-1,vbTextCompare)
    			spParam(0) = AllLinks(0)
    			AllLinks(0) = ad_params
    		else
    			spParam = split(AllLinks(0),"|",-1,vbTextCompare)
    		end if
    		if IsDate(spParam(0)) then
    			LinksDate = cdate(spParam(0))
    		else
    			LinksDate = Now()
    		end if
    
    		If (UBound(AllLinks) <= spParam(3) + 1 and clng(datediff("s",LinksDate,now())) > clng(spParam(5))) or clng(datediff("s",LinksDate,now())) > clng(spParam(4)) Then 
    			NewTextLink = GetNewLink(ad_url)
    			if NewTextLink <> "" then
    				redim preserve AllLinks(UBound(AllLinks) + 1)
    				AllLinks(0) = ad_params
    				AllLinks(ubound(AllLinks)) = NewTextLink
    			end if
    
    			If ubound(AllLinks) > spParam(3) then
    				for i = 1 to spParam(3)
    					AllLinks(i) = AllLinks(i + 1)
    				next
    				redim preserve AllLinks(spParam(3))
    			End If
    
    			AllLinks(0) = Now() & mid(AllLinks(0),instr(1,AllLinks(0),"|",vbTextCompare))
    			
    			data = ""
    			For i = 0 to UBound(AllLinks)
    				data = data & AllLinks(i)
    				if i < UBound(AllLinks) then data = data & "<ad_break>"
    			Next
    
    			Application.Lock 'prevents other processes from changing file while writing
    			set fso = server.createobject("Scripting.FileSystemObject")
    			set stream = fso.opentextfile(ad_file,2,true)
    			stream.write data
    			stream.close
    			set fso=nothing
    			Application.UnLock
    			
    		End If 
    
    		'get 5 random non-duplicate ads
    		i = 0
    		
    		do while i < num_ads and i < UBound(AllLinks)
    			redim preserve displayAds(i)
    			redim preserve ad_ids(i)
    			attempt = 0
    			
    			'Select an ad
    			r = int(Rnd() * (UBound(AllLinks)) + 1)
    			
    			'Verify that the ad has not been selected before
    			for j = 0 to i - 1
    				if displayAds(j) = AllLinks(r) then
    					AllLinks(r) = ""
    					exit for
    				end if
    			next
    			
    			'If ad selected before find other (non preselected)
    			'Give it a maximum of 100 attempts
    			do while attempt < 100 and AllLinks(r) = ""
    				r = int(Rnd() * (UBound(AllLinks)) + 1)
    				for j = 0 to i - 1
    					if displayAds(j) = AllLinks(r) then
    						AllLinks(r) = "" 'If used before then blank
    						exit for
    					end if
    				next
    				attempt = attempt + 1
    			loop
    			
    			if Request.ServerVariables("REMOTE_ADDR") = spParam(1) or Request.ServerVariables("SERVER_ADDR") = Request.ServerVariables("REMOTE_ADDR") then
    				displayAds(i) = Replace(AllLinks(r),""" />",""" class=""" & spParam(2) & """ />")
    			else
    				displayAds(i) = AllLinks(r)
    			end if
    			
    			'Extract ids
    			dim tempAds
    			tempAds = split(displayAds(i), "<id>")
    			
    			if ubound(tempAds) > 0 then 'if <id> found then save the id
    				ad_ids(i) = tempAds(1)
    				displayAds(i) = tempAds(0)
    			end if
    			
    			i = i + 1
    		loop
    	End If
    	
    	dim printAds
    	printAds = join(displayAds, ad_separator)
    	
    	redim preserve displayAds(num_ads - 1)
    	if len(ad_ids(0)) then 'Only write Id image if Id's exist
    		Response.Write "<img src=""http://ads.digitalpoint.com/t-" & join(ad_ids, "-") & ".gif"" width=""1"" height=""1"">"
    	end if
    	
    	'ad_network = displayAds	'Print yourself
    	Response.Write printAds		'Print all at once
    	
    end function
    
    '-----------------------------------------------------------------------------------
    
    Private Function GetHTTPText(File)
    
    	if Application("LastCommsAttempt") = "" then
    		Application("LastCommsAttempt") = now
    	else
    		if datediff("s",Application("LastCommsAttempt"),now()) > 4 then
    			Application("LastCommsAttempt") = now
    		else
    			exit function
    		end if
    	end if
    	Dim wHTTP
    	Set wHTTP = server.CreateObject("Microsoft.XMLHTTP")
    	'whttp.settimeouts 2000,30000,30000,30000
    	wHTTP.Open "GET", File, false
    	wHTTP.Send
    	'If wHTTP.WaitForResponse(5) = True Then
    		GetHTTPText = wHTTP.ResponseText
    	'End If
    	Set wHTTP=nothing
    
    end function 
    
    '-----------------------------------------------------------------------------------
    
    Private Function GetNewLink(File)
    
    	dim ht, spLink
    	ht = GetHTTPText(File)
    	if ht <> "" then
    		if instr(1,ht,"<ad_param>",vbTextCompare) > 0 then
    			spLink = split(ht,"<ad_param>",-1,vbTextCompare)
    			ad_params = now() & "|216.9.35.51|" & spLink(0)
    			GetNewLink = spLink(1)
    		else
    			Application("LastCommsAttempt") = dateadd("s",100,now)
    			ad_params = now() & "|216.9.35.51|abcdefgh|400|900|4"
    		end if
    	else
    		if datediff("s",Application("LastCommsAttempt"),now()) > 5 then
    			Application("LastCommsAttempt") = dateadd("s",100,now)
    		end if
    		ad_params = now() & "|216.9.35.51|abcdefgh|400|900|4"
    	end if
    
    end function 
    
    dim ads
    ads=ad_network
    %>
    Code (markup):
    Which is exact code (with config changes) from a forum submitter on this site. The code is said to be "working code" by members of this forum and it does seem to be so.

    Everything looks fine to me (the ads display, the .GIF reference is there, etc.) but I just can't seem to figure out why it doesn't validate? Does anyone have any clues at all?

    EDIT: The URL is www(dot)servicefinders(dot)net
     
    rdouglass, Oct 16, 2008 IP