在页面加载时,将上传路径保存到Session中:
string uploadPath = Server.MapPath("~/Uploads/"); Session["UploadPath"] = uploadPath;
在上传文件的方法中,获取存储在Session中的上传路径:
string uploadPath = Session["UploadPath"].ToString();
在Web.config文件中添加以下配置:
通过以下代码获取上传路径:
string uploadPath = Server.MapPath(ConfigurationManager.AppSettings["UploadPath"]);
无论哪种方法,都需确保上传路径正确且持久化,避免在页面刷新时丢失。