bellow是我的代码,当我重定向到另一个页面时,它会抛出一个错误作为安全异常。在本地调试时工作正常。
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
clsProductProp objProductProp = new clsProductProp();
objProductProp = (clsProductProp)Session["ProductDetails"];
clsCommon objCommon = new clsCommon();
bool IsDone = false;
Int32 Vol_ProductId = 0;
//--------------------------check for directory existence------------------
if (System.IO.Directory.Exists(Server.MapPath("ProductImages") + "\\" + user))
{
Path = Server.MapPath("ProductImages") + "\\" + user;
}
else
{
Directory.CreateDirectory(Server.MapPath("ProductImages") + "\\" + user);
if (System.IO.Directory.Exists(Server.MapPath("ProductImages") + "\\" + user))
{
Directory.CreateDirectory(Server.MapPath("ProductImages") + "\\" + user + "\\Image");
Directory.CreateDirectory(Server.MapPath("ProductImages") + "\\" + user + "\\Thumb");
}
Path = Server.MapPath("ProductImages") + "\\" + user;
}
objProductProp.vendorId = Convert.ToInt32(Session["LOGIN_ID"]);
if (ViewState["ReturnURL"].ToString() == "/AddProduct.aspx")
{
try
{
Vol_ProductId = InsertThrVolsuionAPI(objProductProp);
}
catch (Exception ex)
{
lblError.Text = "Problem with connectin API, please try again.";
}
//insert thr' volusion API
if (Vol_ProductId > 0)
{
IsDone = objProduct.InsertProduct( objProductProp , Vol_ProductId );
if (IsDone)
{
ArrayList values = new ArrayList();
values = (ArrayList)Session["CatValue"];
foreach (string item in values)
{
objProduct.UpdateCategoryOfProduct(Vol_ProductId, item, objProductProp.vendorId);
}
Session["CatValue"] = null;
}
}
}
else
{
try
{
Vol_ProductId = UpdateThrVolsuionAPI(objProductProp);
}
catch (Exception ex)
{
lblError.Text = "Problem with connectin API, please try again.";
}
if (Vol_ProductId > 0)
{
IsDone = objProduct.UpdateProduct(objProductProp);
//Old session values
ArrayList values = new ArrayList();
values = (ArrayList)Session["NewCatValue"];
//New session values
ArrayList Newvalues = new ArrayList();
Newvalues = (ArrayList)Session["NewCatValue"];
foreach (string item in Newvalues)
{
objProduct.UpdateCategoryOfProduct(Vol_ProductId, item, objProductProp.vendorId);
}
Session["CatValue"] = null;
}
}
if (Vol_ProductId > 0)
{
try
{
if (objProductProp.image1 != "")
{
//Path = Server.MapPath("PeviewImages" + "\\" + user);
string fullImageName = Server.MapPath("PeviewImages" + "\\" + user) + "\\Image\\" + objProductProp.image1;
string DestPath = Server.MapPath("ProductImages" + "\\" + user) + "\\Image\\" + objProductProp.image1;
if (Session["OldImage1"].ToString() == "false")
if (File.Exists(DestPath))
{
File.Delete(DestPath);
}
if (File.Exists(fullImageName))
{
File.Move(fullImageName, DestPath);
FileTransfer("~/ProductImages//" + user + "//Image//" + objProductProp.image1, objProductProp.image1);
}
string fullImageName1 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb1;
string DestPath1 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb1;
if (Session["OldImage1"].ToString() == "false")
if (File.Exists(DestPath1))
{
File.Delete(DestPath1);
}
if (File.Exists(fullImageName1))
{
File.Move(fullImageName1, DestPath1);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image1thumb1, objProductProp.image1thumb1);
}
string fullImageName2 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb2;
string DestPath2 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb2;
if (Session["OldImage1"].ToString() == "false")
if (File.Exists(DestPath2))
{
File.Delete(DestPath2);
}
if (File.Exists(fullImageName2))
{
File.Move(fullImageName2, DestPath2);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image1thumb2, objProductProp.image1thumb2);
}
string fullImageName3 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb3;
string DestPath3 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb3;
if (Session["OldImage1"].ToString() == "false")
if (File.Exists(DestPath3))
{
File.Delete(DestPath3);
}
if (File.Exists(fullImageName3))
{
File.Move(fullImageName3, DestPath3);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image1thumb3, objProductProp.image1thumb3);
}
string fullImageName4 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb4;
string DestPath4 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image1thumb4;
if (Session["OldImage1"].ToString() == "false")
if (File.Exists(DestPath4))
{
File.Delete(DestPath4);
}
if (File.Exists(fullImageName4))
{
File.Move(fullImageName4, DestPath4);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image1thumb4, objProductProp.image1thumb4);
}
}
if (objProductProp.image2 != "")
{
string fullImageName = Server.MapPath("PeviewImages" + "\\" + user) + "\\Image\\" + objProductProp.image2;
string DestPath = Server.MapPath("ProductImages" + "\\" + user) + "\\Image\\" + objProductProp.image2;
if (Session["OldImage2"].ToString() == "false")
if (File.Exists(DestPath))
{
File.Delete(DestPath);
}
if (File.Exists(fullImageName))
{
File.Move(fullImageName, DestPath);
FileTransfer("~/ProductImages//" + user + "//Image//" + objProductProp.image2, objProductProp.image2);
}
string fullImageName1 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image2thumb1;
string DestPath1 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image2thumb1;
if (Session["OldImage2"].ToString() == "false")
if (File.Exists(DestPath1))
{
File.Delete(DestPath1);
}
if (File.Exists(fullImageName1))
{
File.Move(fullImageName1, DestPath1);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image2thumb1, objProductProp.image2thumb1);
}
string fullImageName2 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image2thumb2;
string DestPath2 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image2thumb2;
if (Session["OldImage2"].ToString() == "false")
if (File.Exists(DestPath2))
{
File.Delete(DestPath2);
}
if (File.Exists(fullImageName2))
{
File.Move(fullImageName2, DestPath2);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image2thumb2, objProductProp.image2thumb2);
}
string fullImageName3 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image2thumb3;
string DestPath3 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image2thumb3;
if (Session["OldImage2"].ToString() == "false")
if (File.Exists(DestPath3))
{
File.Delete(DestPath3);
}
if (File.Exists(fullImageName3))
{
File.Move(fullImageName3, DestPath3);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image2thumb3, objProductProp.image2thumb3);
}
}
if (objProductProp.image3 != "")
{
string fullImageName = Server.MapPath("PeviewImages" + "\\" + user) + "\\Image\\" + objProductProp.image3;
string DestPath = Server.MapPath("ProductImages" + "\\" + user) + "\\Image\\" + objProductProp.image3;
if (Session["OldImage3"].ToString() == "false")
if (File.Exists(DestPath))
{
File.Delete(DestPath);
}
if (File.Exists(fullImageName))
{
File.Move(fullImageName, DestPath);
FileTransfer("~/ProductImages//" + user + "//Image//" + objProductProp.image3, objProductProp.image3);
}
string fullImageName1 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image3thumb1;
string DestPath1 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image3thumb1;
if (Session["OldImage3"].ToString() == "false")
if (File.Exists(DestPath1))
{
File.Delete(DestPath1);
}
if (File.Exists(fullImageName1))
{
File.Move(fullImageName1, DestPath1);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image3thumb1, objProductProp.image3thumb1);
}
string fullImageName2 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image3thumb2;
string DestPath2 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image3thumb2;
if (Session["OldImage3"].ToString() == "false")
if (File.Exists(DestPath2))
{
File.Delete(DestPath2);
}
if (File.Exists(fullImageName2))
{
File.Move(fullImageName2, DestPath2);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image3thumb2, objProductProp.image3thumb2);
}
string fullImageName3 = Server.MapPath("PeviewImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image3thumb3;
string DestPath3 = Server.MapPath("ProductImages" + "\\" + user) + "\\Thumb\\" + objProductProp.image3thumb3;
if (Session["OldImage3"].ToString() == "false")
if (File.Exists(DestPath3))
{
File.Delete(DestPath3);
}
if (File.Exists(fullImageName3))
{
File.Move(fullImageName3, DestPath3);
FileTransfer("~/ProductImages//" + user + "//Thumb//" + objProductProp.image3thumb3, objProductProp.image3thumb3);
}
}
DeleteImages(objProductProp);
objProductProp = null;
if (ViewState["ReturnURL"].ToString() == "/AddProduct.aspx")
{
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Redirect("VendorMessage.aspx?ProductIsOpen=true&id=1", false);
}
else
{
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Redirect("VendorMessage.aspx?ProductIsOpen=true&id=2", false);
}
}
catch (Exception ex)
{
lblError.Text = "Sorry!, There was a problem, please try again.";
}
}
else
Response.Write("<script language='javascript'>alert('Product Already Exists.')</script>");
}
catch (Exception ex)
{
lblError.Text = "Sorry!, There was a problem, please try again.";
}
}
你能告诉我问题在哪里吗?