Asp.Net:Web服务抛出"线程已被中止" [英] Asp.Net : Web service throws "Thread was being aborted"
本文介绍了Asp.Net:Web服务抛出"线程已被中止"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web服务,我通过AJAX,需要先登录用户调用。每个方法我要检查,如果用户登录并发送403 code,如果他们都没有,但是当我称之为到Response.End()
我得到线程已被中止的错误。我怎么称呼呢?
[的WebMethod(真)]
公共字符串的MyMethod()
{
如果(!userIsLoggedIn)
{
HttpContext.Current.Response.Status code = 403;
HttpContext.Current.Response.End();
}
/ *做的东西,除非用户在登录......这不应该执行* /
...
}
解决方案
因为它是一个的WebMethod
,最简单的方法是只返回任何内容。这相当于行为结束为一个Ajax请求的响应:
[的WebMethod(真)]
公共字符串的MyMethod()
{
如果(!userIsLoggedIn)
{
HttpContext.Current.Response.Status code = 403;
返回null;
}
}
I have a web service that I call via ajax that requires the user to be logged in. in each method I want to check if the user is logged in and send a 403 code if they are not, however when I call a Response.End()
I get the error "Thread was being aborted". What should I call instead?
[WebMethod(true)]
public string MyMethod()
{
if(!userIsLoggedIn)
{
HttpContext.Current.Response.StatusCode = 403;
HttpContext.Current.Response.End();
}
/* Do stuff that should not execute unless the user is logged in... */
...
}
解决方案
Since it's a WebMethod
, the easiest method is to just return nothing. This would be equivalent behavior to ending the response for an ajax request:
[WebMethod(true)]
public string MyMethod()
{
if(!userIsLoggedIn)
{
HttpContext.Current.Response.StatusCode = 403;
return null;
}
}
这篇关于Asp.Net:Web服务抛出"线程已被中止"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文