javascript - 自将 ASP.NET 站点从 HTTP 更改为 HTTPS 后,自动完成/即时搜索结果框停止工作
问题描述
我有一个 ASP.NET 站点,在该站点中实现了自动完成/即时搜索功能,用于查找用户名。我有一个 SearchResults.aspx 页面,它实质上呈现了一个与传递给它的“搜索词”查询字符串匹配的用户 JSON 列表。JSON 通过 AWS Lambda 函数从 Azure Active Directory 中获取。
这是页面加载;
protected void Page_Load(object sender, EventArgs e)
{
if (!Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
List<Users> Results = GetADUsers(Request.QueryString["term"]);
Response.ContentType = "application/json;charset=UTF-8";
var output = (from r in Results
select new { label = r.Name}).ToList();
// Then we need to convert it to a JSON string
JavaScriptSerializer Serializer = new JavaScriptSerializer();
string JSON = Serializer.Serialize(output);
// And finally write the result to the client.
Response.Write(JSON);
}
这是获取用户的功能:
List<Users> GetADUsers(string searchParameter)
{
List<Users> ret = new List<Users>();
try
{
using (var client = new AmazonLambdaClient(Amazon.RegionEndpoint.APSoutheast2))
{
var request = new InvokeRequest
{
FunctionName = ConfigurationManager.AppSettings["lambdaArnPrefix"] + "lambda-wlyw-GetAzureAdUsers",
Payload = "\"" + searchParameter + "\"",
InvocationType = InvocationType.RequestResponse
};
var response = client.Invoke(request);
string result;
using (var sr = new StreamReader(response.Payload))
{
result = sr.ReadToEnd();
}
dynamic _userList = JsonConvert.DeserializeObject(result);
for (int i = 0; i < _userList.Count; i++)
{
ret.Add(
new Users
{
Name = _userList[i].userName
});
}
}
}
catch (Exception ex)
{
ret.Add(new Users() { Name = ex.Message });
}
return ret;
}
然后,我的主页上有一个搜索框,它基本上使用 SearchResults.aspx 页面中的内容来根据在搜索框中输入的内容来填充结果(就像使用 SearchResults.aspx 一样,就像 Web 服务一样) .
<script>
$(function() {
$( "#tags" ).autocomplete({ source: "/SearchResults.aspx" });
});
</script>
上面的 javascript 引用了这个输入:
<div class="ui-widget">
<input id="tags" runat="server"/>
</div>
并使用此处提供的自动完成 javascript - http://leaverou.github.io/awesomplete(我没有制作,我只是在使用)。
此 AWS Lambda 函数在测试时运行良好。SearchResults.aspx 页面在浏览器中测试时工作正常。但是,自从从 HTTP 迁移到 HTTPS 后,用于触发整个过程的输入文本框已经停止工作。我不明白为什么。也许 HTTP 到 HTTPS 的事情是红鲱鱼?但这是我所做的唯一改变?谁能想到这不再起作用的原因?
解决方案
推荐阅读
- html - 文本框周围的阴影
- keras - Keras seq2seq 模型如何在训练时从验证中屏蔽填充零?
- flutter - 颤振:我怎样才能抓住后退按钮按下退出我的应用程序
- pandas - 熊猫系列饼图的切片颜色匹配
- java - 在Java中的while循环外检索值
- stripe-payments - Stripe ACH + Plaid:'account_id 必须是格式正确的非空字符串'
- android - Dagger 2 不提供 Retrofit API
- ios - removeFromSuperView() 之前的 CABasicAnimation 性能
- flutter - 重建 FutureBuilder
- javascript - 连接到不属于我的网站 WebSocket 服务器