1
1388-2/HB
I have a class file in my App_Code folder called "clsBasePage.vb" that looks
like this:
Public Class clsBasePage
Inherits System.Web.UI.Page
...stuff...
End Class
It's a "page" in that it inherits from ui.page, but has no .aspx file. It's
just a class file.
In creating a new page for my website, say mynewpage.aspx, I remove the
IDE's automatic header & form html so all it contains is this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="mynewpage.aspx.vb"
Inherits="mynewpage" %>
And I make mynewpage.aspx.vb inherit from clsBasePage, like this:
Partial Class mynewpage
Inherits clsBasePage
...stuff...
End Class
I've recently added this method to clsBasePage
Public Sub GetTheTextFromTheOtherWebsite()
Me.objWebClient = New System.Net.WebClient
With objWebClient
.Headers.Item(Net.HttpRequestHeader.Referer) = "localhost"
.Headers.Item(Net.HttpRequestHeader.UserAgent) = "my web app v1.0"
.BaseAddress = "https://www.theotherwebsite.com"
.DownloadStringAsync(New System.Uri("cgi/server/textmaker.exe",
UriKind.Relative))
End With
End Sub
When I call GetTheTextFromTheOtherWebsite from mynewpage, the
..DownloadStringAsync() method of the WebClient object is throwing this
error:
"Asynchronous operations are not allowed in this context. Page starting an
asynchronous operation has to have the Async attribute set to true and an
asynchronous operation can only be started on a page prior to
PreRenderComplete event."
I believe the typical "fix" for this would be to add the Async="true"
attribute to the @Page directive so that the page can perform an Async task.
Adding this value to mynewpage doesn't change anything, I think I need to
add it to clsBasePage instead. What's got me stumped here is that
clsBasePage doesn't have an .aspx file or a @Page directive at all, so I'm
not sure how to set that Async value to true on my base page class.
like this:
Public Class clsBasePage
Inherits System.Web.UI.Page
...stuff...
End Class
It's a "page" in that it inherits from ui.page, but has no .aspx file. It's
just a class file.
In creating a new page for my website, say mynewpage.aspx, I remove the
IDE's automatic header & form html so all it contains is this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="mynewpage.aspx.vb"
Inherits="mynewpage" %>
And I make mynewpage.aspx.vb inherit from clsBasePage, like this:
Partial Class mynewpage
Inherits clsBasePage
...stuff...
End Class
I've recently added this method to clsBasePage
Public Sub GetTheTextFromTheOtherWebsite()
Me.objWebClient = New System.Net.WebClient
With objWebClient
.Headers.Item(Net.HttpRequestHeader.Referer) = "localhost"
.Headers.Item(Net.HttpRequestHeader.UserAgent) = "my web app v1.0"
.BaseAddress = "https://www.theotherwebsite.com"
.DownloadStringAsync(New System.Uri("cgi/server/textmaker.exe",
UriKind.Relative))
End With
End Sub
When I call GetTheTextFromTheOtherWebsite from mynewpage, the
..DownloadStringAsync() method of the WebClient object is throwing this
error:
"Asynchronous operations are not allowed in this context. Page starting an
asynchronous operation has to have the Async attribute set to true and an
asynchronous operation can only be started on a page prior to
PreRenderComplete event."
I believe the typical "fix" for this would be to add the Async="true"
attribute to the @Page directive so that the page can perform an Async task.
Adding this value to mynewpage doesn't change anything, I think I need to
add it to clsBasePage instead. What's got me stumped here is that
clsBasePage doesn't have an .aspx file or a @Page directive at all, so I'm
not sure how to set that Async value to true on my base page class.