带PageMethod的AJAX Toolkit AutoCompleteExtender:401未经授权的错误

时间:2013-02-08 15:10:45

标签: c#-4.0 autocompleteextender

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

<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问题,但没有一个解决方案适用于许多人,

任何导致尝试都将不胜感激。

1 个答案:

答案 0 :(得分:1)

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