客制化控件调用webapi接口

在客制化控件中调用cloud接口,从cloud传 kdservice-sessionid和ASP.NET_SessionId到我的客制化控件中,然后HttpClient中设置cookie,保持与cloud会话一致,不需要登录
public static HttpClient _clientSingle;
public static HttpClient SingleHttpClient
{
get
{
if (_clientSingle == null)
{
//var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip };
var handler = new HttpClientHandler() { UseCookies = true };
_clientSingle = new HttpClient(handler);
if (!string.IsNullOrEmpty(aspnetSessionId))
{
_clientSingle.DefaultRequestHeaders.Add("kdservice-sessionid", kdserviceSessionId);
_clientSingle.DefaultRequestHeaders.Add("ASP.NET_SessionId", aspnetSessionId);
}
}
return _clientSingle;
}
}
这样可以正常调用cloud WebApi接口,但是我注销或者超时后重新登录,cloud的 kdservice-sessionid和ASP.NET_SessionId没有变化,我调用Webapi接口时报错,context.Session.AppContext == null,Session已过期。只有完全退出后再登录才可以,注销后登录调用,调用api会报错。

 

问题名称:客制化控件调用webapi接口

点击链接查看答案:

https://club.kingdee.com/forum.php?mod=viewthread&tid=1498458

未经允许不得转载:友商问答 » 客制化控件调用webapi接口

赞 (0)