Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Saturday, March 31, 2012

seo question

Hi

can anyone tell me - if i have content stored in a database and its being displayed in GRIDVIEW on front page of website (like news) - is that content being picked up by bots/search engines etc?


cheers


Probably. :)

It will be read by any SEO that spiders your site, since the spider reads rendered output. But, if the user needs to select parameters to display the content, such as in a search, it may not get spidered.

SEO doesn't depend on ASP.NET, so you won't find much on this site to help you. Try Google, there's a ton of information out there.

Jeff


cheers Jeff

Separate out a string, and ...

What can I do this in C# or VB.NET?

Let say I have a string stored in dbase, say stringfield, and the string is:

fire, water, electricity, milk, ...

I want to separate them out, and do a hyperlink for them, like the folowing:

fire: hyperlink is http://localhost/findwords.apsx?word=fire
water: hyperlink is http://localhost/findwords.apsx?word=water
electricity: hyperlink is http://localhost/findwords.apsx?word=electricity
milk: hyperlink is http://localhost/findwords.apsx?word=milk

Or is this better ...

fire, 654, water, 897, electricity, 512, milk, 770, ...

and when I click the word, hyperlink is as follows:

fire: hyperlink is http://localhost/findwords.apsx?wordid=654
water: hyperlink is http://localhost/findwords.apsx?wordid=897
...

How? Thanks.
Any good reference for this? Is this relates to regular expression?
Thanks.A String object has a handy Split function. So, you can split your String at each comma.

Like this:

<%@. Page Language="VB" %>
<script runat="server"
Sub Page_Load( ByVal sender As Object, ByVal eArgs As EventArgs )

' get string from database
Dim ValuesAsString As String = "fire, water, electricity, milk"

' remove the spaces
ValuesAsString = ValuesAsString.Replace( " ","" )

' split the result at the commas
Dim ValuesAsArray As Array
ValuesAsArray = ValuesAsString.Split( "," )

' bind the result to whatever you like
' being lazy, i'm just using a simple repeater
ValuesRepeater.DataSource = ValuesAsArray
ValuesRepeater.DataBind()

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Repeater id="ValuesRepeater" runat="server">
<ItemTemplate>
<a href='findwords.apsx?word=<%# Container.DataItem() %>'><%# Container.DataItem() %></a>
<br />
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>

I hope this helps answer your question.

However, I am sure it would be a much better idea to "split" the string before storing it, and therefore save the words to the database individually.

As to whether you should use ID numbers or the words themselves is a matter of "design". There's no right or wrong. Having said that, I would use IDs. Words might have accents or hypens or apostrophes ... each of which would be awkward or illegal in a query string.

I hope this helps.
Thanks for replying, and I am thinking of using the second method because some words might have more than one meaning, and I can use different ID to separate them out, for example fire, 654, fire, 655, water, 897, electricity, 512, milk, 770, ...

Hence
the url http://localhost/findwords.apsx?wordid=654 and 655 refer to same word, fire, but different meaning ...

So, the question is HOW?

I found source codes in PHP, as follows:

$LOV = split(";", ";All;0;No;1;Yes");

if(sizeof($LOV)%2 != 0)
$array_length = sizeof($LOV) - 1;
else
$array_length = sizeof($LOV);

for($i = 0; $i < $array_length; $i = $i + 2)
{
if($LOV[$i] == $fldis_recommended)
$option="<option SELECTED value=\"" . $LOV[$i] . "\">" . $LOV[$i + 1];
else
$option="<option value=\"" . $LOV[$i] . "\">" . $LOV[$i + 1];

echo $option;
}

How to translate this into VB.NET?

Thanks.
I'm a C# coder, but am learning VB and so am using this as a learning opportunity. I'm not 100% sure that the translation is correct syntactically (I'm sure someone will correct it if it isn't), however the structure is correct.

Dim LOV As String [] = ";All;0;No;1;Yes".Split(";")
Dim option As String
Dim array_length As Integer

If Not ( ( LOV.Length Mod 0 ) = 0 ) Then

array_length = LOV.Length - 1

Else

array_length = LOV.Length

End If

Dim i As Integer

For i = 0 To i < array_length Step 2

If LOV(i) = fldis_recommended Then ' Don't know where fldis_recommended comes from

option = "<option SELECTED value=" & vbQuote & LOV(i) & vbQuote & ">" & LOV(i+1)

Else

option = "<option value=" & vbQuote & LOV(i) & vbQuote & ">" & LOV(i+1)

End If

Response.Write(option) ' or however you are sending it to the Response object

Next


> I'm not 100% sure that the translation is correct syntactically (I'm sure someone will correct it if it isn't), however the structure is correct

The syntax is a little wrong, which I've amended with comments below.

(May I ask why you're learning VB?)

Dim LOV As String() = "0;All;1;No;2;Yes".Split(";")'<-- String[] to String(), also changed the string itself
Dim opt As String'<-- option is a reserved word, so changed to opt

Dim array_length As Integer
If Not ( ( LOV.Length Mod 2 ) = 0 ) Then'<-- Changed to Mod 2
array_length = LOV.Length - 1
Else
array_length = LOV.Length
End If

Dim i As Integer
If (array_length > 0) Then
For i = 0 To array_length-1 Step 2'<-- removed "i <", changed array_length-1
If LOV(i) = fldis_recommended Then' Don't know where fldis_recommended comes from
opt = "<opt SELECTED value=""" & LOV(i) & """>" & LOV(i+1)'<-- changed vbQuote to "" (escaped quotation)
Else
opt = "<opt value=""" & LOV(i) & """>" & LOV(i+1)
End If
Response.Write(opt)' or however you are sending it to the Response object
Next
End If


> (May I ask why you're learning VB?)

I just think that it's a good idea to know VB as well as C# and there may be a situation when I need to code in VB.

Monday, March 26, 2012

serialization and Session Object

Hello,
I recently read that a class must support serialization in order for it to
be stored in the Session State. Before reading this I had been storing a
class to the Session State no problem (without serialization). The class is
simply a storage class and contains only primitive types...is it necessary
to serialize this object? If so, how do you go about serializing an entire
class?
Thanks much.BTW, using C#. Thanks
"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
>
It only needs to be serializable if you using session state other then
InProc. If you are using InProc, you can place anything you want into
session.
"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
>
"Bilbo" <Bilbo@.cox.net> wrote in news:eZDMiA1aEHA.2516
@.TK2MSFTNGP10.phx.gbl:

> is it necessary
> to serialize this object?
I think only if you're using session variables in a webfarm:
http://support.microsoft.com/defaul...b;EN-US;q312112
I never had problems storing complex objects in a sesion variable on a
single web server environment.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]
Check in your Web.config, that's where it is set. InProc is the default.
And if you haven't had any serialization warnings after putting custom
objects into session, then you're using InProc.
"Bilbo" <Bilbo@.cox.net> wrote in message
news:e$8bUo1aEHA.596@.TK2MSFTNGP11.phx.gbl...
> Thanks for your response. How can I tell if I am using InProc?
> Thanks.
>
> "Marina" <someone@.nospam.com> wrote in message
> news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
it
> to
a
class
> entire
>
Thanks for your response. How can I tell if I am using InProc?
Thanks.
"Marina" <someone@.nospam.com> wrote in message
news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
> It only needs to be serializable if you using session state other then
> InProc. If you are using InProc, you can place anything you want into
> session.
> "Bilbo" <Bilbo@.cox.net> wrote in message
> news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
to
> is
> necessary
entire
>

Saturday, March 24, 2012

serialization and Session Object

Hello,

I recently read that a class must support serialization in order for it to
be stored in the Session State. Before reading this I had been storing a
class to the Session State no problem (without serialization). The class is
simply a storage class and contains only primitive types...is it necessary
to serialize this object? If so, how do you go about serializing an entire
class?

Thanks much.BTW, using C#. Thanks

"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
"Bilbo" <Bilbo@.cox.net> wrote in news:eZDMiA1aEHA.2516
@.TK2MSFTNGP10.phx.gbl:

> is it necessary
> to serialize this object?

I think only if you're using session variables in a webfarm:

http://support.microsoft.com/defaul...b;EN-US;q312112

I never had problems storing complex objects in a sesion variable on a
single web server environment.

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
It only needs to be serializable if you using session state other then
InProc. If you are using InProc, you can place anything you want into
session.

"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
Thanks for your response. How can I tell if I am using InProc?

Thanks.

"Marina" <someone@.nospam.com> wrote in message
news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
> It only needs to be serializable if you using session state other then
> InProc. If you are using InProc, you can place anything you want into
> session.
> "Bilbo" <Bilbo@.cox.net> wrote in message
> news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> > Hello,
> > I recently read that a class must support serialization in order for it
to
> > be stored in the Session State. Before reading this I had been storing a
> > class to the Session State no problem (without serialization). The class
> is
> > simply a storage class and contains only primitive types...is it
> necessary
> > to serialize this object? If so, how do you go about serializing an
entire
> > class?
> > Thanks much.
Check in your Web.config, that's where it is set. InProc is the default.

And if you haven't had any serialization warnings after putting custom
objects into session, then you're using InProc.

"Bilbo" <Bilbo@.cox.net> wrote in message
news:e$8bUo1aEHA.596@.TK2MSFTNGP11.phx.gbl...
> Thanks for your response. How can I tell if I am using InProc?
> Thanks.
>
> "Marina" <someone@.nospam.com> wrote in message
> news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
> > It only needs to be serializable if you using session state other then
> > InProc. If you are using InProc, you can place anything you want into
> > session.
> > "Bilbo" <Bilbo@.cox.net> wrote in message
> > news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> > > Hello,
> > > > I recently read that a class must support serialization in order for
it
> to
> > > be stored in the Session State. Before reading this I had been storing
a
> > > class to the Session State no problem (without serialization). The
class
> > is
> > > simply a storage class and contains only primitive types...is it
> > necessary
> > > to serialize this object? If so, how do you go about serializing an
> entire
> > > class?
> > > > Thanks much.
> >

Serialization of Session objects

Hello,
I have implemented SQL Server session state in my application however I am
having some problems. Simple objects stored in Session state are fine and ar
e
handled by .NET, however when I try to store more complex objects such as an
ArrayList in session state I am not able to figure out exactly what I have t
o
do to serialize and deserialize the object.
There doesn't seem to be any code examples around when it comes to
serializing session objects. Could anyone provide me with some code that
would help?
I have managed to successfully serialize and deserialize an object to a file
but I am specifically looking to serialize the object to session state.
Thanks,
GaryAny class stored in session must implement the ISerializable attribute.
http://msdn.microsoft.com/library/d.../>
asstopic.asp
Robbe Morris - 2004/2005 Microsoft MVP C#
Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp
"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
> are
> handled by .NET, however when I try to store more complex objects such as
> an
> ArrayList in session state I am not able to figure out exactly what I have
> to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
> file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Gary,
All you have to do is to put a line
[Serializable]
before definition of every class you are going to save in the session state.
Eliyahu
"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
are
> handled by .NET, however when I try to store more complex objects such as
an
> ArrayList in session state I am not able to figure out exactly what I have
to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Hello,
Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manuall
y
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!
Regards,
Gary
"Eliyahu Goldin" wrote:

> Gary,
> All you have to do is to put a line
> [Serializable]
> before definition of every class you are going to save in the session stat
e.
>
> Eliyahu
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> are
> an
> to
> file
>
>
Hello,
Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manuall
y
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!
Regards,
Gary
"Robbe Morris [C# MVP]" wrote:

> Any class stored in session must implement the ISerializable attribute.
> http://msdn.microsoft.com/library/d...
classtopic.asp
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> Earn money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
>
>

Serialization of Session objects

Hello,

I have implemented SQL Server session state in my application however I am
having some problems. Simple objects stored in Session state are fine and are
handled by .NET, however when I try to store more complex objects such as an
ArrayList in session state I am not able to figure out exactly what I have to
do to serialize and deserialize the object.

There doesn't seem to be any code examples around when it comes to
serializing session objects. Could anyone provide me with some code that
would help?

I have managed to successfully serialize and deserialize an object to a file
but I am specifically looking to serialize the object to session state.

Thanks,

GaryAny class stored in session must implement the ISerializable attribute.

http://msdn.microsoft.com/library/d...lasst opic.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#

Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
> are
> handled by .NET, however when I try to store more complex objects such as
> an
> ArrayList in session state I am not able to figure out exactly what I have
> to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
> file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Gary,

All you have to do is to put a line
[Serializable]

before definition of every class you are going to save in the session state.

Eliyahu

"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
are
> handled by .NET, however when I try to store more complex objects such as
an
> ArrayList in session state I am not able to figure out exactly what I have
to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Hello,

Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manually
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!

Regards,

Gary

"Eliyahu Goldin" wrote:

> Gary,
> All you have to do is to put a line
> [Serializable]
> before definition of every class you are going to save in the session state.
>
> Eliyahu
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> > Hello,
> > I have implemented SQL Server session state in my application however I am
> > having some problems. Simple objects stored in Session state are fine and
> are
> > handled by .NET, however when I try to store more complex objects such as
> an
> > ArrayList in session state I am not able to figure out exactly what I have
> to
> > do to serialize and deserialize the object.
> > There doesn't seem to be any code examples around when it comes to
> > serializing session objects. Could anyone provide me with some code that
> > would help?
> > I have managed to successfully serialize and deserialize an object to a
> file
> > but I am specifically looking to serialize the object to session state.
> > Thanks,
> > Gary
>
Hello,

Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manually
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!

Regards,

Gary

"Robbe Morris [C# MVP]" wrote:

> Any class stored in session must implement the ISerializable attribute.
> http://msdn.microsoft.com/library/d...lasst opic.asp
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> Earn money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> > Hello,
> > I have implemented SQL Server session state in my application however I am
> > having some problems. Simple objects stored in Session state are fine and
> > are
> > handled by .NET, however when I try to store more complex objects such as
> > an
> > ArrayList in session state I am not able to figure out exactly what I have
> > to
> > do to serialize and deserialize the object.
> > There doesn't seem to be any code examples around when it comes to
> > serializing session objects. Could anyone provide me with some code that
> > would help?
> > I have managed to successfully serialize and deserialize an object to a
> > file
> > but I am specifically looking to serialize the object to session state.
> > Thanks,
> > Gary
>

Serializing an object from HttpApplicationState

Hi!
I have an object stored in the HttpApplicationState collection of my
site, but i would like to mantain the state of this object even if the
application restart, so in case of any problem or when I change
something in the web.config or add anything to the bin directory, i can
load the last values from somewhere and continue the work.
I'm using serialization to accomplish this, and it works ok. But i'm
serializing the object to a file in the "HttpApplication.EndRequest"
event. The problem is that with this event, it saves the file in the end
of every instance of HttpApplication, which occours almost every second.
I tested locally, and it saves the file everytime i access any page.
I know that the HttpApplicationState is shared among all the instances
of HttpApplication, and I would like to save the file only before
ApplicationState is destroyed, not the application...
There is no event in HttpApplicationState, so is there any way of doing
this?
Thanks in advance.Hi Natan:
One of the safest things you could do is re-save the file anytime the
value changes (if it is not changing too frequently). This would take
care of even catostrophic failures.
There is an Application_End method you can use in the code behind for
Global.asax. This method should fire whenever the application shuts
down or recycles.
Scott
http://www.OdeToCode.com
On Sun, 26 Sep 2004 19:06:03 -0300, Natan <nvivo@.mandic.com.br> wrote:

>Hi!
>I have an object stored in the HttpApplicationState collection of my
>site, but i would like to mantain the state of this object even if the
>application restart, so in case of any problem or when I change
>something in the web.config or add anything to the bin directory, i can
>load the last values from somewhere and continue the work.
>I'm using serialization to accomplish this, and it works ok. But i'm
>serializing the object to a file in the "HttpApplication.EndRequest"
>event. The problem is that with this event, it saves the file in the end
>of every instance of HttpApplication, which occours almost every second.
>I tested locally, and it saves the file everytime i access any page.
>I know that the HttpApplicationState is shared among all the instances
>of HttpApplication, and I would like to save the file only before
>ApplicationState is destroyed, not the application...
>There is no event in HttpApplicationState, so is there any way of doing
>this?
>
>Thanks in advance.
Scott Allen wrote:
> Hi Natan:
> One of the safest things you could do is re-save the file anytime the
> value changes (if it is not changing too frequently). This would take
> care of even catostrophic failures.
That's what i would like to avoid. File writes are too expensive, and
this would be like 3 or 4 per second. although the file size is aprox.
20k, it is still unnecessary.

> There is an Application_End method you can use in the code behind for
> Global.asax. This method should fire whenever the application shuts
> down or recycles.
Application_End is tied to the EndRequest actually, which is not the
Application in IIS itself, but HttpApplication instance. Many instances
are created and destroyed everytime by the server... take a look at the
documentation.
I really would like to save it only when necessary. Maybe i'll need to
implement it in another way...
Hi Natan:

>Application_End is tied to the EndRequest actually, which is not the
>Application in IIS itself, but HttpApplication instance. Many instances
>are created and destroyed everytime by the server... take a look at the
>documentation.
>
Negative: Application_EndRequest fires as the last event in the
pipeline before the request moves to the HttpHandler for the requested
resource. This happens on every request. Furthermore, the
HttpApplication instance is not destroyed, but is kept in a pool to
service another request.
Application_End, like Application_Start, is invoked only once, and
only invoked on a single HttpApplication instance, the first instance
in the pool. It will fire before the application domain unloads,
although there is some evidence that this behavior is not 100.00%
reliable.
I've been through the documentation many times, but even better I have
code that can demonstrate this behavior. You can watch the output
window of the debugger as you make requests to the web app with the
following code in global. Do an IISRESET to watch Application_End
fire.
public Global()
{
InitializeComponent();
id = System.Threading.Interlocked.Increment(ref counter);
}
protected void Application_Start(Object sender, EventArgs e)
{
Debug.WriteLine("Application_Start on ID: " + id.ToString());
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
Debug.WriteLine("Application_EndRequest on ID: " + id.ToString());
}
protected void Application_End(Object sender, EventArgs e)
{
Debug.WriteLine("Application_End on ID: " + id.ToString());
}
static int counter = 0;
int id = 0;
Hope this helps,
Scott
http://www.OdeToCode.com
Scott Allen wrote:
> Negative: Application_EndRequest fires as the last event in the
> pipeline before the request moves to the HttpHandler for the requested
> resource. This happens on every request. Furthermore, the
> HttpApplication instance is not destroyed, but is kept in a pool to
> service another request.
> Application_End, like Application_Start, is invoked only once, and
> only invoked on a single HttpApplication instance, the first instance
> in the pool. It will fire before the application domain unloads,
> although there is some evidence that this behavior is not 100.00%
> reliable.
Hmmm... thanks. The sdk documentation has some wrong links.
Anyway, the problem with Application_End is that the applicationstate
object is already destroyed, so I can't use it...
=/
Hi Scott!
Suddenly I had the brilliant idea of creating a destructor for my object
(duh... why didn't i thought about it before?), and applying a singleton
pattern for it, so there is only one instance of it and when it is
destroyed, no matter where he is, it serializes itself to the file. When
the application restarts it checks for the file and load the state again.
Thanks anyway!

Serializing an object from HttpApplicationState

Hi!

I have an object stored in the HttpApplicationState collection of my
site, but i would like to mantain the state of this object even if the
application restart, so in case of any problem or when I change
something in the web.config or add anything to the bin directory, i can
load the last values from somewhere and continue the work.

I'm using serialization to accomplish this, and it works ok. But i'm
serializing the object to a file in the "HttpApplication.EndRequest"
event. The problem is that with this event, it saves the file in the end
of every instance of HttpApplication, which occours almost every second.
I tested locally, and it saves the file everytime i access any page.

I know that the HttpApplicationState is shared among all the instances
of HttpApplication, and I would like to save the file only before
ApplicationState is destroyed, not the application...

There is no event in HttpApplicationState, so is there any way of doing
this?

Thanks in advance.Hi Natan:

One of the safest things you could do is re-save the file anytime the
value changes (if it is not changing too frequently). This would take
care of even catostrophic failures.

There is an Application_End method you can use in the code behind for
Global.asax. This method should fire whenever the application shuts
down or recycles.

--
Scott
http://www.OdeToCode.com

On Sun, 26 Sep 2004 19:06:03 -0300, Natan <nvivo@.mandic.com.br> wrote:

>Hi!
>I have an object stored in the HttpApplicationState collection of my
>site, but i would like to mantain the state of this object even if the
>application restart, so in case of any problem or when I change
>something in the web.config or add anything to the bin directory, i can
>load the last values from somewhere and continue the work.
>I'm using serialization to accomplish this, and it works ok. But i'm
>serializing the object to a file in the "HttpApplication.EndRequest"
>event. The problem is that with this event, it saves the file in the end
>of every instance of HttpApplication, which occours almost every second.
>I tested locally, and it saves the file everytime i access any page.
>I know that the HttpApplicationState is shared among all the instances
>of HttpApplication, and I would like to save the file only before
>ApplicationState is destroyed, not the application...
>There is no event in HttpApplicationState, so is there any way of doing
>this?
>
>Thanks in advance.
Scott Allen wrote:
> Hi Natan:
> One of the safest things you could do is re-save the file anytime the
> value changes (if it is not changing too frequently). This would take
> care of even catostrophic failures.

That's what i would like to avoid. File writes are too expensive, and
this would be like 3 or 4 per second. although the file size is aprox.
20k, it is still unnecessary.

> There is an Application_End method you can use in the code behind for
> Global.asax. This method should fire whenever the application shuts
> down or recycles.

Application_End is tied to the EndRequest actually, which is not the
Application in IIS itself, but HttpApplication instance. Many instances
are created and destroyed everytime by the server... take a look at the
documentation.

I really would like to save it only when necessary. Maybe i'll need to
implement it in another way...
Hi Natan:

>Application_End is tied to the EndRequest actually, which is not the
>Application in IIS itself, but HttpApplication instance. Many instances
>are created and destroyed everytime by the server... take a look at the
>documentation.

Negative: Application_EndRequest fires as the last event in the
pipeline before the request moves to the HttpHandler for the requested
resource. This happens on every request. Furthermore, the
HttpApplication instance is not destroyed, but is kept in a pool to
service another request.

Application_End, like Application_Start, is invoked only once, and
only invoked on a single HttpApplication instance, the first instance
in the pool. It will fire before the application domain unloads,
although there is some evidence that this behavior is not 100.00%
reliable.

I've been through the documentation many times, but even better I have
code that can demonstrate this behavior. You can watch the output
window of the debugger as you make requests to the web app with the
following code in global. Do an IISRESET to watch Application_End
fire.

public Global()
{
InitializeComponent();
id = System.Threading.Interlocked.Increment(ref counter);
}

protected void Application_Start(Object sender, EventArgs e)
{
Debug.WriteLine("Application_Start on ID: " + id.ToString());
}

protected void Application_EndRequest(Object sender, EventArgs e)
{
Debug.WriteLine("Application_EndRequest on ID: " + id.ToString());
}

protected void Application_End(Object sender, EventArgs e)
{
Debug.WriteLine("Application_End on ID: " + id.ToString());
}

static int counter = 0;
int id = 0;

Hope this helps,

--
Scott
http://www.OdeToCode.com
Scott Allen wrote:
> Negative: Application_EndRequest fires as the last event in the
> pipeline before the request moves to the HttpHandler for the requested
> resource. This happens on every request. Furthermore, the
> HttpApplication instance is not destroyed, but is kept in a pool to
> service another request.
> Application_End, like Application_Start, is invoked only once, and
> only invoked on a single HttpApplication instance, the first instance
> in the pool. It will fire before the application domain unloads,
> although there is some evidence that this behavior is not 100.00%
> reliable.

Hmmm... thanks. The sdk documentation has some wrong links.

Anyway, the problem with Application_End is that the applicationstate
object is already destroyed, so I can't use it...

=/
Hi Scott!

Suddenly I had the brilliant idea of creating a destructor for my object
(duh... why didn't i thought about it before?), and applying a singleton
pattern for it, so there is only one instance of it and when it is
destroyed, no matter where he is, it serializes itself to the file. When
the application restarts it checks for the file and load the state again.

Thanks anyway!