2016-09-07 52 views
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 
    } 

回答

1

此错误被抛出的原因是因为它是我的默认页面。我修复它的方式是创建一个空白的默认页面,然后在加载时重定向到我想要的主页。我会在这里留下它,因为它可能对某人有用,我相信这是一个独特的例子。