Ajax Exception Handling

C

Chuck

I have an HttpModule I use for exception handling.
Essentially it handles
AppDomain.CurrentDomain.UnhandledException
and
application.Error

When an exception occurs I log it and then do a response.clear
and stick some new html into the response, giving the user a nice error
message.
The html error message shows up on his requested page.

If I have an exception within an Ajax update panel, the logging still works.
However, sticking stuff into the Response does not.

I wrote the HttpModule because I can drop-it-in on all of our websites, with
no coding needed on the sites webpages.

Is their a way to get my error message html sent back to the user/page and
still keeping all my exception handling code contained with the HttpModule?

thanks,
 
A

Andrew Morton

I have an HttpModule I use for exception handling.
Essentially it handles
AppDomain.CurrentDomain.UnhandledException
and
application.Error

When an exception occurs I log it and then do a response.clear
and stick some new html into the response, giving the user a nice error
message.
The html error message shows up on his requested page.

Why not handle the error explicitly, using try...catch?
I wrote the HttpModule because I can drop-it-in on all of our websites,
with no coding needed on the sites webpages.

Ah, but you can't get away with it that easily. To wit:
When an exception occurs I log it and then do a response.clear
If I have an exception within an Ajax update panel, the logging still
works. However, sticking stuff into the Response does not.

"Sticking stuff into the Response" is usually a bad idea with ASP.NET.

The code handling that AJAX call should deal with the exception and be
handling error conditions and adjusting its output, not some "catch-all"
handler.

ICBW, but to me it looks like the way you're doing it is a kludge.

Andrew
 
A

Allen Chen [MSFT]

Hi,
I have an HttpModule I use for exception handling.
Essentially it handles
AppDomain.CurrentDomain.UnhandledException
and
application.Error

My suggestion is to use Response.Redirect() to redirect to an error.aspx
page instead of directly writing content into response. The benefit is,
it's much easier to edit the error page than hard coding it. In addition,
this approach works for AJAX postback as well.

Please have a try and let me know if it works.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chuck

With the Ajax I don't see anyway other than Redirect or Server.Transfer.
However, this is a HttpModule so I will probably have to use a Virtual Path
Provider for the redirect page since it will be an embedded resource.
 
A

Allen Chen [MSFT]

Hi,
With the Ajax I don't see anyway other than Redirect or Server.Transfer.
However, this is a HttpModule so I will probably have to use a Virtual Path
Provider for the redirect page since it will be an embedded resource.

Virtual Path Provider should work when using Response.Redirect and
Server.Transfer. However, Server.Transfer, in most cases, will not work in
an AJAX Postback. Server.Transfer is a kind of server side postback, namely
you send an AJAX Postback to server, server then runs Server.Transfer to
transfer the posted data to a page on the same server. The terminal page
gets and handles the posted data. Therefore, in most cases the sent back
data cannot be correctly recognized by AJAX client side logic.

So please use Response.Redirect. If you have additional questions please
don't hesitate to let me know.

Regards,
Allen Chen
Microsoft Online Support
 
C

Chuck

So how can I use response.redirect to an embedded aspx file.
When I tried that by using the normal methods(just get the path to the
embedded resource), the aspx file displays but does not compile.
If I use a Virtual Path Provider, I don't know a way to get the path to the
compiled aspx file and give it to Response.Redirect.
 
A

Allen Chen [MSFT]

Hi,
So how can I use response.redirect to an embedded aspx file.
When I tried that by using the normal methods(just get the path to the
embedded resource), the aspx file displays but does not compile.
If I use a Virtual Path Provider, I don't know a way to get the path to the
compiled aspx file and give it to Response.Redirect.

Could you tell me why do you say "I don't know a way to get the path to the
compiled aspx file"? If you're using Virtual Path Provider you can control
the path.

I've created a sample that slightly changes the code of
http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx?msg=2940045

What I did in the code is to catch exception in global.asax. In async
postback, throw an exception. User will then be redirected to a page.

http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/NG|_embedde
d%7C_resources.zip

Regards,
Allen Chen
Microsoft Online Support
 
C

Chuck

When using Response.Redirect("wantsAtextValueForThePath") it wants a Path to
the file to redirect to. Getting the path to embedded resource is easy. I
don't know how to get the path to a an embedded resource that has been
compiled by the Virtual Path Provider.

With Virtual Path Provider you are returned an IHttpHandler not a path to
the compiled file.

This is great for Server.Transfer(StringPath or IHttpHandler); But I can't
use Server.Transfer because of Ajax.

When I use the VPP I do it like this:
IHttpHandler virtualPage =
(Page)System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath("~/App_Resource/Util.dll/"
+ "Util.ExceptionHandler.ExceptionViewer.aspx", typeof(Page));

virtualPage.ProcessRequest(HttpContext.Current);

While I now have a compiled page. I don't know how to get a Path to the
compiled page. I belive I need the Path to the compiled file if I am going
to use Response.Redirect.
 
A

Allen Chen [MSFT]

Hi,
With Virtual Path Provider you are returned an IHttpHandler not a path to
the compiled file.

I'm a little confused. Could you please tell me why you cannot get the path
of the compiled page? In the project mentioned in my previous post, the
path is:

App_Resource/WebApplicationControls.dll/WebApplicationControls.WebForm1.aspx

Is there anything I missed?
I belive I need the Path to the compiled file if I am going
to use Response.Redirect.

The URL you passed to Response.Redirect is not the physical path of the
compiled dll. It's only a URL. How to handle it depends on many factors
such as Hanlder mapping in IIS, etc.

You can send me a demo that can reproduce the problem you're facing to. I
am willing to test it on my side.

My email is (e-mail address removed) update here after sending the
project in case I missed that email.

Regards,
Allen Chen
Microsoft Online Support
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
L

laurens brown

UNITED NATIONS COMPENSATION UNIT IN AFFILIATION WITH WORLD BANK
From:, Special Envoy to Secretary-General Laurens Nicholas
Atten: Beneficiary

We have been having a meeting for the past 7 months which just ended 2
days ago with the secretary to the UNITED NATIONS. This email is to all
the people that have been victim in any part of the world, the UNITED
NATIONS IN Affiliation with WORLD BANK have agreed to compensate you
with the sum of $1,900.000.00 USD, for self support.This is regarding
the draws he organized before he left the office to help individuals to
own a self charity organization also for your to build your Personal
Company/organization so as to help the less privileged in there society.

This includes every foreign contractors that may have not received their
contract, inheritance & lotto sum, and people that have had an
unfinished transaction or international businesses that failed due to
Government problems etc. We found your name in the list of those who are
to benefit from these compensation exercise and that is why we are
contacting you, this have been agreed upon and have been signed You are
advised to contact Us here in Benin Republic, as he is our
representative in Benin, contact him immediately for your Draft of
$1,900.000.00 USD.

This funds are in a Bank Draft for security purpose ok?, so he will send
it to you and you can clear it in any bank of your choice. Therefore,
you should send him your full Name and telephone number your correct
mailing address where you want him to send the Draft to you. Contact Us
immediately for your FUNDS at the given address below:
Comapny Name:
Contact
E-MAIL:
E-MAIL:
PHONE: +

I apologize on behalf of my organization for any delay you might have
encountered in receiving your fund in the past. Thanks and God bless you
and your family. Hoping to hear from you as soon as you cash your FUNDS.
Regards,
Secretary Gen. Laurens Nicholas
United Nations Fund $1,900.000.00 USD.
Secretary- Office
United Nations Fund Supporting Dept
http://www.unorg/sg
Email: (e-mail address removed)
Tel:+22995130320
 
A

Allen Chen [MSFT]

Hi,
With Virtual Path Provider you are returned an IHttpHandler not a path to
the compiled file.

Have you solved this issue?

Regards,
Allen Chen
Microsoft Online Support
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top