Showing posts with label pages. Show all posts
Showing posts with label pages. Show all posts

Saturday, March 31, 2012

Server side code in-side aspx

I usually use code-behind pages in ASP.Net, but occasionally I have to put my
server code inside an aspx file.
I have a problem finding the correct signature for a button click event.
Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles loginbtn.Click
compiles in in code behind, but it doesn't compile inside an aspx file.

How can I write a server event handler and put the code inside an asp file?That is the correct signature. What's the error you get?

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I usually use code-behind pages in ASP.Net, but occasionally I have to
> put my
> server code inside an aspx file.
> I have a problem finding the correct signature for a button click
> event.
> Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles loginbtn.Click
> compiles in in code behind, but it doesn't compile inside an aspx
> file.
> How can I write a server event handler and put the code inside an asp
> file?

Server side code in-side aspx

I usually use code-behind pages in ASP.Net, but occasionally I have to put m
y
server code inside an aspx file.
I have a problem finding the correct signature for a button click event.
Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles loginbtn.Click
compiles in in code behind, but it doesn't compile inside an aspx file.
How can I write a server event handler and put the code inside an asp file?That is the correct signature. What's the error you get?
-Brock
DevelopMentor
http://staff.develop.com/ballen

> I usually use code-behind pages in ASP.Net, but occasionally I have to
> put my
> server code inside an aspx file.
> I have a problem finding the correct signature for a button click
> event.
> Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles loginbtn.Click
> compiles in in code behind, but it doesn't compile inside an aspx
> file.
> How can I write a server event handler and put the code inside an asp
> file?
>

server side menu problem

hi,
in my site there r 2 frames:
1.menu frame
2.application display
the menu is based on <A HREF=...> because I need to direct the pages to
the application display frame.now I need to cuach a session before I redirect
the page and <AHREF=...> is not build for that.I need un aspx control that has
the property "target" so Icould redirect the page to the write fame.
So, how can I control from a server side function the frame to display the
content?
Is it even possible?
If not, how to avoid it without using client-based menus?
how can I cuach the session without aspx control?Not clear what's the problem. When you navigate to another page from the
client, the session persists.

Eliyahu

"server side menu problem2" <server side menu
problem2@.discussions.microsoft.com> wrote in message
news:7FB9586D-9492-4F26-9585-AF9FEDB17E78@.microsoft.com...
> hi,
> in my site there r 2 frames:
> 1.menu frame
> 2.application display
> the menu is based on <A HREF=...> because I need to direct the pages to
> the application display frame.now I need to cuach a session before I
redirect
> the page and <AHREF=...> is not build for that.I need un aspx control that
has
> the property "target" so Icould redirect the page to the write fame.
> So, how can I control from a server side function the frame to display the
> content?
> Is it even possible?
> If not, how to avoid it without using client-based menus?
> how can I cuach the session without aspx control?

Thursday, March 29, 2012

server side menu problem

hi,
in my site there r 2 frames:
1.menu frame
2.application display
the menu is based on <A HREF=...> because I need to direct the pages to
the application display frame.now I need to cuach a session before I redirec
t
the page and <AHREF=...> is not build for that.I need un aspx control that h
as
the property "target" so Icould redirect the page to the write fame.
So, how can I control from a server side function the frame to display the
content?
Is it even possible?
If not, how to avoid it without using client-based menus?
how can I cuach the session without aspx control?Not clear what's the problem. When you navigate to another page from the
client, the session persists.
Eliyahu
"server side menu problem2" <server side menu
problem2@.discussions.microsoft.com> wrote in message
news:7FB9586D-9492-4F26-9585-AF9FEDB17E78@.microsoft.com...
> hi,
> in my site there r 2 frames:
> 1.menu frame
> 2.application display
> the menu is based on <A HREF=...> because I need to direct the pages to
> the application display frame.now I need to cuach a session before I
redirect
> the page and <AHREF=...> is not build for that.I need un aspx control that
has
> the property "target" so Icould redirect the page to the write fame.
> So, how can I control from a server side function the frame to display the
> content?
> Is it even possible?
> If not, how to avoid it without using client-based menus?
> how can I cuach the session without aspx control?
>

Saturday, March 24, 2012

server updateing data already on the client

Hi

I would like that when data is updated in a database on
the sever taht all instance of that data already being
viewed on aspx pages by clients be updated. Is this
acheiveble with an activeX control on the page that
listens for information from the server? I dont want to
have to use page refreshes firing in a loop.

Thanks in advance

JakeYou can write a Windows Form application and host it in a browser, just like
ActiveX. You'll need to use remoting for that though.
The catch is that every user must have IE and .NET framework installed.
Other browsers don't support .NET "applets"

"Jake" <anonymous@.discussions.microsoft.com> wrote in message
news:2418501c45f00$7f8a8640$a501280a@.phx.gbl...
> Hi
> I would like that when data is updated in a database on
> the sever taht all instance of that data already being
> viewed on aspx pages by clients be updated. Is this
> acheiveble with an activeX control on the page that
> listens for information from the server? I dont want to
> have to use page refreshes firing in a loop.
> Thanks in advance
> Jake
Thanks that sounds exactly like what I am after.

Would you know of where I can find information about
imbeding/running windows application in a web page/
browser and remoting?

Thanks again

Jake

>--Original Message--
>You can write a Windows Form application and host it in
a browser, just like
>ActiveX. You'll need to use remoting for that though.
>The catch is that every user must have IE and .NET
framework installed.
>Other browsers don't support .NET "applets"
>"Jake" <anonymous@.discussions.microsoft.com> wrote in
message
>news:2418501c45f00$7f8a8640$a501280a@.phx.gbl...
>> Hi
>>
>> I would like that when data is updated in a database on
>> the sever taht all instance of that data already being
>> viewed on aspx pages by clients be updated. Is this
>> acheiveble with an activeX control on the page that
>> listens for information from the server? I dont want
to
>> have to use page refreshes firing in a loop.
>>
>> Thanks in advance
>>
>> Jake
>
>.

server updateing data already on the client

Hi
I would like that when data is updated in a database on
the sever taht all instance of that data already being
viewed on aspx pages by clients be updated. Is this
acheiveble with an activeX control on the page that
listens for information from the server? I dont want to
have to use page refreshes firing in a loop.
Thanks in advance
JakeYou can write a Windows Form application and host it in a browser, just like
ActiveX. You'll need to use remoting for that though.
The catch is that every user must have IE and .NET framework installed.
Other browsers don't support .NET "applets"
"Jake" <anonymous@.discussions.microsoft.com> wrote in message
news:2418501c45f00$7f8a8640$a501280a@.phx
.gbl...
> Hi
> I would like that when data is updated in a database on
> the sever taht all instance of that data already being
> viewed on aspx pages by clients be updated. Is this
> acheiveble with an activeX control on the page that
> listens for information from the server? I dont want to
> have to use page refreshes firing in a loop.
> Thanks in advance
> Jake
Thanks that sounds exactly like what I am after.
Would you know of where I can find information about
imbeding/running windows application in a web page/
browser and remoting?
Thanks again
Jake

>--Original Message--
>You can write a Windows Form application and host it in
a browser, just like
>ActiveX. You'll need to use remoting for that though.
>The catch is that every user must have IE and .NET
framework installed.
>Other browsers don't support .NET "applets"
>"Jake" <anonymous@.discussions.microsoft.com> wrote in
message
> news:2418501c45f00$7f8a8640$a501280a@.phx
.gbl...
to
>
>.
>

Thursday, March 22, 2012

Server.Execute sluggish, faster way to retrieve HTML string?

Hi,

I need to retrieve the HTML string of one of my ASP pages, and whenever I make the attempt using my code, it brings the entire server to a hault for quite a while. The server's hardware specs are perfectly fine, and I've narrowed it down to the Server.Execute line. Is there anything I can do here? Here's my code:

StringWriter sw =new StringWriter();Server.Execute("page.aspx", sw);String strHtmlCode = sw.GetStringBuilder().ToString();

Thanks!

Use HttpWebRequest/HttpWebResponse:

//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}

String strHtmlCode = GetHtmlPage("http://domain/page.aspx");


This may be because page.aspx may be huge page and it will take long time in processing. Because of this, your current page execution will stop:)

Cheers

Bhavesh


lad.bhavesh:

This may be because page.aspx maybe huge page and it will take long time in processing. Because of this,your current page execution will stop:)

Cheers

Bhavesh


Including the one image and stylesheet, it's about 55 KB.


Mikesdotnetting:

Use HttpWebRequest/HttpWebResponse:

//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}

String strHtmlCode = GetHtmlPage("http://domain/page.aspx");

I apologize - I should have been more clear on the context here. A session needs to be maintained in order to access this page. Is there anything else I can use? And believe me, I've tried googling :). I'm sure it's out there somewhere, but I can't seem to find it.

Will this do you?

http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx


That'll do it, thanks!

Server.Execute vs Include?

I have several small pieces of common code that get applied to each page.
Which is better a better way of including them in other pages? Use the
traditional include statement or go with the Server.Execute("pagename")
method.

Thanks
KeithNeither, unless the code absolutely has to be in a "webform"

Instead, just create a module or class and call the code like you would any
other function.

"Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> I have several small pieces of common code that get applied to each page.
> Which is better a better way of including them in other pages? Use the
> traditional include statement or go with the Server.Execute("pagename")
> method.
> Thanks
> Keith
That seems rather silly to create a class simply to write out 4 or 5 lines
of HTML with reponse.write. Not to mention maintaining all the dam double
quotes within the reponse.write text. All my HTML conforms to the standards
required for MSXML and XSL/XSLT. Placing everything in an object for the
sake of making an object makes it much more dificult to debug. OOP is a
wonderfull thing but only when applied where appropriate.

I think I will stick with include files for things of this nature. The
server.execute is fine but objects defined by the parent are not available
to the child whereas in an include they are.

Keith

PS: The microsoft guy told me to stay away from modules!

"Boban Dragojlovic" <news@._N_O_S_P_AM_dragojlovic.org> wrote in message
news:lduqb.847$A71.375@.newssvr14.news.prodigy.com. ..
> Neither, unless the code absolutely has to be in a "webform"
> Instead, just create a module or class and call the code like you would
any
> other function.
>
> "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> > I have several small pieces of common code that get applied to each
page.
> > Which is better a better way of including them in other pages? Use the
> > traditional include statement or go with the Server.Execute("pagename")
> > method.
> > Thanks
> > Keith
I think the easiest way is to throw the HTML and other stuff into User
Controls. Then you just drop the user controls onto your web page for them
to appear. These are similiar to includes but better.

Jeff

"Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
news:%23adm3qJpDHA.1676@.TK2MSFTNGP09.phx.gbl...
> That seems rather silly to create a class simply to write out 4 or 5 lines
> of HTML with reponse.write. Not to mention maintaining all the dam double
> quotes within the reponse.write text. All my HTML conforms to the
standards
> required for MSXML and XSL/XSLT. Placing everything in an object for the
> sake of making an object makes it much more dificult to debug. OOP is a
> wonderfull thing but only when applied where appropriate.
> I think I will stick with include files for things of this nature. The
> server.execute is fine but objects defined by the parent are not available
> to the child whereas in an include they are.
> Keith
> PS: The microsoft guy told me to stay away from modules!
>
> "Boban Dragojlovic" <news@._N_O_S_P_AM_dragojlovic.org> wrote in message
> news:lduqb.847$A71.375@.newssvr14.news.prodigy.com. ..
> > Neither, unless the code absolutely has to be in a "webform"
> > Instead, just create a module or class and call the code like you would
> any
> > other function.
> > "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> > news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> > > I have several small pieces of common code that get applied to each
> page.
> > > Which is better a better way of including them in other pages? Use
the
> > > traditional include statement or go with the
Server.Execute("pagename")
> > > method.
> > > > Thanks
> > > Keith
> >
Now that sounds like a more reasonable solution to me as well.

Cheers
Keith

"Jeff" <jsiver@.dls.net> wrote in message
news:O7bV3ycpDHA.3688@.TK2MSFTNGP11.phx.gbl...
> I think the easiest way is to throw the HTML and other stuff into User
> Controls. Then you just drop the user controls onto your web page for
them
> to appear. These are similiar to includes but better.
> Jeff
> "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> news:%23adm3qJpDHA.1676@.TK2MSFTNGP09.phx.gbl...
> > That seems rather silly to create a class simply to write out 4 or 5
lines
> > of HTML with reponse.write. Not to mention maintaining all the dam
double
> > quotes within the reponse.write text. All my HTML conforms to the
> standards
> > required for MSXML and XSL/XSLT. Placing everything in an object for the
> > sake of making an object makes it much more dificult to debug. OOP is a
> > wonderfull thing but only when applied where appropriate.
> > I think I will stick with include files for things of this nature. The
> > server.execute is fine but objects defined by the parent are not
available
> > to the child whereas in an include they are.
> > Keith
> > PS: The microsoft guy told me to stay away from modules!
> > "Boban Dragojlovic" <news@._N_O_S_P_AM_dragojlovic.org> wrote in message
> > news:lduqb.847$A71.375@.newssvr14.news.prodigy.com. ..
> > > Neither, unless the code absolutely has to be in a "webform"
> > > > Instead, just create a module or class and call the code like you
would
> > any
> > > other function.
> > > > > "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> > > news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> > > > I have several small pieces of common code that get applied to each
> > page.
> > > > Which is better a better way of including them in other pages? Use
> the
> > > > traditional include statement or go with the
> Server.Execute("pagename")
> > > > method.
> > > > > > Thanks
> > > > Keith
> > > > > >

Server.GetLastError() and "Page-Level Error Pages"

Hello,
I'm currently reading the MS Developing Web applications with c# (and
VB.net).
In the chapter related to Error management, there is a sample about
"Page-Level Error Pages"
eg:
In my form:
========
<%@dotnet.itags.org. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
errorPage="ErrDefault1.aspx"%>
I have placed a button on the form and in the code behind just thrown an
Exception.
in ErrDefaulst1.aspx:
==============
private void Page_Load(object sender, System.EventArgs e)
{
if (Server.GetLastError() != null)
litError.Text="<h3>" + Server.GetLastError().Message + "</h3>";
else
litError.Text= "<h3>Unkown Error occured...</h3>";
Server.ClearError();
}
It is said, that is is possible to use the Server.GetLastError() in the
error page. However, it is always null.
Did I miss something?
Thanks,
JosI asked this.. and got answered by myself:) a few days ago..
My answer:
"Since you are redirected to another errorpage you loose the GetLatsetError
information, cause you are not on that page anymore.. BUT.. if you in
Global.aspx in Page_Eerror event (where it's still accessible) put
Server.GetLastError in a SESSION variable.. you can get it thru that on the
Errorpage .."
/Lars
"Jos Joye" <jose.joye@.KILLTHESPAMSbluewin.ch> skrev i meddelandet
news:usxcl$eeEHA.3132@.TK2MSFTNGP11.phx.gbl...
> Hello,
> I'm currently reading the MS Developing Web applications with c# (and
> VB.net).
> In the chapter related to Error management, there is a sample about
> "Page-Level Error Pages"
> eg:
> In my form:
> ========
> <%@. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
> AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
> errorPage="ErrDefault1.aspx"%>
> I have placed a button on the form and in the code behind just thrown an
> Exception.
>
> in ErrDefaulst1.aspx:
> ==============
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (Server.GetLastError() != null)
> litError.Text="<h3>" + Server.GetLastError().Message + "</h3>";
> else
> litError.Text= "<h3>Unkown Error occured...</h3>";
> Server.ClearError();
> }
>
> It is said, that is is possible to use the Server.GetLastError() in the
> error page. However, it is always null.
> Did I miss something?
> Thanks,
> Jos
>
>
>
Thanks for the answer. However, I'm not too clear about it.
1) I thaught that the Page_Error() method has to be located in the Web class
and not in the Global.aspx. Did I misundertood what you explained me.
2) With the following:
<%@. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
errorPage="ErrDefault1.aspx"%>
I was trying to get rid of the Page_Error() method and have a "kind of
automatic" redirection to the ErrDefault1.aspx page in case of error.
If I make usage of the Page_Error() method, I do not see the reason of
having the "errorPage="ErrDefault1.aspx"%>" statement in my aspx file.
Thanks,
Jos
"Lars Netzel" <[stop_spam]@.host.topdomain> wrote in message
news:%23kg7VEfeEHA.1764@.TK2MSFTNGP10.phx.gbl...
> I asked this.. and got answered by myself:) a few days ago..
> My answer:
> "Since you are redirected to another errorpage you loose the
GetLatsetError
> information, cause you are not on that page anymore.. BUT.. if you in
> Global.aspx in Page_Eerror event (where it's still accessible) put
> Server.GetLastError in a SESSION variable.. you can get it thru that on
the
> Errorpage .."
> /Lars
>
>
> "Jos Joye" <jose.joye@.KILLTHESPAMSbluewin.ch> skrev i meddelandet
> news:usxcl$eeEHA.3132@.TK2MSFTNGP11.phx.gbl...
>
Hi Jos,
I think Lars is suggesting having the exception handled, or at least its
details stored somewhere, in the Application_Error method in "Global.asax".
It may be that perhaps your exception page doesn't need to show the
details of the exception to the end user, although I, of course, don't
know the details of your scenario. If you're principally interested in
apologizing to the user and publishing the details of the exception
somewhere developers can get hold of it (event log, email, file etc) you
could use Microsoft Exception Management Application block from:
http://msdn.microsoft.com/library/d...-r
m.asp
You could get around adding errorPage and Page_Error() code your
individual aspx pages by also setting the default error redirect in your
webconfig <customErrors> section:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
</customErrors>
(mode attribute is explained in the comments preceding the section in
web.config, "On" is likely to be necessary for testing and debugging if
you're serving the pages from your own machine)
In this way your page exception would not get handled on the page, would
propogate to the Global.asax handler, which would publish the exception
to whatever log your wanted, or perhaps store it in some accessible
storage, and *not* clear the error. Then the exception would propogate
to the defaultRedirect page in the web.config file, which could
apologize to the user and possibly use any persisted exception details.
This works quite neatly, although it is worth noting that any resources
not handled by the ASP.NET isapi filter (for instance any legacy asp
pages you may be obliged to include) will require additional handling.
There may well be faults with this method of handling things, and to be
honest it feels a little cumbersome defaulting to allowing the exception
to escalate to the application level, but I've certainly been obliged to
do it, and application level handling definitely should exist.
Hope I didn't deviate to far from your question!
Regards,
Duncan Kennedy.
Hi Duncan,
Thanks a lot for your really interesting reply.
I'm actually in the process of getting up to speed with ASP.NET (sorry for
the stupid questions ;-) )
I still have an open question related to this topic.
Say an exception is thrown in the Rendering part (preRendering/Rendering) of
the form.
This is actually out my scope. In that situation, if I do not have a
Page_Error() defined, how could I record the kind of error that occured.
If I understand it correctly, as soon as I get out of the Page scope, I will
not have the exception available anymore if I did not save it manually
somewhere (eg. : Session bag).
If I defined an Application_Error handler (in Global.asax) will I have this
information available?
Thanks,
Jos
"Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> wrote in
message news:ucyw3ZgeEHA.1692@.tk2msftngp13.phx.gbl...
> Hi Jos,
> I think Lars is suggesting having the exception handled, or at least its
> details stored somewhere, in the Application_Error method in
"Global.asax".
> It may be that perhaps your exception page doesn't need to show the
> details of the exception to the end user, although I, of course, don't
> know the details of your scenario. If you're principally interested in
> apologizing to the user and publishing the details of the exception
> somewhere developers can get hold of it (event log, email, file etc) you
> could use Microsoft Exception Management Application block from:
>
http://msdn.microsoft.com/library/d...tml/emab-rm.asp[col
or=darkred]
>
> You could get around adding errorPage and Page_Error() code your
> individual aspx pages by also setting the default error redirect in your
> webconfig <customErrors> section:
> <customErrors mode="On" defaultRedirect="ErrorPage.aspx">
> </customErrors>
> (mode attribute is explained in the comments preceding the section in
> web.config, "On" is likely to be necessary for testing and debugging if
> you're serving the pages from your own machine)
> In this way your page exception would not get handled on the page, would
> propogate to the Global.asax handler, which would publish the exception
> to whatever log your wanted, or perhaps store it in some accessible
> storage, and *not* clear the error. Then the exception would propogate
> to the defaultRedirect page in the web.config file, which could
> apologize to the user and possibly use any persisted exception details.
> This works quite neatly, although it is worth noting that any resources
> not handled by the ASP.NET isapi filter (for instance any legacy asp
> pages you may be obliged to include) will require additional handling.
> There may well be faults with this method of handling things, and to be
> honest it feels a little cumbersome defaulting to allowing the exception
> to escalate to the application level, but I've certainly been obliged to
> do it, and application level handling definitely should exist.
> Hope I didn't deviate to far from your question!
>
> Regards,
>
> Duncan Kennedy.[/color]
Hi Jos,
I'm sorrier for the stupid answers...
If an exception either occurs on a page before a Page_Error() handler
has been assigned or is not cleared by by a Page_Error() method then the
application will throw a HttpUnhandledException exception, which will
contain in its "innerException" property the exception that was
unhandled on the page.
As such you should still have your page exception when you're coding at
the Application_Error level, it will just be wrapped in another
exception. You could persist this somewhere appropriate if you wanted
to keep it to give a verbose report to the user when you finally
transferred the scope to an error page (Server.Redirect, defaultError in
web.config etc).
I hope this helps, Michael O'Donovan pointed out the following url on
error handling in another thread which might be useful:
http://msdn.microsoft.com/asp.net/u...ustomErrors.asp
Best of luck,
Duncan.
Jos Joye wrote:
> Hi Duncan,
> Thanks a lot for your really interesting reply.
> I'm actually in the process of getting up to speed with ASP.NET (sorry for
> the stupid questions ;-) )
> I still have an open question related to this topic.
> Say an exception is thrown in the Rendering part (preRendering/Rendering)
of
> the form.
> This is actually out my scope. In that situation, if I do not have a
> Page_Error() defined, how could I record the kind of error that occured.
> If I understand it correctly, as soon as I get out of the Page scope, I wi
ll
> not have the exception available anymore if I did not save it manually
> somewhere (eg. : Session bag).
> If I defined an Application_Error handler (in Global.asax) will I have thi
s
> information available?
> Thanks,
> Jos
>
> "Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> wrote in
> message news:ucyw3ZgeEHA.1692@.tk2msftngp13.phx.gbl...
>
> "Global.asax".
>
> http://msdn.microsoft.com/library/d...
-rm.asp
>
>
>
Thanks a lot for the explanation and for the great reference. I think that
I'm pretty clear on this topic now :-))
Jos
"Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> a crit dans
le message de news:euOxvEjeEHA.2812@.tk2msftngp13.phx.gbl...
> Hi Jos,
> I'm sorrier for the stupid answers...
> If an exception either occurs on a page before a Page_Error() handler
> has been assigned or is not cleared by by a Page_Error() method then the
> application will throw a HttpUnhandledException exception, which will
> contain in its "innerException" property the exception that was
> unhandled on the page.
> As such you should still have your page exception when you're coding at
> the Application_Error level, it will just be wrapped in another
> exception. You could persist this somewhere appropriate if you wanted
> to keep it to give a verbose report to the user when you finally
> transferred the scope to an error page (Server.Redirect, defaultError in
> web.config etc).
> I hope this helps, Michael O'Donovan pointed out the following url on
> error handling in another thread which might be useful:
>
http://msdn.microsoft.com/asp.net/u...ustomErrors.asp
> Best of luck,
> Duncan.
>
>
> Jos Joye wrote:
for
(preRendering/Rendering) of
will
this
http://msdn.microsoft.com/library/d...tml/emab-rm.asp[col
or=darkred]

Server.GetLastError() and "Page-Level Error Pages"

Hello,
I'm currently reading the MS Developing Web applications with c# (and
VB.net).

In the chapter related to Error management, there is a sample about
"Page-Level Error Pages"

eg:
In my form:
========
<%@dotnet.itags.org. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
errorPage="ErrDefault1.aspx"%
I have placed a button on the form and in the code behind just thrown an
Exception.

in ErrDefaulst1.aspx:
==============

private void Page_Load(object sender, System.EventArgs e)
{
if (Server.GetLastError() != null)
litError.Text="<h3>" + Server.GetLastError().Message + "</h3>";
else
litError.Text= "<h3>Unkown Error occured...</h3>";
Server.ClearError();
}

It is said, that is is possible to use the Server.GetLastError() in the
error page. However, it is always null.
Did I miss something?

Thanks,
JosI asked this.. and got answered by myself:) a few days ago..

My answer:

"Since you are redirected to another errorpage you loose the GetLatsetError
information, cause you are not on that page anymore.. BUT.. if you in
Global.aspx in Page_Eerror event (where it's still accessible) put
Server.GetLastError in a SESSION variable.. you can get it thru that on the
Errorpage .."

/Lars

"Jos Joye" <jose.joye@.KILLTHESPAMSbluewin.ch> skrev i meddelandet
news:usxcl$eeEHA.3132@.TK2MSFTNGP11.phx.gbl...
> Hello,
> I'm currently reading the MS Developing Web applications with c# (and
> VB.net).
> In the chapter related to Error management, there is a sample about
> "Page-Level Error Pages"
> eg:
> In my form:
> ========
> <%@. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
> AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
> errorPage="ErrDefault1.aspx"%>
> I have placed a button on the form and in the code behind just thrown an
> Exception.
>
> in ErrDefaulst1.aspx:
> ==============
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (Server.GetLastError() != null)
> litError.Text="<h3>" + Server.GetLastError().Message + "</h3>";
> else
> litError.Text= "<h3>Unkown Error occured...</h3>";
> Server.ClearError();
> }
>
> It is said, that is is possible to use the Server.GetLastError() in the
> error page. However, it is always null.
> Did I miss something?
> Thanks,
> Jos
>
Thanks for the answer. However, I'm not too clear about it.

1) I thaught that the Page_Error() method has to be located in the Web class
and not in the Global.aspx. Did I misundertood what you explained me.

2) With the following:
<%@. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
errorPage="ErrDefault1.aspx"%>
I was trying to get rid of the Page_Error() method and have a "kind of
automatic" redirection to the ErrDefault1.aspx page in case of error.
If I make usage of the Page_Error() method, I do not see the reason of
having the "errorPage="ErrDefault1.aspx"%>" statement in my aspx file.

Thanks,
Jos

"Lars Netzel" <[stop_spam]@.host.topdomain> wrote in message
news:%23kg7VEfeEHA.1764@.TK2MSFTNGP10.phx.gbl...
> I asked this.. and got answered by myself:) a few days ago..
> My answer:
> "Since you are redirected to another errorpage you loose the
GetLatsetError
> information, cause you are not on that page anymore.. BUT.. if you in
> Global.aspx in Page_Eerror event (where it's still accessible) put
> Server.GetLastError in a SESSION variable.. you can get it thru that on
the
> Errorpage .."
> /Lars
>
>
> "Jos Joye" <jose.joye@.KILLTHESPAMSbluewin.ch> skrev i meddelandet
> news:usxcl$eeEHA.3132@.TK2MSFTNGP11.phx.gbl...
> > Hello,
> > I'm currently reading the MS Developing Web applications with c# (and
> > VB.net).
> > In the chapter related to Error management, there is a sample about
> > "Page-Level Error Pages"
> > eg:
> > In my form:
> > ========
> > <%@. Page language="c#" Codebehind="TestErrOnPage.aspx.cs"
> > AutoEventWireup="false" Inherits="myDummyTry.TestErrOnPage"
> > errorPage="ErrDefault1.aspx"%>
> > I have placed a button on the form and in the code behind just thrown an
> > Exception.
> > in ErrDefaulst1.aspx:
> > ==============
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > if (Server.GetLastError() != null)
> > litError.Text="<h3>" + Server.GetLastError().Message + "</h3>";
> > else
> > litError.Text= "<h3>Unkown Error occured...</h3>";
> > Server.ClearError();
> > }
> > It is said, that is is possible to use the Server.GetLastError() in the
> > error page. However, it is always null.
> > Did I miss something?
> > Thanks,
> > Jos
Hi Jos,

I think Lars is suggesting having the exception handled, or at least its
details stored somewhere, in the Application_Error method in "Global.asax".

It may be that perhaps your exception page doesn't need to show the
details of the exception to the end user, although I, of course, don't
know the details of your scenario. If you're principally interested in
apologizing to the user and publishing the details of the exception
somewhere developers can get hold of it (event log, email, file etc) you
could use Microsoft Exception Management Application block from:

http://msdn.microsoft.com/library/d...tml/emab-rm.asp

You could get around adding errorPage and Page_Error() code your
individual aspx pages by also setting the default error redirect in your
webconfig <customErrors> section:

<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
</customErrors
(mode attribute is explained in the comments preceding the section in
web.config, "On" is likely to be necessary for testing and debugging if
you're serving the pages from your own machine)

In this way your page exception would not get handled on the page, would
propogate to the Global.asax handler, which would publish the exception
to whatever log your wanted, or perhaps store it in some accessible
storage, and *not* clear the error. Then the exception would propogate
to the defaultRedirect page in the web.config file, which could
apologize to the user and possibly use any persisted exception details.

This works quite neatly, although it is worth noting that any resources
not handled by the ASP.NET isapi filter (for instance any legacy asp
pages you may be obliged to include) will require additional handling.

There may well be faults with this method of handling things, and to be
honest it feels a little cumbersome defaulting to allowing the exception
to escalate to the application level, but I've certainly been obliged to
do it, and application level handling definitely should exist.

Hope I didn't deviate to far from your question!

Regards,

Duncan Kennedy.
Hi Duncan,

Thanks a lot for your really interesting reply.
I'm actually in the process of getting up to speed with ASP.NET (sorry for
the stupid questions ;-) )

I still have an open question related to this topic.
Say an exception is thrown in the Rendering part (preRendering/Rendering) of
the form.
This is actually out my scope. In that situation, if I do not have a
Page_Error() defined, how could I record the kind of error that occured.
If I understand it correctly, as soon as I get out of the Page scope, I will
not have the exception available anymore if I did not save it manually
somewhere (eg. : Session bag).

If I defined an Application_Error handler (in Global.asax) will I have this
information available?

Thanks,
Jos

"Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> wrote in
message news:ucyw3ZgeEHA.1692@.tk2msftngp13.phx.gbl...
> Hi Jos,
> I think Lars is suggesting having the exception handled, or at least its
> details stored somewhere, in the Application_Error method in
"Global.asax".
> It may be that perhaps your exception page doesn't need to show the
> details of the exception to the end user, although I, of course, don't
> know the details of your scenario. If you're principally interested in
> apologizing to the user and publishing the details of the exception
> somewhere developers can get hold of it (event log, email, file etc) you
> could use Microsoft Exception Management Application block from:
>
http://msdn.microsoft.com/library/d...tml/emab-rm.asp
>
> You could get around adding errorPage and Page_Error() code your
> individual aspx pages by also setting the default error redirect in your
> webconfig <customErrors> section:
> <customErrors mode="On" defaultRedirect="ErrorPage.aspx">
> </customErrors>
> (mode attribute is explained in the comments preceding the section in
> web.config, "On" is likely to be necessary for testing and debugging if
> you're serving the pages from your own machine)
> In this way your page exception would not get handled on the page, would
> propogate to the Global.asax handler, which would publish the exception
> to whatever log your wanted, or perhaps store it in some accessible
> storage, and *not* clear the error. Then the exception would propogate
> to the defaultRedirect page in the web.config file, which could
> apologize to the user and possibly use any persisted exception details.
> This works quite neatly, although it is worth noting that any resources
> not handled by the ASP.NET isapi filter (for instance any legacy asp
> pages you may be obliged to include) will require additional handling.
> There may well be faults with this method of handling things, and to be
> honest it feels a little cumbersome defaulting to allowing the exception
> to escalate to the application level, but I've certainly been obliged to
> do it, and application level handling definitely should exist.
> Hope I didn't deviate to far from your question!
>
> Regards,
>
> Duncan Kennedy.
Hi Jos,

I'm sorrier for the stupid answers...

If an exception either occurs on a page before a Page_Error() handler
has been assigned or is not cleared by by a Page_Error() method then the
application will throw a HttpUnhandledException exception, which will
contain in its "innerException" property the exception that was
unhandled on the page.

As such you should still have your page exception when you're coding at
the Application_Error level, it will just be wrapped in another
exception. You could persist this somewhere appropriate if you wanted
to keep it to give a verbose report to the user when you finally
transferred the scope to an error page (Server.Redirect, defaultError in
web.config etc).

I hope this helps, Michael O'Donovan pointed out the following url on
error handling in another thread which might be useful:

http://msdn.microsoft.com/asp.net/u...ustomErrors.asp

Best of luck,

Duncan.

Jos Joye wrote:
> Hi Duncan,
> Thanks a lot for your really interesting reply.
> I'm actually in the process of getting up to speed with ASP.NET (sorry for
> the stupid questions ;-) )
> I still have an open question related to this topic.
> Say an exception is thrown in the Rendering part (preRendering/Rendering) of
> the form.
> This is actually out my scope. In that situation, if I do not have a
> Page_Error() defined, how could I record the kind of error that occured.
> If I understand it correctly, as soon as I get out of the Page scope, I will
> not have the exception available anymore if I did not save it manually
> somewhere (eg. : Session bag).
> If I defined an Application_Error handler (in Global.asax) will I have this
> information available?
> Thanks,
> Jos
>
> "Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> wrote in
> message news:ucyw3ZgeEHA.1692@.tk2msftngp13.phx.gbl...
>>Hi Jos,
>>
>>I think Lars is suggesting having the exception handled, or at least its
>>details stored somewhere, in the Application_Error method in
> "Global.asax".
>>It may be that perhaps your exception page doesn't need to show the
>>details of the exception to the end user, although I, of course, don't
>>know the details of your scenario. If you're principally interested in
>>apologizing to the user and publishing the details of the exception
>>somewhere developers can get hold of it (event log, email, file etc) you
>>could use Microsoft Exception Management Application block from:
>>
>>
> http://msdn.microsoft.com/library/d...tml/emab-rm.asp
>>
>>You could get around adding errorPage and Page_Error() code your
>>individual aspx pages by also setting the default error redirect in your
>>webconfig <customErrors> section:
>>
>> <customErrors mode="On" defaultRedirect="ErrorPage.aspx">
>> </customErrors>
>>
>>(mode attribute is explained in the comments preceding the section in
>>web.config, "On" is likely to be necessary for testing and debugging if
>>you're serving the pages from your own machine)
>>
>>In this way your page exception would not get handled on the page, would
>>propogate to the Global.asax handler, which would publish the exception
>>to whatever log your wanted, or perhaps store it in some accessible
>>storage, and *not* clear the error. Then the exception would propogate
>>to the defaultRedirect page in the web.config file, which could
>>apologize to the user and possibly use any persisted exception details.
>>
>>This works quite neatly, although it is worth noting that any resources
>>not handled by the ASP.NET isapi filter (for instance any legacy asp
>>pages you may be obliged to include) will require additional handling.
>>
>>There may well be faults with this method of handling things, and to be
>>honest it feels a little cumbersome defaulting to allowing the exception
>>to escalate to the application level, but I've certainly been obliged to
>>do it, and application level handling definitely should exist.
>>
>>Hope I didn't deviate to far from your question!
>>
>>
>>Regards,
>>
>>
>>Duncan Kennedy.
>
Thanks a lot for the explanation and for the great reference. I think that
I'm pretty clear on this topic now :-))
Jos
"Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> a crit dans
le message de news:euOxvEjeEHA.2812@.tk2msftngp13.phx.gbl...
> Hi Jos,
> I'm sorrier for the stupid answers...
> If an exception either occurs on a page before a Page_Error() handler
> has been assigned or is not cleared by by a Page_Error() method then the
> application will throw a HttpUnhandledException exception, which will
> contain in its "innerException" property the exception that was
> unhandled on the page.
> As such you should still have your page exception when you're coding at
> the Application_Error level, it will just be wrapped in another
> exception. You could persist this somewhere appropriate if you wanted
> to keep it to give a verbose report to the user when you finally
> transferred the scope to an error page (Server.Redirect, defaultError in
> web.config etc).
> I hope this helps, Michael O'Donovan pointed out the following url on
> error handling in another thread which might be useful:
>
http://msdn.microsoft.com/asp.net/u...ustomErrors.asp
> Best of luck,
> Duncan.
>
>
> Jos Joye wrote:
> > Hi Duncan,
> > Thanks a lot for your really interesting reply.
> > I'm actually in the process of getting up to speed with ASP.NET (sorry
for
> > the stupid questions ;-) )
> > I still have an open question related to this topic.
> > Say an exception is thrown in the Rendering part
(preRendering/Rendering) of
> > the form.
> > This is actually out my scope. In that situation, if I do not have a
> > Page_Error() defined, how could I record the kind of error that occured.
> > If I understand it correctly, as soon as I get out of the Page scope, I
will
> > not have the exception available anymore if I did not save it manually
> > somewhere (eg. : Session bag).
> > If I defined an Application_Error handler (in Global.asax) will I have
this
> > information available?
> > Thanks,
> > Jos
> > "Duncan Kennedy" <youmustbespammingme.contractor1@.achilles.com> wrote in
> > message news:ucyw3ZgeEHA.1692@.tk2msftngp13.phx.gbl...
> >>Hi Jos,
> >>
> >>I think Lars is suggesting having the exception handled, or at least its
> >>details stored somewhere, in the Application_Error method in
> > "Global.asax".
> >>It may be that perhaps your exception page doesn't need to show the
> >>details of the exception to the end user, although I, of course, don't
> >>know the details of your scenario. If you're principally interested in
> >>apologizing to the user and publishing the details of the exception
> >>somewhere developers can get hold of it (event log, email, file etc) you
> >>could use Microsoft Exception Management Application block from:
> >>
> >>
http://msdn.microsoft.com/library/d...tml/emab-rm.asp
> >>
> >>You could get around adding errorPage and Page_Error() code your
> >>individual aspx pages by also setting the default error redirect in your
> >>webconfig <customErrors> section:
> >>
> >> <customErrors mode="On" defaultRedirect="ErrorPage.aspx">
> >> </customErrors>
> >>
> >>(mode attribute is explained in the comments preceding the section in
> >>web.config, "On" is likely to be necessary for testing and debugging if
> >>you're serving the pages from your own machine)
> >>
> >>In this way your page exception would not get handled on the page, would
> >>propogate to the Global.asax handler, which would publish the exception
> >>to whatever log your wanted, or perhaps store it in some accessible
> >>storage, and *not* clear the error. Then the exception would propogate
> >>to the defaultRedirect page in the web.config file, which could
> >>apologize to the user and possibly use any persisted exception details.
> >>
> >>This works quite neatly, although it is worth noting that any resources
> >>not handled by the ASP.NET isapi filter (for instance any legacy asp
> >>pages you may be obliged to include) will require additional handling.
> >>
> >>There may well be faults with this method of handling things, and to be
> >>honest it feels a little cumbersome defaulting to allowing the exception
> >>to escalate to the application level, but I've certainly been obliged to
> >>do it, and application level handling definitely should exist.
> >>
> >>Hope I didn't deviate to far from your question!
> >>
> >>
> >>Regards,
> >>
> >>
> >>Duncan Kennedy.