共享主机环境的已知问题,解决方法很好,但我会建议升级您的服务器。我的主机有一个DotNetNuke选项,这意味着它将在服务器上保留内存,并且不会因不活动而回收应用程序池。与VPS相比,这更便宜。
如果它不是共享主机,these IIS settings could help you。
总之,回到你的解决方法:
你说客户不能访问的WebAPI,只有你的网站可以的后端。看起来很奇怪,因为webapi暴露了REST GET,POST方法。无论采用哪种方式,您都可以在服务器端对您的webapi执行异步调用,而不会等待响应或对您的API执行javascript调用。
假设您的网站也是ASP.NET:
public static async Task StartupWebapi()
{
string requestUrl = "http://yourwebapi.com/api/startup";
using (var client = new HttpClient())
{
//client.Timeout = new TimeSpan(0, 0, 20); timeout if needed
try
{
HttpResponseMessage response = await client.GetAsync(requestUrl);
if (response.IsSuccessStatusCode)
{
resultString = await response.Content.ReadAsStringAsync();
}
}
}
}
然后,在某处你的代码,将被调用时,你的客户的网站开始至少。
HostingEnvironment.QueueBackgroundWorkItem(ct => SomeClass.StartupWebapi());
或在javascript中,它是异步执行的。
$.ajax({
url: "http://yourwebapi.com/api/startup",
type: "GET",
success: function (response) {
},
error: function (response) {
}
});
见this question一些其他的解决方法。