我正在试图访问作为WebForm项目一部分的控制器中的会话。所有会话变量都设置在ASPX页上。
Session["SESSION_KEY_UI_CULTURE"] = ddlLanguage.SelectedValue;
现在,根据客户机的API请求,我需要读取会话变量并执行任务,但会话始终为空。
[RoutePrefix("api/accounts")]
public class AccountsController : ApiController
{
[Route("config")]
[HttpGet]
public IHttpActionResult GetCompanyConfig()
{
if(HttpContext.Current.Session != null)
{
//Session is always NULL
}
return Ok();
}
}
我尝试在webconfig文件中删除和添加sessionstatemodule
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>