亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# 此時無法啟動異步操作。

C# 此時無法啟動異步操作。

C#
倚天杖 2021-11-14 17:12:53
我正在嘗試在單擊 asp web 表單中的提交按鈕時運行我的代碼。單擊按鈕后立即發生錯誤有人知道原因嗎?錯誤消息顯示如下:“/”應用程序中的服務器錯誤。此時無法啟動異步操作。異步操作只能在異步處理程序或模塊內或在頁面生命周期中的某些事件期間啟動。如果在執行 Page 時發生此異常,請確保將 Page 標記為 <%@ Page Async="true" %>。aspx文件:<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"><div class="jumbotron">    <h1>Luis</h1>                <asp:TextBox ID="TextBox1" runat="server" Height="40px" Width="273px"></asp:TextBox>    </div>    <p>       <input id="Submit1"  runat="server" type="submit" value="Check" onserverclick="Submit_Click"/></p>      <p>    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p></asp:Content>.cs 文件:public partial class _Default : Page{public async void Submit1_Click(object sender, EventArgs e) {    string utterance = TextBox1.Text;    var client = new HttpClient();    var queryString = HttpUtility.ParseQueryString(string.Empty);    // This app ID is for a public sample app that recognizes requests to turn on and turn off lights    var luisAppId = "75bcaaff-1dc1-4dsa-adf7-63584cea339a";    var subscriptionKey = "43314f19c5ecgdascba6a00f1d3cc3533";    // The request header contains your subscription key    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);    // The "q" parameter contains the utterance to send to LUIS    //queryString["q"] = "turn on the left light";    // These optional request parameters are set to their default values    queryString["timezoneOffset"] = "0";    queryString["verbose"] = "false";    queryString["spellCheck"] = "false";    queryString["staging"] = "false";    var uri = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" + luisAppId + "?" + queryString + "&q=" + utterance;    var response = await client.GetAsync(uri);    var strResponseContent = await response.Content.ReadAsStringAsync();    // Display the JSON result from LUIS    //Console.WriteLine(strResponseContent.ToString());    Label1.Text = strResponseContent.ToString();}}
查看完整描述

1 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

您正在調用一個ASYNC方法,而答案在錯誤中。

確保頁面標記為 <%@ Page Async="true" %>。


查看完整回答
反對 回復 2021-11-14
  • 1 回答
  • 0 關注
  • 683 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號