【问题标题】:AJAX Toolkit AutoCompleteExtender with PageMethod: 401 Unauthorized errorAJAX Toolkit AutoCompleteExtender with PageMethod: 401 Unauthorized error
【发布时间】:2013-02-08 15:10:45
【问题描述】:

我正在尝试在文本框上实现自动完成功能,该功能使用 AJAX 工具包中的 AutoCompleteExtender 从我们的数据库中提取数据。文本框和控件位于嵌套在 aspx 页面(具有更新面板)上的用户控件上;脚本管理器位于母版页上。

<asp:TextBox ID="txtTowelManufacturer" runat="server" Width="200px"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="txtTowelManufacturer_AutoCompleteExtender" 
    runat="server" MinimumPrefixLength="1" ServiceMethod="GetCompletionList"
    TargetControlID="txtTowelManufacturer" UseContextKey="True">
</ajaxToolkit:AutoCompleteExtender>

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
    ...
}

当我使用 cassini 在我的开发机器上运行该页面时,使用扩展程序会生成 401 Unauthorized 错误,而没有进一步的调试信息。帖子正确,回复为空:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

如果我直接或使用相对路径手动指定 ServicePath,我会得到同样的错误。如果我指定了不正确的路径,它会正确生成 404 Not Found 错误,所以我知道它正在寻找正确的位置。

我一直无法弄清楚为什么在这种情况下会出现身份验证错误。我们没有使用 Windows 身份验证或跨越任何域,虽然 401 问题已被多次提出,但所提供的解决方案都没有对许多人有效,

任何尝试的线索将不胜感激。

【问题讨论】:

  • GetCompletionList 方法的定义位于哪个文件中?
  • 在同一页面后面的代码中,文本框和扩展器都打开了。
  • 尝试将方法从用户控件的ascx.cs文件移动到页面的aspx.cs文件。
  • 成功了,谢谢!我不认为我会尝试这样做。请张贴作为答案,以便我标记它。

标签: c#-4.0 autocompleteextender


【解决方案1】:

尝试将GetCompletionList() 方法从用户控件的ascx.cs 文件移动到页面的aspx.cs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2020-08-15
    相关资源
    最近更新 更多