所以我试图从缓存中写入一个 xml 文件。当我从登录页面移动到帐户详细信息页面时,我的 accountdetails pageload() 获取用户名/密码 - 发送到数据库 - 如果匹配则获取表信息 - 然后将数据绑定到网格视图并保存到缓存。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
myBusinessLayer = new clsBusinessLayer(Server.MapPath("/"));
BindUserInfoGridView();
}
}
private Accounts BindUserInfoGridView()
{
string tempPath = Server.MapPath("Programaholics.accdb");
clsDataLayer myDataLayer = new clsDataLayer(tempPath);
Accounts userListing = myBusinessLayer.FindUsername(PreviousPage.Username.Text, PreviousPage.Password.Text);
gvUserInfo.DataSource = userListing.tblUserInfo;
gvUserInfo.DataBind();
Cache.Insert("UserDataSet", userListing);
return userListing;
}
在 businessLayer 类中,我将以下代码写入 xml:
public DataSet WriteUserXMLFile(System.Web.Caching.Cache appCache)
{
DataSet xmlDataSet = (DataSet)appCache["UserDataSet"];
xmlDataSet.WriteXml(dataPath + "/App_Code/username.xml");
return xmlDataSet;
}
我在 accountDetails 页面上的 asp:Button 有一个 onclick 事件
public void btnExportUserXML_Click(object senderr, EventArgs e)
{
//This was added after Review
myBusinessLayer= new clsBusinessLayer(Server.MapPath("/"));
myBusinessLayer.WriteUserXMLFile(Cache);
}
由于某种原因,这将不起作用。我不断得到例外myBusinessLayer.writeXMLFile(Cache);
。我假设当单击按钮时页面被刷新并且缓存丢失。这是学校的课程项目,所以我不需要了解任何 sqlinjection 或其他安全技术我只需要找出为什么我无法获得保存到 xmlfile 的按钮。我已经放入myBusinessLayer.writeXMLFile(Cache);
页面加载,它会工作,但根据要求,它必须是一个加载它的按钮。谢谢你。