未将对象引用设置到对象实例我在网上下了个网站,运行后下面的这段代码提示未将对象引用设置到对象实例cart.MigrateShoppingCartItems(Session["AnonUID"].ToString(), UserName.Text);
是在登录/注册部分出现差错的,就是我登录以前注册的账户,会提示上述错误,出现错误的完整的代码如下:
<%@ Page Language="C#" Inherits="IBuyAdventure.PageBase" src="components/stdpage.cs" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Register TagPrefix="IBA" TagName="Header" Src="UserControl/Header.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Categories" Src="UserControl/Categories.ascx" %>
<html>
<head>
<title>达也电子商务网</title>
</head>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e) {
// Store Return Url in Page State
if (Request.QueryString["ReturnUrl"] != null)
{
ReturnUrl.Value = Request.QueryString["ReturnUrl"];
((HyperLink)RegisterUser).NavigateUrl = "Register.aspx?ReturnUrl=" + ReturnUrl.Value;
}
}
void LoginBtn_Click(Object sender, EventArgs e) {
IBuyAdventure.UsersDB users = new IBuyAdventure.UsersDB(getConnStr());
IBuyAdventure.CartDB cart = new IBuyAdventure.CartDB(getConnStr());
if (users.ValidateLogin(UserName.Text, Password.Text)) {
// Migrate any temporary shopping cart items to logged-in username
cart.MigrateShoppingCartItems(Session["AnonUID"].ToString(), UserName.Text);
// Set Client Authentication Cookie
FormsAuthentication.RedirectFromLoginPage(UserName.Text, Persist.Checked);
}
else {
Message.Text = "注册失败,请输入正确资料再次注册.";
}
}
</script>
<body background="images/back_sub.gif">
<form method=post action="Login.aspx" runat="server">
<font face="Verdana, Arial, Helvetica" size="2">
<table border="0">
<tr>
<td colspan="5">
<IBA:Header id="Header" runat="server"/>
</td>
</tr>
<!--Begin Navigational Buttons-->
<tr>
<td rowspan="5" align="left" valign="top">
<IBA:Categories id="Categories" runat="server"/>
</td>
<td valign="top">
<center>
<br>
<input type="hidden" value="/IBuyAdventure/default.aspx" id="ReturnUrl" runat="server">
<P><font size="2">要购买本站物品 请先登陆或注册:<br><br>
<table cellpadding="5" colspan="2">
<tr>
<td width="310" bgcolor="#800000">
<font color="#ffffff" style="Verdana, Arial, Helvetica" size="2"><b>注册</b></font>
</td>
</tr>
<tr>
<td bgcolor="f7efde" valign=top>
<table>
<tr>
<td width=100><font size="2">用户名: </font></td>
<td><asp:textbox id="UserName" width="160" runat="server"/></td>