Solved

WebException when trying to retrieve HTML created from another ASPX page.

Posted on 2008-10-28
2
282 Views
Last Modified: 2013-12-17
Hi,

I am receiving a WebException when I post and retrieve HTML from an ASPX Page.
The page is responsible for creating a branded email:

  http://www.hesgroup.com.au/email/emailtemplate.aspx

The following fields are posted to it:

            string toName = string.IsNullOrEmpty(Request.Form["toName"]) ? String.Empty : Server.UrlDecode(Request.Form["toName"]);
            string toEmail = string.IsNullOrEmpty(Request.Form["toEmail"]) ? String.Empty : Server.UrlDecode(Request.Form["toEmail"]);
            string fromName = string.IsNullOrEmpty(Request.Form["fromName"]) ? String.Empty : Server.UrlDecode(Request.Form["fromName"]);
            string fromEmail = string.IsNullOrEmpty(Request.Form["fromEmail"]) ? String.Empty : Server.UrlDecode(Request.Form["fromEmail"]);
            string subject = string.IsNullOrEmpty(Request.Form["subject"]) ? String.Empty : Server.UrlDecode(Request.Form["subject"]);
            string message = string.IsNullOrEmpty(Request.Form["message"]) ? String.Empty : Server.UrlDecode(Request.Form["message"]);


The error being returned is a 500 server error and does not help me in anyway debug.
I am also retrieving the exception details (see code below) to help with debug but still cannot resolve:

I have attached all the code (in a zip file) needed to reproduce error including a 'Contact Us' page that will post fields to page creating the email.
In summary, this page posts to the email template, and then retrieves the HTML and sends the HTML by email to customer and client.

This library has never failed me until this project and I cannot seem to resolve.
My money is on an OVERFLOW error in the byte code when adding post keys.

Would love a HTTP expert to help with this - any help appreciated.

SHOULD BE EASY TO RUN ALL FILES!!

Thanks for your time.


----------------------
 

           string toName = string.IsNullOrEmpty(Request.Form["toName"]) ? String.Empty : Server.UrlDecode(Request.Form["toName"]);

            string toEmail = string.IsNullOrEmpty(Request.Form["toEmail"]) ? String.Empty : Server.UrlDecode(Request.Form["toEmail"]);

            string fromName = string.IsNullOrEmpty(Request.Form["fromName"]) ? String.Empty : Server.UrlDecode(Request.Form["fromName"]);

            string fromEmail = string.IsNullOrEmpty(Request.Form["fromEmail"]) ? String.Empty : Server.UrlDecode(Request.Form["fromEmail"]);

            string subject = string.IsNullOrEmpty(Request.Form["subject"]) ? String.Empty : Server.UrlDecode(Request.Form["subject"]);

            string message = string.IsNullOrEmpty(Request.Form["message"]) ? String.Empty : Server.UrlDecode(Request.Form["message"]);
 

------------------------------------------
 
 

catch (WebException wex)

            {

                if (this._doThrowExceptions)

                    throw wex;
 

                if (wex.Status == WebExceptionStatus.ProtocolError)

                {

                    HttpWebResponse response = wex.Response as HttpWebResponse;

                    if (response != null)

                    {

                        this._errorMessage = "HttpWebResponse.StatusCode=" + response.StatusCode + "|HttpWebResponse.StatusDescription=" + response.StatusDescription + "|" + wex.Message;

                    }

                }

                else

                {

                    this._errorMessage = wex.Message;

                }

                this._hasError = true;

                return null;

            }

Open in new window

0
Comment
Question by:smacca
2 Comments
 
LVL 2

Accepted Solution

by:
smokingspaceman earned 500 total points
ID: 22820009
http://www.asp.net/learn/whitepapers/request-validation/

The error you could be getting is probably due to request validation. Try turning it off.

<%@ Page Language="VB" validateRequest="false"...>

This disables a security feature used for preventing script attacks.
0
 

Author Closing Comment

by:smacca
ID: 31511026
Spot on!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now