Forum Moderators: open
With Perl/CGI, you can call a remote .cgi script by inserting an <IMG> tag in an HTML page, which calls as its SRC a .cgi script, which in turn returns either an image or an image URL location. A typical example is a web page hit counter.
I have noticed that with the www.sitemeter.com web counter, the <IMG> tag calls an .asp script, which does the same thing as the above .cgi script. (I know that this site uses ASP and not ASP.NET, but presumably ASP.NET can provide the same functionality.)
I wish to do the same thing. That is, I want to call a remote ASP.NET script from within a static HTML page, which returns either an image or image URL, or, preferrably, nothing at all (the call simply executes the script, with the script not returning anything).
If it's important to know, my ASP.NET code is indeed a hit counter, but one that provides specific details necessary for the site it supports.
What, and how, does my ASP.NET code return an image or image URL, or nothing, to the calling HTML file?
If anyone can help, a thousand thanks. (Well, actually, 999 thanks, since I thanked the receptionist for making me a coffee this morning.)
Cheers!
Imports System.Drawing.Imaging
Imports System.Drawing.Brush
Public Class counter
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put your counter i ma just using rand number
Dim sNumber As String = Right(Rnd().ToString, 6)
GetCounter(sNumber)
Response.Write("Document.write '<IMG src=Pictures/counter.gif>'")
Response.End()
End Sub
Private Function GetCounter(ByVal sNumber As String) As String
'creates image with counter 40*15 gif
Dim objImage As Bitmap
objImage = New Bitmap(40, 15)
Dim objGraphics As Graphics
objGraphics = Graphics.FromImage(objImage)
'set font
Dim objFont As Font = New Font("Verdana", 10, FontStyle.Bold)
objGraphics.DrawString(sNumber, objFont, Brushes.White, 1, 0)
'save image
objImage.Save("c:\inetpub\wwwroot\aoa\pictures\counter.gif", ImageFormat.Gif)
Return sNumber
End Function
End Class
then you can call this page as javascript from any html page
using
<script language="javascript" src=counter.aspx></script>
I hope it will help
I genuinely appreciate your help.
However, I do not use Visual Studio ... I am stuck with a text editor.
As a result, I have not been able to get your sample code working (partly, I think, because I cannot generate a well-formed webform).
I have now spent 90 minutes trying different things ... but to no avail.
Is it possible, and I am sorry for asking, for you to show me the *complete* aspx code, and the complete html code? (I'm hoping that this is easy, and you only gave me truncated code in order to keep your reply short and to the point.)
If you're able to help further, an even bigger thanks is due.
Until then ... here's my standard-size thanks ... thanks!
I hope it will help
P.S.
MS offers WYSIWYG application development tool for ASP.NET. It is free and better than notepad.
[asp.net...]
First, thank you for taking the time to provide me with the complete codes.
It transpired - and I write this for anyone who comes across this issue/problem - that running your script returned a "Server Application Unavailable" error.
Only a little bit of research showed that this was due to a security setting on the host machine (in this case, being my own workstation).
To get the script running, you open up the machine.config file found at c:\winnt\Microsoft.NET\Framework\v1.0.3705\CONFIG). Search for the string "<processmodel" NOTE: no closing tag, or it goes to another section of this config file.
Change userName="machine" to userNAME="SYSTEM".
Then, without rebooting, the script worked as advertised.
Well, actually, I did have to change the line:
Response.Write("document.write(""<IMG src=Pictures/counter.gif>"")")
to
Response.Write("<IMG src=Pictures/counter.gif>")
On my machine at least, the javascript inside the .aspx file does not execute, so the document.write appeared as text on the webpage.
None of this is criticism ... I only post this extended response for anyone following this thread now or later.
Tomasz, I genuinely appreciate your replies, which enabled me to do *exactly* what I wanted.
I'd give you a big kiss, but I'm not gay, and you're probably on the other side of the world :)
Instead, I give you a big THANK YOU!
I was wrong is saying that I needed to change your line:
Response.Write("document.write(""<IMG src=Pictures/counter.gif>"")")
as the Javascript is indeed needed. Oops.
And, thanks for pointing me to Microsoft's Matrix. I do already have this program. I only said that I have a "text editor" because I was hoping any replies would show the code, not which buttons to press in a WYSIWYG application.
It is only by seeing the code (thank you Tomasz) that I will learn.