473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Unhandled Exception in ASP.NET 2 asp:Menu control

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
7 2645
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: tfsmag | last post by:
Has anyone had a problem with putting a menu control into a master page in .net 2.0? I have a problem where if i just drop a menu control on a regular page the menu works fine, the submenus work...
4
by: Ben | last post by:
Hi, I'm using images in my menu control. I have my menu setup based on this example: http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.menuitembinding.imageurlfield(VS.80).aspx ...
2
by: Mark Rae | last post by:
Hi, I'm interested in what people think of the new <asp:Menu> control in comparison to other 3rd-party menu controls. E.g. until v2, I used the AITOC FlexMenu...
0
by: chris.mcinnes | last post by:
G'day, I'm trying to implement a graphical horizontal Menu-bar feeding off a SiteMapDataSource with some top-level menu-items and a couple of sub-menus. I've managed to get the menu bar...
2
by: jason | last post by:
Does anybody know how I would get borders around each menuitem? Do I have incorportate into a table? Thanks. The below produces a border around the entire menu. <form id="form1" runat="server">...
2
by: Steve Richter | last post by:
I would like to have a standard site navigation menu, horizontal across the page, at the top of the page. When I hover over a top level menu item I want a drop down menu to appear with the same...
1
by: eps | last post by:
Has anyone have any experience of doing this ? I want a small menu on each row with a few options, I have tried it and it seems to work great at first but after clicking on a menu item and...
3
by: win | last post by:
I've create menu in a webform. <asp:Menu ID="Menu1" runat="server" CssClass="toolbar" Orientation="Horizontal"> <Items> <asp:MenuItem Text="Master" Value="Master"> <asp:MenuItem...
0
by: BooGhost | last post by:
Some background: 1. I've got a master page with an asp:Menu using an XML sitemap. 2. A page that uses the master page has an object tag (instancing an activex control) 3. This activex control...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.