0
我試圖在Page_Load方法內的Azure託管的網頁上執行異步任務。但是我收到上述錯誤。我已經在aspx文件中將頁面的Async屬性設置爲true,但仍然沒有運氣。該操作要求頁面是異步的(異步屬性必須設置爲true)。
ASP部首代碼:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SalesAndCCFAQ.FAQ" Async ="true"%>
的Page_Load代碼:
protected void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(test));
Page.ExecuteRegisteredAsyncTasks();
//Only need to fill catDropDown when the page is first directed to
if (!Page.IsPostBack)
{
fillCatDropDown();
//Show who is currently logged in
currentUserLabel.Text += HttpContext.Current.User.Identity.Name;
}
if (GlobalUse.external == true)
{
whichApproved = "approvedExternal = 1";
greenKeyImage.Visible = false;
greenKeyLabel.Visible = false;
yellowKeyImage.Visible = false;
yellowKeyLabel.Visible = false;
redKeyImage.Visible = false;
redKeyLabel.Visible = false;
}
else
{
whichApproved = "approvedInternal = 1";
}
//String to be added to main query if a category is selected
filterCatQuery = "cid = (SELECT cid FROM Category WHERE name = '" + catDropDown.Text + "')";
}
Page_PreInit代碼:
protected void Page_PreInit()
{
if (!Page.IsPostBack)
{
if (GlobalUse.external == true)
{
this.MasterPageFile = "~/SiteExternal.Master";
}
}
}
異步函數被調用:
protected async Task test()
{
if (GlobalUse.external != null)
return;
await GlobalUse.isUserExternalGroup(); //This method sets GlobalUse.external
Response.Redirect("~/Default.aspx"); //Refresh to call the PreInit Code again
}