Webforms response.redirect返回正确的URL并重新加载相同的页面

时间:2015-03-29 17:38:16

标签: c# asp.net .net redirect webforms

当我在我的webform上按下一个按钮,将一个项目插入我的数据库并将一些信息存储到会话中时,我会执行一些操作。在执行结束时,表单应该重定向到下一页,而是重新加载相同的页面并更改URL。我试图将它从Response.Redirect(“URL”)更改为Server.TransferRequest,它仍然做同样的事情。代码如下:

protected void CheckoutConfirm_Click(object sender, EventArgs e)
        {
        //some irrelevant code
        using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
        {
            placedOrder.totalPrice = usersShoppingCart.GetTotal();
            _db.Orders.Add(placedOrder);
            _db.SaveChanges();
            List<CartItem> itemsInCart = usersShoppingCart.GetCartItems();
            //creating corresponding OrderProducts for each product in this order
            foreach (CartItem o in itemsInCart)
            {
                Orderproducts myOrderProduct = new Orderproducts();
                myOrderProduct.ProductID = o.ProductId;
                myOrderProduct.OrderID = placedOrder.OrderID;
                myOrderProduct.quantity = o.Quantity;
                _db.OrderProducts.Add(myOrderProduct);
                _db.SaveChanges();
                Session.Clear();
                Session["CustomerName"] = customer.CustomerName;
                Session["orderID"] = placedOrder.OrderID;
                Session["orderStatus"] = placedOrder.OrderStatus;
                Session["Address"] = customer.CustomerName + "\r\n" + customer.Address + "\r\n" + customer.City + "\r\n" + customer.Country;
            }
        }

        Server.TransferRequest("Checkout/finishedCheckout.aspx");

1 个答案:

答案 0 :(得分:0)

问题是在母版页中的Page_PreRender中发生的空引用异常。由于例外,重定向无法完成,同一页面只会重新加载。