By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,853 Members | 842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,853 IT Pros & Developers. It's quick & easy.

Unhandled Exception in ASP.NET 2 asp:Menu control

P: n/a
I have a Windows service that requests web pages from a site using an
HttpWebRequest object. When I try to request a page from an ASP.NET 2 site,
I get a WebException with message "The remote server returned an error:
(500) Internal Server Error." I found a post that suggested to catch the
WebException to retrieve the actual HttpWebResponse object for more
information. The response returned is shown below.

At first I thought this was a problem with my web app, but I can now
reproduce this error with a very simple test case. I have created a Form
containing only a simple asp:Menu with a simple asp:SiteMapDataSource. The
page displays in an IE browser without error, but gets the excpetion shown
below when trying to retrieve the response via a HttpWebRequest with the
below code.

Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or could there
be another problem with my code or server. If a control problem, is it
possible to work around this problem. Thanks.

Chuck Hartman
-------------------------------------------
Uri homepage = new Uri("http://localhost/SCVCC/Default3.aspx");
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create(homepage);
httpWebRequest.Method = "GET";

HttpWebResponse response = null;
Stream stream = null;
try
{
response = (HttpWebResponse)httpWebRequest.GetResponse();
stream = response.GetResponseStream();
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
{
response = ex.Response as HttpWebResponse;
if (response != null)
{
stream = response.GetResponseStream();
}
}
}
StreamReader reader = new StreamReader(stream);
string sHtmlResponse = reader.ReadToEnd();

=============================
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e, Boolean
registerScript) +655
System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1787

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET
Version:2.0.50215.44
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Chuck,

Welcome to ASPNET newsgroup.
From your description, you're using the HttpWebRequest component to
programmatically request remote pages's content. it works well untial
you're trying to access a remote ASP.NET 2.0 page which contains a simple
Menu control. This page works well when we navigate through normal browser,
but continuously report non- reference error when accessing through the
HTTPwebrequest component, yes?

Based on my experience, it is likely caused by lack of the browser setting
info when we use HttpWebrequest to request the asp.net 2.0 page. In asp.net
2.0, most web server controls are designed as browser /device sensitive
which means the control will adjust the Output Rendering setting according
to the client side device, for example, it'll register different script
code according to different clientside browser. And Menu control will
retrieve such setting from the HttpRequest.Browser property and this
property is populated from the HTTP UserAgent header in the http request
from client. When we accessing the web page through httpwebrequest, we
generally don't set this field thus the serverside may not populate the
Request.Browser field or any sub fields. I think you can try setting the
HttpWebRequest's UserAgent propety (a string value). For example, the IE6
will use the following useragent header value:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)\

Please have a test on the above things.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Chuck Hartman" <Ch**********@online.nospam>
| Subject: Unhandled Exception in ASP.NET 2 asp:Menu control
| Date: Mon, 19 Sep 2005 12:07:27 -0700
| Lines: 80
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <en**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net 67.119.76.107
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125610
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have a Windows service that requests web pages from a site using an
| HttpWebRequest object. When I try to request a page from an ASP.NET 2
site,
| I get a WebException with message "The remote server returned an error:
| (500) Internal Server Error." I found a post that suggested to catch the
| WebException to retrieve the actual HttpWebResponse object for more
| information. The response returned is shown below.
|
| At first I thought this was a problem with my web app, but I can now
| reproduce this error with a very simple test case. I have created a Form
| containing only a simple asp:Menu with a simple asp:SiteMapDataSource.
The
| page displays in an IE browser without error, but gets the excpetion
shown
| below when trying to retrieve the response via a HttpWebRequest with the
| below code.
|
| Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or could
there
| be another problem with my code or server. If a control problem, is it
| possible to work around this problem. Thanks.
|
| Chuck Hartman
| -------------------------------------------
| Uri homepage = new Uri("http://localhost/SCVCC/Default3.aspx");
| HttpWebRequest httpWebRequest =
| (HttpWebRequest)WebRequest.Create(homepage);
| httpWebRequest.Method = "GET";
|
| HttpWebResponse response = null;
| Stream stream = null;
| try
| {
| response = (HttpWebResponse)httpWebRequest.GetResponse();
| stream = response.GetResponseStream();
| }
| catch (WebException ex)
| {
| if (ex.Status == WebExceptionStatus.ProtocolError)
| {
| response = ex.Response as HttpWebResponse;
| if (response != null)
| {
| stream = response.GetResponseStream();
| }
| }
| }
| StreamReader reader = new StreamReader(stream);
| string sHtmlResponse = reader.ReadToEnd();
|
| =============================
| Object reference not set to an instance of an object.
| Description: An unhandled exception occurred during the execution of the
| current web request. Please review the stack trace for more information
| about the error and where it originated in the code.
|
| Exception Details: System.NullReferenceException: Object reference not
set
| to an instance of an object.
|
| Source Error:
|
| An unhandled exception was generated during the execution of the current
web
| request. Information regarding the origin and location of the exception
can
| be identified using the exception stack trace below.
|
| Stack Trace:
|
|
| [NullReferenceException: Object reference not set to an instance of an
| object.]
| System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e, Boolean
| registerScript) +655
| System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
| System.Web.UI.Control.PreRenderRecursiveInternal() +77
| System.Web.UI.Control.PreRenderRecursiveInternal() +161
| System.Web.UI.Control.PreRenderRecursiveInternal() +161
| System.Web.UI.Page.ProcessRequestMain(Boolean
| includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1787
|
|
----------------------------------------------------------------------------
----
| Version Information: Microsoft .NET Framework Version:2.0.50215.44;
ASP.NET
| Version:2.0.50215.44
|
|
|

Nov 19 '05 #2

P: n/a
Steven,

Your suggestion does eliminate the crash in the Menu server control.
However, the Menu control does not render itself properly when the request
is initiated by the HttpWebRequest object. It does render properly when the
page is requested from IE 6.

I set a breakpoint for the server side menu control's Init event and took a
look at the Request object's UserAgent string when accessing with an IE
browser. It contained almost what you suggested:
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)"
I set the UserAgent string for the HttpWebRequest to the exact above string.
I now receive a response stream for ALMOST what would be expected. The Menu
control does not crash and most of the page is now rendered properly.
However, the Menu control does not render anything when the request comes
from the HttpWebRequest object. What else does the Menu control need in the
request to render itself properly? Thanks.

Chuck Hartman

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:X7**************@TK2MSFTNGXA01.phx.gbl...
Hi Chuck,

Welcome to ASPNET newsgroup.
From your description, you're using the HttpWebRequest component to
programmatically request remote pages's content. it works well untial
you're trying to access a remote ASP.NET 2.0 page which contains a simple
Menu control. This page works well when we navigate through normal
browser,
but continuously report non- reference error when accessing through the
HTTPwebrequest component, yes?

Based on my experience, it is likely caused by lack of the browser setting
info when we use HttpWebrequest to request the asp.net 2.0 page. In
asp.net
2.0, most web server controls are designed as browser /device sensitive
which means the control will adjust the Output Rendering setting according
to the client side device, for example, it'll register different script
code according to different clientside browser. And Menu control will
retrieve such setting from the HttpRequest.Browser property and this
property is populated from the HTTP UserAgent header in the http
request
from client. When we accessing the web page through httpwebrequest, we
generally don't set this field thus the serverside may not populate the
Request.Browser field or any sub fields. I think you can try setting the
HttpWebRequest's UserAgent propety (a string value). For example, the
IE6
will use the following useragent header value:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
1.1.4322)\

Please have a test on the above things.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Chuck Hartman" <Ch**********@online.nospam>
| Subject: Unhandled Exception in ASP.NET 2 asp:Menu control
| Date: Mon, 19 Sep 2005 12:07:27 -0700
| Lines: 80
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <en**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
67.119.76.107
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125610
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have a Windows service that requests web pages from a site using an
| HttpWebRequest object. When I try to request a page from an ASP.NET 2
site,
| I get a WebException with message "The remote server returned an error:
| (500) Internal Server Error." I found a post that suggested to catch
the
| WebException to retrieve the actual HttpWebResponse object for more
| information. The response returned is shown below.
|
| At first I thought this was a problem with my web app, but I can now
| reproduce this error with a very simple test case. I have created a Form
| containing only a simple asp:Menu with a simple asp:SiteMapDataSource.
The
| page displays in an IE browser without error, but gets the excpetion
shown
| below when trying to retrieve the response via a HttpWebRequest with the
| below code.
|
| Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or could
there
| be another problem with my code or server. If a control problem, is it
| possible to work around this problem. Thanks.
|
| Chuck Hartman
| -------------------------------------------
| Uri homepage = new Uri("http://localhost/SCVCC/Default3.aspx");
| HttpWebRequest httpWebRequest =
| (HttpWebRequest)WebRequest.Create(homepage);
| httpWebRequest.Method = "GET";
|
| HttpWebResponse response = null;
| Stream stream = null;
| try
| {
| response = (HttpWebResponse)httpWebRequest.GetResponse();
| stream = response.GetResponseStream();
| }
| catch (WebException ex)
| {
| if (ex.Status == WebExceptionStatus.ProtocolError)
| {
| response = ex.Response as HttpWebResponse;
| if (response != null)
| {
| stream = response.GetResponseStream();
| }
| }
| }
| StreamReader reader = new StreamReader(stream);
| string sHtmlResponse = reader.ReadToEnd();
|
| =============================
| Object reference not set to an instance of an object.
| Description: An unhandled exception occurred during the execution of the
| current web request. Please review the stack trace for more information
| about the error and where it originated in the code.
|
| Exception Details: System.NullReferenceException: Object reference not
set
| to an instance of an object.
|
| Source Error:
|
| An unhandled exception was generated during the execution of the current
web
| request. Information regarding the origin and location of the exception
can
| be identified using the exception stack trace below.
|
| Stack Trace:
|
|
| [NullReferenceException: Object reference not set to an instance of an
| object.]
| System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e, Boolean
| registerScript) +655
| System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
| System.Web.UI.Control.PreRenderRecursiveInternal() +77
| System.Web.UI.Control.PreRenderRecursiveInternal() +161
| System.Web.UI.Control.PreRenderRecursiveInternal() +161
| System.Web.UI.Page.ProcessRequestMain(Boolean
| includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1787
|
|
----------------------------------------------------------------------------
----
| Version Information: Microsoft .NET Framework Version:2.0.50215.44;
ASP.NET
| Version:2.0.50215.44
|
|
|

Nov 19 '05 #3

P: n/a
Sorry, the exact UserAgent string that I used was:
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322;
..NET CLR 2.0.50215)"

"Chuck Hartman" <Ch**********@online.nospam> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
Steven,

Your suggestion does eliminate the crash in the Menu server control.
However, the Menu control does not render itself properly when the request
is initiated by the HttpWebRequest object. It does render properly when
the page is requested from IE 6.

I set a breakpoint for the server side menu control's Init event and took
a look at the Request object's UserAgent string when accessing with an IE
browser. It contained almost what you suggested:
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
1.1.4322)"
I set the UserAgent string for the HttpWebRequest to the exact above
string. I now receive a response stream for ALMOST what would be expected.
The Menu control does not crash and most of the page is now rendered
properly. However, the Menu control does not render anything when the
request comes from the HttpWebRequest object. What else does the Menu
control need in the request to render itself properly? Thanks.

Chuck Hartman

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:X7**************@TK2MSFTNGXA01.phx.gbl...
Hi Chuck,

Welcome to ASPNET newsgroup.
From your description, you're using the HttpWebRequest component to
programmatically request remote pages's content. it works well untial
you're trying to access a remote ASP.NET 2.0 page which contains a simple
Menu control. This page works well when we navigate through normal
browser,
but continuously report non- reference error when accessing through the
HTTPwebrequest component, yes?

Based on my experience, it is likely caused by lack of the browser
setting
info when we use HttpWebrequest to request the asp.net 2.0 page. In
asp.net
2.0, most web server controls are designed as browser /device sensitive
which means the control will adjust the Output Rendering setting
according
to the client side device, for example, it'll register different script
code according to different clientside browser. And Menu control will
retrieve such setting from the HttpRequest.Browser property and this
property is populated from the HTTP UserAgent header in the http
request
from client. When we accessing the web page through httpwebrequest, we
generally don't set this field thus the serverside may not populate the
Request.Browser field or any sub fields. I think you can try setting the
HttpWebRequest's UserAgent propety (a string value). For example, the
IE6
will use the following useragent header value:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
1.1.4322)\

Please have a test on the above things.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Chuck Hartman" <Ch**********@online.nospam>
| Subject: Unhandled Exception in ASP.NET 2 asp:Menu control
| Date: Mon, 19 Sep 2005 12:07:27 -0700
| Lines: 80
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <en**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
67.119.76.107
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125610
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have a Windows service that requests web pages from a site using an
| HttpWebRequest object. When I try to request a page from an ASP.NET 2
site,
| I get a WebException with message "The remote server returned an error:
| (500) Internal Server Error." I found a post that suggested to catch
the
| WebException to retrieve the actual HttpWebResponse object for more
| information. The response returned is shown below.
|
| At first I thought this was a problem with my web app, but I can now
| reproduce this error with a very simple test case. I have created a
Form
| containing only a simple asp:Menu with a simple asp:SiteMapDataSource.
The
| page displays in an IE browser without error, but gets the excpetion
shown
| below when trying to retrieve the response via a HttpWebRequest with
the
| below code.
|
| Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or could
there
| be another problem with my code or server. If a control problem, is it
| possible to work around this problem. Thanks.
|
| Chuck Hartman
| -------------------------------------------
| Uri homepage = new Uri("http://localhost/SCVCC/Default3.aspx");
| HttpWebRequest httpWebRequest =
| (HttpWebRequest)WebRequest.Create(homepage);
| httpWebRequest.Method = "GET";
|
| HttpWebResponse response = null;
| Stream stream = null;
| try
| {
| response = (HttpWebResponse)httpWebRequest.GetResponse();
| stream = response.GetResponseStream();
| }
| catch (WebException ex)
| {
| if (ex.Status == WebExceptionStatus.ProtocolError)
| {
| response = ex.Response as HttpWebResponse;
| if (response != null)
| {
| stream = response.GetResponseStream();
| }
| }
| }
| StreamReader reader = new StreamReader(stream);
| string sHtmlResponse = reader.ReadToEnd();
|
| =============================
| Object reference not set to an instance of an object.
| Description: An unhandled exception occurred during the execution of
the
| current web request. Please review the stack trace for more information
| about the error and where it originated in the code.
|
| Exception Details: System.NullReferenceException: Object reference not
set
| to an instance of an object.
|
| Source Error:
|
| An unhandled exception was generated during the execution of the
current
web
| request. Information regarding the origin and location of the exception
can
| be identified using the exception stack trace below.
|
| Stack Trace:
|
|
| [NullReferenceException: Object reference not set to an instance of an
| object.]
| System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e, Boolean
| registerScript) +655
| System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
| System.Web.UI.Control.PreRenderRecursiveInternal() +77
| System.Web.UI.Control.PreRenderRecursiveInternal() +161
| System.Web.UI.Control.PreRenderRecursiveInternal() +161
| System.Web.UI.Page.ProcessRequestMain(Boolean
| includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1787
|
|
----------------------------------------------------------------------------
----
| Version Information: Microsoft .NET Framework Version:2.0.50215.44;
ASP.NET
| Version:2.0.50215.44
|
|
|


Nov 19 '05 #4

P: n/a
Thanks for your further followup Chuck,

Well since the problem still exists for HttpWebRequest sent request, I
think there must still have something we didn't provide in the request
message. Would you provide a simple test page(with menu control) that can
reproduce the behavior on your side to me? I'll perform some tests on my
side and try comparing the http message between Httpwebrequest sent message
and the IE generated one.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Chuck Hartman" <Ch**********@online.nospam>
| References: <en**************@TK2MSFTNGP12.phx.gbl>
<X7**************@TK2MSFTNGXA01.phx.gbl>
<ex**************@TK2MSFTNGP09.phx.gbl>
| Subject: Re: Unhandled Exception in ASP.NET 2 asp:Menu control
| Date: Tue, 20 Sep 2005 10:46:29 -0700
| Lines: 195
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <ut**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net 67.119.76.107
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125872
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Sorry, the exact UserAgent string that I used was:
| "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322;
| .NET CLR 2.0.50215)"
|
| "Chuck Hartman" <Ch**********@online.nospam> wrote in message
| news:ex**************@TK2MSFTNGP09.phx.gbl...
| > Steven,
| >
| > Your suggestion does eliminate the crash in the Menu server control.
| > However, the Menu control does not render itself properly when the
request
| > is initiated by the HttpWebRequest object. It does render properly
when
| > the page is requested from IE 6.
| >
| > I set a breakpoint for the server side menu control's Init event and
took
| > a look at the Request object's UserAgent string when accessing with an
IE
| > browser. It contained almost what you suggested:
| > "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
| > 1.1.4322)"
| > I set the UserAgent string for the HttpWebRequest to the exact above
| > string. I now receive a response stream for ALMOST what would be
expected.
| > The Menu control does not crash and most of the page is now rendered
| > properly. However, the Menu control does not render anything when the
| > request comes from the HttpWebRequest object. What else does the Menu
| > control need in the request to render itself properly? Thanks.
| >
| > Chuck Hartman
| >
| > "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| > news:X7**************@TK2MSFTNGXA01.phx.gbl...
| >> Hi Chuck,
| >>
| >> Welcome to ASPNET newsgroup.
| >> From your description, you're using the HttpWebRequest component to
| >> programmatically request remote pages's content. it works well untial
| >> you're trying to access a remote ASP.NET 2.0 page which contains a
simple
| >> Menu control. This page works well when we navigate through normal
| >> browser,
| >> but continuously report non- reference error when accessing through the
| >> HTTPwebrequest component, yes?
| >>
| >> Based on my experience, it is likely caused by lack of the browser
| >> setting
| >> info when we use HttpWebrequest to request the asp.net 2.0 page. In
| >> asp.net
| >> 2.0, most web server controls are designed as browser /device sensitive
| >> which means the control will adjust the Output Rendering setting
| >> according
| >> to the client side device, for example, it'll register different script
| >> code according to different clientside browser. And Menu control will
| >> retrieve such setting from the HttpRequest.Browser property and this
| >> property is populated from the HTTP UserAgent header in the http
| >> request
| >> from client. When we accessing the web page through httpwebrequest, we
| >> generally don't set this field thus the serverside may not populate the
| >> Request.Browser field or any sub fields. I think you can try setting
the
| >> HttpWebRequest's UserAgent propety (a string value). For example,
the
| >> IE6
| >> will use the following useragent header value:
| >>
| >> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
| >> 1.1.4322)\
| >>
| >> Please have a test on the above things.
| >>
| >> Thanks,
| >>
| >> Steven Cheng
| >> Microsoft Online Support
| >>
| >> Get Secure! www.microsoft.com/security
| >> (This posting is provided "AS IS", with no warranties, and confers no
| >> rights.)
| >>
| >>
| >> --------------------
| >> | From: "Chuck Hartman" <Ch**********@online.nospam>
| >> | Subject: Unhandled Exception in ASP.NET 2 asp:Menu control
| >> | Date: Mon, 19 Sep 2005 12:07:27 -0700
| >> | Lines: 80
| >> | X-Priority: 3
| >> | X-MSMail-Priority: Normal
| >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| >> | X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| >> | X-RFC2646: Format=Flowed; Original
| >> | Message-ID: <en**************@TK2MSFTNGP12.phx.gbl>
| >> | Newsgroups: microsoft.public.dotnet.framework.aspnet
| >> | NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
| >> 67.119.76.107
| >> | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| >> | Xref: TK2MSFTNGXA01.phx.gbl
| >> microsoft.public.dotnet.framework.aspnet:125610
| >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| >> |
| >> | I have a Windows service that requests web pages from a site using an
| >> | HttpWebRequest object. When I try to request a page from an ASP.NET
2
| >> site,
| >> | I get a WebException with message "The remote server returned an
error:
| >> | (500) Internal Server Error." I found a post that suggested to
catch
| >> the
| >> | WebException to retrieve the actual HttpWebResponse object for more
| >> | information. The response returned is shown below.
| >> |
| >> | At first I thought this was a problem with my web app, but I can now
| >> | reproduce this error with a very simple test case. I have created a
| >> Form
| >> | containing only a simple asp:Menu with a simple
asp:SiteMapDataSource.
| >> The
| >> | page displays in an IE browser without error, but gets the excpetion
| >> shown
| >> | below when trying to retrieve the response via a HttpWebRequest with
| >> the
| >> | below code.
| >> |
| >> | Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or
could
| >> there
| >> | be another problem with my code or server. If a control problem, is
it
| >> | possible to work around this problem. Thanks.
| >> |
| >> | Chuck Hartman
| >> | -------------------------------------------
| >> | Uri homepage = new Uri("http://localhost/SCVCC/Default3.aspx");
| >> | HttpWebRequest httpWebRequest =
| >> | (HttpWebRequest)WebRequest.Create(homepage);
| >> | httpWebRequest.Method = "GET";
| >> |
| >> | HttpWebResponse response = null;
| >> | Stream stream = null;
| >> | try
| >> | {
| >> | response = (HttpWebResponse)httpWebRequest.GetResponse();
| >> | stream = response.GetResponseStream();
| >> | }
| >> | catch (WebException ex)
| >> | {
| >> | if (ex.Status == WebExceptionStatus.ProtocolError)
| >> | {
| >> | response = ex.Response as HttpWebResponse;
| >> | if (response != null)
| >> | {
| >> | stream = response.GetResponseStream();
| >> | }
| >> | }
| >> | }
| >> | StreamReader reader = new StreamReader(stream);
| >> | string sHtmlResponse = reader.ReadToEnd();
| >> |
| >> | =============================
| >> | Object reference not set to an instance of an object.
| >> | Description: An unhandled exception occurred during the execution of
| >> the
| >> | current web request. Please review the stack trace for more
information
| >> | about the error and where it originated in the code.
| >> |
| >> | Exception Details: System.NullReferenceException: Object reference
not
| >> set
| >> | to an instance of an object.
| >> |
| >> | Source Error:
| >> |
| >> | An unhandled exception was generated during the execution of the
| >> current
| >> web
| >> | request. Information regarding the origin and location of the
exception
| >> can
| >> | be identified using the exception stack trace below.
| >> |
| >> | Stack Trace:
| >> |
| >> |
| >> | [NullReferenceException: Object reference not set to an instance of
an
| >> | object.]
| >> | System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e, Boolean
| >> | registerScript) +655
| >> | System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
| >> | System.Web.UI.Control.PreRenderRecursiveInternal() +77
| >> | System.Web.UI.Control.PreRenderRecursiveInternal() +161
| >> | System.Web.UI.Control.PreRenderRecursiveInternal() +161
| >> | System.Web.UI.Page.ProcessRequestMain(Boolean
| >> | includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
| >> +1787
| >> |
| >> |
| >>
----------------------------------------------------------------------------
| >> ----
| >> | Version Information: Microsoft .NET Framework Version:2.0.50215.44;
| >> ASP.NET
| >> | Version:2.0.50215.44
| >> |
| >> |
| >> |
| >>
| >
| >
|
|
|

Nov 19 '05 #5

P: n/a
Steven,

The mystery is solved.

I set up an external server to demonstrate the problem to you, but then I
could not reproduce the problem. The difference between the web apps was
Security Trimming was turned on in one app and not in the other. My browser
had a persistent Forms Authentication cookie so it showed all the menu
items. When my Windows service invoked the HttpWebRequest, it did not pass
in a CookieCollection, so it did not show any menu items. After I retrieved
and set the CookieCollection for the HttpWebRequest, all of the Menu items
are now rendered. In this case, it was my bad... Thanks for your help.

However, it is very nice that the ASP.NET 2.0 server controls can adjust
their rendering for different agents, but the lack of the UserAgent string
should not cause a control to crash. It would seem appropriate that the
Menu control should either render itself with an suitable default or throw
an appropriate exception that notifies you that the UserAgent string is
required. Thanks again.

Chuck Hartman

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:YW*************@TK2MSFTNGXA01.phx.gbl...
Thanks for your further followup Chuck,

Well since the problem still exists for HttpWebRequest sent request, I
think there must still have something we didn't provide in the request
message. Would you provide a simple test page(with menu control) that can
reproduce the behavior on your side to me? I'll perform some tests on my
side and try comparing the http message between Httpwebrequest sent
message
and the IE generated one.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Chuck Hartman" <Ch**********@online.nospam>
| References: <en**************@TK2MSFTNGP12.phx.gbl>
<X7**************@TK2MSFTNGXA01.phx.gbl>
<ex**************@TK2MSFTNGP09.phx.gbl>
| Subject: Re: Unhandled Exception in ASP.NET 2 asp:Menu control
| Date: Tue, 20 Sep 2005 10:46:29 -0700
| Lines: 195
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <ut**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
67.119.76.107
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125872
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Sorry, the exact UserAgent string that I used was:
| "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322;
| .NET CLR 2.0.50215)"
|
| "Chuck Hartman" <Ch**********@online.nospam> wrote in message
| news:ex**************@TK2MSFTNGP09.phx.gbl...
| > Steven,
| >
| > Your suggestion does eliminate the crash in the Menu server control.
| > However, the Menu control does not render itself properly when the
request
| > is initiated by the HttpWebRequest object. It does render properly
when
| > the page is requested from IE 6.
| >
| > I set a breakpoint for the server side menu control's Init event and
took
| > a look at the Request object's UserAgent string when accessing with an
IE
| > browser. It contained almost what you suggested:
| > "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
| > 1.1.4322)"
| > I set the UserAgent string for the HttpWebRequest to the exact above
| > string. I now receive a response stream for ALMOST what would be
expected.
| > The Menu control does not crash and most of the page is now rendered
| > properly. However, the Menu control does not render anything when the
| > request comes from the HttpWebRequest object. What else does the Menu
| > control need in the request to render itself properly? Thanks.
| >
| > Chuck Hartman
| >
| > "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| > news:X7**************@TK2MSFTNGXA01.phx.gbl...
| >> Hi Chuck,
| >>
| >> Welcome to ASPNET newsgroup.
| >> From your description, you're using the HttpWebRequest component to
| >> programmatically request remote pages's content. it works well untial
| >> you're trying to access a remote ASP.NET 2.0 page which contains a
simple
| >> Menu control. This page works well when we navigate through normal
| >> browser,
| >> but continuously report non- reference error when accessing through
the
| >> HTTPwebrequest component, yes?
| >>
| >> Based on my experience, it is likely caused by lack of the browser
| >> setting
| >> info when we use HttpWebrequest to request the asp.net 2.0 page. In
| >> asp.net
| >> 2.0, most web server controls are designed as browser /device
sensitive
| >> which means the control will adjust the Output Rendering setting
| >> according
| >> to the client side device, for example, it'll register different
script
| >> code according to different clientside browser. And Menu control
will
| >> retrieve such setting from the HttpRequest.Browser property and this
| >> property is populated from the HTTP UserAgent header in the http
| >> request
| >> from client. When we accessing the web page through httpwebrequest,
we
| >> generally don't set this field thus the serverside may not populate
the
| >> Request.Browser field or any sub fields. I think you can try setting
the
| >> HttpWebRequest's UserAgent propety (a string value). For example,
the
| >> IE6
| >> will use the following useragent header value:
| >>
| >> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
| >> 1.1.4322)\
| >>
| >> Please have a test on the above things.
| >>
| >> Thanks,
| >>
| >> Steven Cheng
| >> Microsoft Online Support
| >>
| >> Get Secure! www.microsoft.com/security
| >> (This posting is provided "AS IS", with no warranties, and confers no
| >> rights.)
| >>
| >>
| >> --------------------
| >> | From: "Chuck Hartman" <Ch**********@online.nospam>
| >> | Subject: Unhandled Exception in ASP.NET 2 asp:Menu control
| >> | Date: Mon, 19 Sep 2005 12:07:27 -0700
| >> | Lines: 80
| >> | X-Priority: 3
| >> | X-MSMail-Priority: Normal
| >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| >> | X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| >> | X-RFC2646: Format=Flowed; Original
| >> | Message-ID: <en**************@TK2MSFTNGP12.phx.gbl>
| >> | Newsgroups: microsoft.public.dotnet.framework.aspnet
| >> | NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
| >> 67.119.76.107
| >> | Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| >> | Xref: TK2MSFTNGXA01.phx.gbl
| >> microsoft.public.dotnet.framework.aspnet:125610
| >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| >> |
| >> | I have a Windows service that requests web pages from a site using
an
| >> | HttpWebRequest object. When I try to request a page from an
ASP.NET
2
| >> site,
| >> | I get a WebException with message "The remote server returned an
error:
| >> | (500) Internal Server Error." I found a post that suggested to
catch
| >> the
| >> | WebException to retrieve the actual HttpWebResponse object for more
| >> | information. The response returned is shown below.
| >> |
| >> | At first I thought this was a problem with my web app, but I can
now
| >> | reproduce this error with a very simple test case. I have created a
| >> Form
| >> | containing only a simple asp:Menu with a simple
asp:SiteMapDataSource.
| >> The
| >> | page displays in an IE browser without error, but gets the
excpetion
| >> shown
| >> | below when trying to retrieve the response via a HttpWebRequest
with
| >> the
| >> | below code.
| >> |
| >> | Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or
could
| >> there
| >> | be another problem with my code or server. If a control problem, is
it
| >> | possible to work around this problem. Thanks.
| >> |
| >> | Chuck Hartman
| >> | -------------------------------------------
| >> | Uri homepage = new Uri("http://localhost/SCVCC/Default3.aspx");
| >> | HttpWebRequest httpWebRequest =
| >> | (HttpWebRequest)WebRequest.Create(homepage);
| >> | httpWebRequest.Method = "GET";
| >> |
| >> | HttpWebResponse response = null;
| >> | Stream stream = null;
| >> | try
| >> | {
| >> | response = (HttpWebResponse)httpWebRequest.GetResponse();
| >> | stream = response.GetResponseStream();
| >> | }
| >> | catch (WebException ex)
| >> | {
| >> | if (ex.Status == WebExceptionStatus.ProtocolError)
| >> | {
| >> | response = ex.Response as HttpWebResponse;
| >> | if (response != null)
| >> | {
| >> | stream = response.GetResponseStream();
| >> | }
| >> | }
| >> | }
| >> | StreamReader reader = new StreamReader(stream);
| >> | string sHtmlResponse = reader.ReadToEnd();
| >> |
| >> | =============================
| >> | Object reference not set to an instance of an object.
| >> | Description: An unhandled exception occurred during the execution
of
| >> the
| >> | current web request. Please review the stack trace for more
information
| >> | about the error and where it originated in the code.
| >> |
| >> | Exception Details: System.NullReferenceException: Object reference
not
| >> set
| >> | to an instance of an object.
| >> |
| >> | Source Error:
| >> |
| >> | An unhandled exception was generated during the execution of the
| >> current
| >> web
| >> | request. Information regarding the origin and location of the
exception
| >> can
| >> | be identified using the exception stack trace below.
| >> |
| >> | Stack Trace:
| >> |
| >> |
| >> | [NullReferenceException: Object reference not set to an instance of
an
| >> | object.]
| >> | System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e, Boolean
| >> | registerScript) +655
| >> | System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
| >> | System.Web.UI.Control.PreRenderRecursiveInternal() +77
| >> | System.Web.UI.Control.PreRenderRecursiveInternal() +161
| >> | System.Web.UI.Control.PreRenderRecursiveInternal() +161
| >> | System.Web.UI.Page.ProcessRequestMain(Boolean
| >> | includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint)
| >> +1787
| >> |
| >> |
| >>
----------------------------------------------------------------------------
| >> ----
| >> | Version Information: Microsoft .NET Framework Version:2.0.50215.44;
| >> ASP.NET
| >> | Version:2.0.50215.44
| >> |
| >> |
| >> |
| >>
| >
| >
|
|
|

Nov 19 '05 #6

P: n/a
Hi Chuck,

Thanks for your followup. First, I'm glad that you've figured out the
problem. Also, as for the
=============
It would seem appropriate that the
Menu control should either render itself with an suitable default or throw
an appropriate exception that notifies you that the UserAgent string is
required.
=============

you mentioned, IMO, this is a reasonable behavior since webserver control
can require that the client request for a certain page always have a valid
Brower Capability info(UserAgent). And how to deal with the case that
client side may not provide UserAgent should be the ASP.NET application's
duty. for ASP.NET begin with 1.x, we can define clientside browser Info
mapping schema through the <browserCaps> ELEMENT under the
<system.web> sectionGroup. The default setting is to use "UserAgent" http
header to generate the BrowserCapability info for the client request (hold
in the Request.Browser property). So we can define the mapping for empty
UserAgent value in it. If you have interests, you can have a look at the
global level(machine.config or the global web.config) which contains the
default settings.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Chuck Hartman" <Ch**********@online.nospam>
| References: <en**************@TK2MSFTNGP12.phx.gbl>
<X7**************@TK2MSFTNGXA01.phx.gbl>
<ex**************@TK2MSFTNGP09.phx.gbl>
<ut**************@TK2MSFTNGP12.phx.gbl>
<YW*************@TK2MSFTNGXA01.phx.gbl>
| Subject: Re: Unhandled Exception in ASP.NET 2 asp:Menu control
| Date: Wed, 21 Sep 2005 12:04:34 -0700
| Lines: 297
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <eG*************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net 67.119.76.107
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:126208
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| The mystery is solved.
|
| I set up an external server to demonstrate the problem to you, but then I
| could not reproduce the problem. The difference between the web apps was
| Security Trimming was turned on in one app and not in the other. My
browser
| had a persistent Forms Authentication cookie so it showed all the menu
| items. When my Windows service invoked the HttpWebRequest, it did not
pass
| in a CookieCollection, so it did not show any menu items. After I
retrieved
| and set the CookieCollection for the HttpWebRequest, all of the Menu
items
| are now rendered. In this case, it was my bad... Thanks for your help.
|
| However, it is very nice that the ASP.NET 2.0 server controls can adjust
| their rendering for different agents, but the lack of the UserAgent
string
| should not cause a control to crash. It would seem appropriate that the
| Menu control should either render itself with an suitable default or
throw
| an appropriate exception that notifies you that the UserAgent string is
| required. Thanks again.
|
| Chuck Hartman
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:YW*************@TK2MSFTNGXA01.phx.gbl...
| > Thanks for your further followup Chuck,
| >
| > Well since the problem still exists for HttpWebRequest sent request, I
| > think there must still have something we didn't provide in the request
| > message. Would you provide a simple test page(with menu control) that
can
| > reproduce the behavior on your side to me? I'll perform some tests on my
| > side and try comparing the http message between Httpwebrequest sent
| > message
| > and the IE generated one.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | From: "Chuck Hartman" <Ch**********@online.nospam>
| > | References: <en**************@TK2MSFTNGP12.phx.gbl>
| > <X7**************@TK2MSFTNGXA01.phx.gbl>
| > <ex**************@TK2MSFTNGP09.phx.gbl>
| > | Subject: Re: Unhandled Exception in ASP.NET 2 asp:Menu control
| > | Date: Tue, 20 Sep 2005 10:46:29 -0700
| > | Lines: 195
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Response
| > | Message-ID: <ut**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
| > 67.119.76.107
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:125872
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Sorry, the exact UserAgent string that I used was:
| > | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
| > 1.1.4322;
| > | .NET CLR 2.0.50215)"
| > |
| > | "Chuck Hartman" <Ch**********@online.nospam> wrote in message
| > | news:ex**************@TK2MSFTNGP09.phx.gbl...
| > | > Steven,
| > | >
| > | > Your suggestion does eliminate the crash in the Menu server control.
| > | > However, the Menu control does not render itself properly when the
| > request
| > | > is initiated by the HttpWebRequest object. It does render properly
| > when
| > | > the page is requested from IE 6.
| > | >
| > | > I set a breakpoint for the server side menu control's Init event and
| > took
| > | > a look at the Request object's UserAgent string when accessing with
an
| > IE
| > | > browser. It contained almost what you suggested:
| > | > "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
| > | > 1.1.4322)"
| > | > I set the UserAgent string for the HttpWebRequest to the exact above
| > | > string. I now receive a response stream for ALMOST what would be
| > expected.
| > | > The Menu control does not crash and most of the page is now rendered
| > | > properly. However, the Menu control does not render anything when
the
| > | > request comes from the HttpWebRequest object. What else does the
Menu
| > | > control need in the request to render itself properly? Thanks.
| > | >
| > | > Chuck Hartman
| > | >
| > | > "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| > | > news:X7**************@TK2MSFTNGXA01.phx.gbl...
| > | >> Hi Chuck,
| > | >>
| > | >> Welcome to ASPNET newsgroup.
| > | >> From your description, you're using the HttpWebRequest component to
| > | >> programmatically request remote pages's content. it works well
untial
| > | >> you're trying to access a remote ASP.NET 2.0 page which contains a
| > simple
| > | >> Menu control. This page works well when we navigate through normal
| > | >> browser,
| > | >> but continuously report non- reference error when accessing
through
| > the
| > | >> HTTPwebrequest component, yes?
| > | >>
| > | >> Based on my experience, it is likely caused by lack of the browser
| > | >> setting
| > | >> info when we use HttpWebrequest to request the asp.net 2.0 page. In
| > | >> asp.net
| > | >> 2.0, most web server controls are designed as browser /device
| > sensitive
| > | >> which means the control will adjust the Output Rendering setting
| > | >> according
| > | >> to the client side device, for example, it'll register different
| > script
| > | >> code according to different clientside browser. And Menu control
| > will
| > | >> retrieve such setting from the HttpRequest.Browser property and
this
| > | >> property is populated from the HTTP UserAgent header in the http
| > | >> request
| > | >> from client. When we accessing the web page through
httpwebrequest,
| > we
| > | >> generally don't set this field thus the serverside may not
populate
| > the
| > | >> Request.Browser field or any sub fields. I think you can try
setting
| > the
| > | >> HttpWebRequest's UserAgent propety (a string value). For example,
| > the
| > | >> IE6
| > | >> will use the following useragent header value:
| > | >>
| > | >> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR
| > | >> 1.1.4322)\
| > | >>
| > | >> Please have a test on the above things.
| > | >>
| > | >> Thanks,
| > | >>
| > | >> Steven Cheng
| > | >> Microsoft Online Support
| > | >>
| > | >> Get Secure! www.microsoft.com/security
| > | >> (This posting is provided "AS IS", with no warranties, and confers
no
| > | >> rights.)
| > | >>
| > | >>
| > | >> --------------------
| > | >> | From: "Chuck Hartman" <Ch**********@online.nospam>
| > | >> | Subject: Unhandled Exception in ASP.NET 2 asp:Menu control
| > | >> | Date: Mon, 19 Sep 2005 12:07:27 -0700
| > | >> | Lines: 80
| > | >> | X-Priority: 3
| > | >> | X-MSMail-Priority: Normal
| > | >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | >> | X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | >> | X-RFC2646: Format=Flowed; Original
| > | >> | Message-ID: <en**************@TK2MSFTNGP12.phx.gbl>
| > | >> | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | >> | NNTP-Posting-Host: adsl-67-119-76-107.dsl.sntc01.pacbell.net
| > | >> 67.119.76.107
| > | >> | Path:
| > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| > | >> | Xref: TK2MSFTNGXA01.phx.gbl
| > | >> microsoft.public.dotnet.framework.aspnet:125610
| > | >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | >> |
| > | >> | I have a Windows service that requests web pages from a site
using
| > an
| > | >> | HttpWebRequest object. When I try to request a page from an
| > ASP.NET
| > 2
| > | >> site,
| > | >> | I get a WebException with message "The remote server returned an
| > error:
| > | >> | (500) Internal Server Error." I found a post that suggested to
| > catch
| > | >> the
| > | >> | WebException to retrieve the actual HttpWebResponse object for
more
| > | >> | information. The response returned is shown below.
| > | >> |
| > | >> | At first I thought this was a problem with my web app, but I can
| > now
| > | >> | reproduce this error with a very simple test case. I have
created a
| > | >> Form
| > | >> | containing only a simple asp:Menu with a simple
| > asp:SiteMapDataSource.
| > | >> The
| > | >> | page displays in an IE browser without error, but gets the
| > excpetion
| > | >> shown
| > | >> | below when trying to retrieve the response via a HttpWebRequest
| > with
| > | >> the
| > | >> | below code.
| > | >> |
| > | >> | Is this a problem in the ASP.NET 2 Menu or SiteMapDataSource, or
| > could
| > | >> there
| > | >> | be another problem with my code or server. If a control problem,
is
| > it
| > | >> | possible to work around this problem. Thanks.
| > | >> |
| > | >> | Chuck Hartman
| > | >> | -------------------------------------------
| > | >> | Uri homepage = new
Uri("http://localhost/SCVCC/Default3.aspx");
| > | >> | HttpWebRequest httpWebRequest =
| > | >> | (HttpWebRequest)WebRequest.Create(homepage);
| > | >> | httpWebRequest.Method = "GET";
| > | >> |
| > | >> | HttpWebResponse response = null;
| > | >> | Stream stream = null;
| > | >> | try
| > | >> | {
| > | >> | response = (HttpWebResponse)httpWebRequest.GetResponse();
| > | >> | stream = response.GetResponseStream();
| > | >> | }
| > | >> | catch (WebException ex)
| > | >> | {
| > | >> | if (ex.Status == WebExceptionStatus.ProtocolError)
| > | >> | {
| > | >> | response = ex.Response as HttpWebResponse;
| > | >> | if (response != null)
| > | >> | {
| > | >> | stream = response.GetResponseStream();
| > | >> | }
| > | >> | }
| > | >> | }
| > | >> | StreamReader reader = new StreamReader(stream);
| > | >> | string sHtmlResponse = reader.ReadToEnd();
| > | >> |
| > | >> | =============================
| > | >> | Object reference not set to an instance of an object.
| > | >> | Description: An unhandled exception occurred during the
execution
| > of
| > | >> the
| > | >> | current web request. Please review the stack trace for more
| > information
| > | >> | about the error and where it originated in the code.
| > | >> |
| > | >> | Exception Details: System.NullReferenceException: Object
reference
| > not
| > | >> set
| > | >> | to an instance of an object.
| > | >> |
| > | >> | Source Error:
| > | >> |
| > | >> | An unhandled exception was generated during the execution of the
| > | >> current
| > | >> web
| > | >> | request. Information regarding the origin and location of the
| > exception
| > | >> can
| > | >> | be identified using the exception stack trace below.
| > | >> |
| > | >> | Stack Trace:
| > | >> |
| > | >> |
| > | >> | [NullReferenceException: Object reference not set to an instance
of
| > an
| > | >> | object.]
| > | >> | System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e,
Boolean
| > | >> | registerScript) +655
| > | >> | System.Web.UI.WebControls.Menu.OnPreRender(EventAr gs e) +22
| > | >> | System.Web.UI.Control.PreRenderRecursiveInternal() +77
| > | >> | System.Web.UI.Control.PreRenderRecursiveInternal() +161
| > | >> | System.Web.UI.Control.PreRenderRecursiveInternal() +161
| > | >> | System.Web.UI.Page.ProcessRequestMain(Boolean
| > | >> | includeStagesBeforeAsyncPoint, Boolean
| > includeStagesAfterAsyncPoint)
| > | >> +1787
| > | >> |
| > | >> |
| > | >>
| >
----------------------------------------------------------------------------
| > | >> ----
| > | >> | Version Information: Microsoft .NET Framework
Version:2.0.50215.44;
| > | >> ASP.NET
| > | >> | Version:2.0.50215.44
| > | >> |
| > | >> |
| > | >> |
| > | >>
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #7

P: n/a
This should be fixed! What about all the various search engine spiders
out there that wont be able to index peoples sites because they throw
exceptions. How will developers even know why their sites arent being
indexed!

Jim

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.