I have a class file in my App_Code folder called "clsBasePage.vb" that looks
Public Class clsBasePage
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"
And I make mynewpage.aspx.vb inherit from clsBasePage, like this:
Partial Class mynewpage
I've recently added this method to clsBasePage
Public Sub GetTheTextFromTheOtherWebsite()
Me.objWebClient = New System.Net.WebClient
.Headers.Item(Net.HttpRequestHeader.Referer) = "localhost"
.Headers.Item(Net.HttpRequestHeader.UserAgent) = "my web app v1.0"
.BaseAddress = "https://www.theotherwebsite.com"
When I call GetTheTextFromTheOtherWebsite from mynewpage, the
.DownloadStringAsync() method of the WebClient object is throwing this
"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
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.