我正在制作一个 WebAPI 应用程序,但发现我无法读取或写入会话。我通常会怎么做会给出 NullObject 引用错误,即:
Session["Test"] = "Testing"; var testing = Session["Test"].ToString();
有人会碰巧理解这个例子的原因吗?
using System;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Web.Api;
namespace DotNetNuke.Modules.ContactsManager
{
public partial class ServicesController : DnnApiController
{
[AllowAnonymous]
[HttpGet]
public HttpResponseMessage createRequest(string amount)
{
//code omitted
HttpContext.Current.Session["Test"] = "Test";
//code omitted
return Request.CreateResponse(HttpStatusCode.OK, result);
}
}
}