我正在开发asp.net web app(Web-Forms),其中我使用Session来存储用户相关数据。虽然我在尝试检索时将数据存储在会话对象中,但却给出了错误:
Object reference not set to an instance of an object.
这是我使用方法的课程:
public partial class CheckoutReview : System.Web.UI.Page, IHttpHandler, IRequiresSessionState
这里是出现错误的代码:
public partial class CheckoutReview : System.Web.UI.Page, IHttpHandler, IRequiresSessionState
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
NVPAPICaller payPalCaller = new NVPAPICaller();
string retMsg = "";
string token = "";
string PayerID = "";
NVPCodec decoder = new NVPCodec();
token = Session["token"].ToString(); <---
设置Session [“token”]:
public partial class CheckoutStart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
NVPAPICaller payPalCaller = new NVPAPICaller();
string retMsg = "";
string token = "";
if (Session["payment_amt"] != null)
{
string amt = Session["payment_amt"].ToString();
bool ret = payPalCaller.ShortcutExpressCheckout(amt, ref token, ref retMsg);
if (ret)
{
Session["token"] = token;
Response.Redirect(retMsg);
}
else
{
Response.Redirect("CheckoutError.aspx?" + retMsg);
}
}
else
{
Response.Redirect("CheckoutError.aspx?ErrorCode=AmtMissing");
}
}
}
如何解决此问题?