Its also possible to generate the IDs at runtime.

Basically is comes down to, with a few locks here and there...

int GetPageID()
{
  pageid = get id from cache ( AppRelativeCurrentExecutionFilePath )

  if not in cache
  {
     // get id from db creates a new id if page was not seen before
     pageid = get id from db ( AppRelativeCurrentExecutionFilePath )
     store id in cache ( AppRelativeCurrentExecutionFilePath, pageid)
  }

  return pageid
}

HTH
// Ryan

On 7/11/07, Daniel Barla-Szabo <[EMAIL PROTECTED]> wrote:
Hi,

There are two problems that I see here:

1.  Shortening the url / string that you are using GetHashCode() on isn't
going to make the hash code any smaller.  Try it on something like this to
see:

int i = "a".GetHashCode();

2.  If you do manage to get a hashing algorithm which brings down your int
"length" to an acceptable size, you will start to get collisions, i.e. you
will have multiple pages with the same hash code.  The smaller the int, the
higher the probability.


If you absolutely must do this, I would recommend some scheme like this: set
up a script which runs though the folders, looking for the .aspx files, and
then assigning them each a small unique number (like an identity column from
a DB), and writing the results to DB.  The system can then translate the URL
into a short int, without any collisions.  You must then obviously get the
call operators to search this table for the relevant page, and it's probably
a good idea to cache the relationship in the application as a hashtable /
dictionary.

You will need to be careful to write the script in such a way that it
doesn't re-assign numbers for urls which are already known / assigned.  This
will help avoid scenarios where an entire range shifts up, and all your
logged incidents are all of a sudden against the wrong page.

HTH

Regards,
Daniel


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Cowan
Sent: 11 July 2007 04:52 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Url generated int

Hi,

What we want is a short int that we will put on the bottom of each page so
users can call operators and identify the page in question by this human
readable integer.  In the same way as each page in a book has a page number.

We could keep a big xml look up or something like that we could cache but
the maintenance is unacceptable.

I would like to be able to generate this number somehow.  I was thinking of
something like the following:

string urlToHash = string.Empty;
for (int i = 0; i < Request.Url.Segments.Length; i++)
{
   string candidate = Request.Url.Segments[i].Replace("/",
"").Replace(".aspx", "");
   if (candidate.Length == 0)
       continue;
   urlToHash += candidate;
}
int hashCode = urlToHash.GetHashCode();
The number is still quite big but I might go with this.

Is there anything other than GetHashCode I could use?

Cheers

Paul
[EMAIL PROTECTED]



> Date: Wed, 11 Jul 2007 16:46:08 +0200> From: [EMAIL PROTECTED]>
Subject: Re: [ADVANCED-DOTNET] Url generated int> To:
ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> > Hi Paul,> > What's wrong with that
integer?> What about using an hashtable-structure instead? Would it be
possible,> giving your requirements?> > --> Efran Cobisi>
http://www.cobisi.com> > Paul Cowan wrote:> > Hi,> >> > I have a flowing
quandary that I am struggling with. The long and the short of it is that we
have the usual mix of static and dynamic pages for our ASP.NET 2.0 web
site.> >> > What we need is a way of identifying each page on the site. The
dynamic pages do not really worry me. What I would like to do is be able to
identify each page with an int.> >> > The first thing that sprung to mind
was:> >> > Request.Url.GetHashCode();> >> > This unfortunately brings back:>
>> > -81369726> >> > For the folloiwng URL:> >> >
http://localhost/ak/misc/sendtoafriend.aspx> >> > Can anyone think of a
better way to generate a unique integer which we can tag our pages with? The
only thing really unique is the url.> >> > Thanks> > [EMAIL PROTECTED]>
> _________________________________________________________________> > Try
Live.com - your fast, personalised homepage with all the things you care
about in one place.> > http://www.live.com/?mkt=en-gb> >
===================================> > This list is hosted by DevelopMentor(r)
http://www.develop.com> >> > View archives and manage your subscription(s)
at http://discuss.develop.com> >> > ===================================>
This list is hosted by DevelopMentor(r) http://www.develop.com> > View
archives and manage your subscription(s) at http://discuss.develop.com
_________________________________________________________________
Feel like a local wherever you go with BackOfMyHand.com
http://www.backofmyhand.com
===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.10.2/894 - Release Date: 2007/07/10
05:44 PM


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.10.2/894 - Release Date: 2007/07/10
05:44 PM


===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to