search engines and ASP

H

Hugh Welford

Hi,

I am planning to have my default page as an asp so as to keep an
accurate hit counter and then redirect to the site using the following code
placed in the body of the page.
<%
application.lock
application("counter")= application("counter") + 1
application.unlock
response.redirect "default_home.htm"%>

Is this a valid way to do this? More importantly, will it still allow the
search engines to read the title, description, keywords etc meta tags, or
will it re-direct them before indexing this page?

Thanks Hugh
 
K

Kevin Spencer

Hi Hugh,

You're heading in the right direction, but first you need to make a few
considerations.

You say that you're making your default home page file name "default.asp" so
that you can get a count of the hits to this page. However, you're
redirecting to "default_home.htm" for no apparent reason. If you're counting
on this page, why not put your content on this page as well? The redirect is
a waste of resources and user's time. Also, your method will not yield any
accurate statistics, since it requires the user to go to the default home
page in order to be counted. What happens when, for example, a user creates
a bookmark to one of your pages and goes directly there wihtout going to
your home page? Nothing, because your counter is on that one page, and that
page only.

First, therefore, you need to decide what exactly it is you want to count.
Do you want to count the specific number of times that a user requests a
certain page? That's what your current code will do. It will keep track of
each and every hit to a single page. Most often, what is useful to the
Webmaster is the number of unique User Sessions on the site (visits to
various pages on the site within a single Browser Session) happen in a day
or over a period of time. I will assume that User Sessions is what you want
to count, and that you don't want to count only a single page, but the
entire Session.

To do this, you need to use a Global Event Handler. In ASP, there are 3 that
we will want to look at: Application_OnStart, Session_OnStart, and
Session_OnEnd. In your code, for example, you are trying to increment an
Application variable. Where does it get created/initialized? This would be
in the Application_OnStart Sub:

Application("counter") = 0

Now, in order to count the User Session, we use the Session_OnStart sub,
which fires exactly ONCE per User Session, and is not page-specific.
Regardless of which page a user requests, this Sub in the global.asa file is
fired:

Application.Lock
Application("counter") = Application("counter") + 1
Application.Unlock

Now, keep in mind that Application variables are stored in memory, so you
want to think about persisting this data somewhere, depending on what
exactly you want to do with it. This can be done by writing it to a text
file, database, or any other persistent storage medium.

If you want to keep track of how many users are currently online with your
site, you can user another variable and the Session_OnEnd Sub. In the
Application_OnStart Sub, you create and initialize a variable like we did
with the "counter" variable:

Application("UsersOnline") = 0

In the Session_OnStart:

Application.Lock
Application("UsersOnline") = Application("UsersOnline") + 1
Application.Unlock

In the Session_OnEnd Sub:

Application.Lock
Application("UsersOnline") = Application("UsersOnline") - 1
Application.Unlock

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
M

Mike Mueller

Last week I changed the default for the root of my web to default.asp from
default.htm. I shared the concerns that you have regarding the search
engines. Google apparently did its crawl over the weekend to my site and
now default.htm is gone and default.asp is right where it .htm was.
Besides the previous message, you just may want to place all the content
from your htm page onto the asp page.

Mike
 
H

Hugh Welford

Hi Kevin...thanks for your in-depth reply. Sure looks as if I should take
your advice.

Hugh
 
J

Jon Spivey

Hugh,
you might also want to bear in mind that search engines don't normally
follow redirects. Sounds to me like you should make you home page
default.asp and lose the redirect altogether, if you do have a good reason
for wanting to redirect use server.transfer in place of response.redirect -
at least this way the search engines will find their way to your home page.
With the redirect as you have it they'll never get there

Jon
Microsoft MVP - FP
 
H

hugh Welford

HI again Kevin,
Reading your message again, I am a little confused over your assertion "keep
in mind that Application variables are stored in memory"

Application variables last for the duration of the application on the
server, dont they? And if so, given the temporary nature of memory, shouldnt
they then be stored on the server in the application itself (in the
applicaton virtual directory??). Its no problem to save my updated
application variable ("count") in a database table, but doesnt that make the
concept of application scope variables pointless?

I'd be very grateful if you could clear this up for me. Thanks Hugh
 
K

Kevin Spencer

Hi Hugh,

Application variables are just that - variables. They exist in the
Application memory space, which exists for the lifetime of the Application.
You are correct in that memory is volatile, and for example, an ASP
Application will stop after a long enough period of time without requests,
and all Application variables are lost when this happens. The next request
spawns a new Application, and the variables must be re-initialized. This is
the nature of memory and of the ASP Application object.

However, as to how Application variables "should" be stored, well, that's
not exactly in our hands, since we didn't create ASP. However, it was
architected correctly. In fact, if you want to store a value somewhere where
it will persist, using a database or other HD storage is recommended. This
doesn't negate the importance and usefulness of the Application memory
space. It simply defines which object serves which purpose.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
H

Hugh Welford

thanks Kevin

Hugh


Kevin Spencer said:
Hi Hugh,

Application variables are just that - variables. They exist in the
Application memory space, which exists for the lifetime of the Application.
You are correct in that memory is volatile, and for example, an ASP
Application will stop after a long enough period of time without requests,
and all Application variables are lost when this happens. The next request
spawns a new Application, and the variables must be re-initialized. This is
the nature of memory and of the ASP Application object.

However, as to how Application variables "should" be stored, well, that's
not exactly in our hands, since we didn't create ASP. However, it was
architected correctly. In fact, if you want to store a value somewhere where
it will persist, using a database or other HD storage is recommended. This
doesn't negate the importance and usefulness of the Application memory
space. It simply defines which object serves which purpose.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

track would
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top