Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 此时无法启动异步操作。_C#_Asp.net_Asynchronous - Fatal编程技术网

C# 此时无法启动异步操作。

C# 此时无法启动异步操作。,c#,asp.net,asynchronous,C#,Asp.net,Asynchronous,我试图在asp web表单中单击“提交”按钮时运行代码。我一点击按钮就发生了错误有人知道原因吗?错误消息如下所示: “/”应用程序中出现服务器错误 此时无法启动异步操作。异步的 操作只能在异步处理程序或 在页面生命周期中的某些事件期间。如果这 执行页面时发生异常,请确保该页面已关闭 标记的 aspx文件: <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <div c

我试图在asp web表单中单击“提交”按钮时运行代码。我一点击按钮就发生了错误有人知道原因吗?错误消息如下所示:

“/”应用程序中出现服务器错误

此时无法启动异步操作。异步的 操作只能在异步处理程序或 在页面生命周期中的某些事件期间。如果这 执行页面时发生异常,请确保该页面已关闭 标记的

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>

您正在调用一个
ASYNC
方法,答案是错误

确保页面已标记

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();
}
}