简体   繁体   English

从ASPX页面重定向到MVC操作的问题

[英]Issue redirecting from ASPX page to MVC action

I am having trouble redirecting from aspx page to mvc action. 我无法从aspx页面重定向到mvc操作。 Actually the aspx is a response handler for payment gateway. 实际上,aspx是付款网关的响应处理程序。 Which then based on response code redirects user to appropriate action. 然后根据响应代码将用户重定向到适当的操作。 However I am having some issue during the redirection. 但是,我在重定向过程中遇到了一些问题。 Earlier I have tried to accept response on MVC action, however I got an error, therefore I decide to use aspx to handle response and redirect to mvc action. 早些时候,我尝试接受对MVC操作的响应,但是遇到一个错误,因此我决定使用aspx处理响应并重定向到mvc操作。

Below is the code that aspx page has in it: 以下是aspx页面中包含的代码:

<%@ Page Language="C#" %>
<script runat="server">
    protected void Page_Load(Object sender, System.EventArgs e)
    {
        String result = System.Web.HttpContext.Current.Request["result"];
        String paymentID = System.Web.HttpContext.Current.Request["paymentid"];
        String respons = System.Web.HttpContext.Current.Request["responsecode"];
        String err = System.Web.HttpContext.Current.Request["Error"];
        String errmsg = System.Web.HttpContext.Current.Request["ErrorText"];
        String tid = System.Web.HttpContext.Current.Request["Trackid"];

        String query = String.Format("checkout/PaymentResult?result={0}&paymentid={1}&responsecode={2}&error={3}&errortext={4}&trackid={5}", result, paymentID, respons, err, errmsg, tid);

        var _file = new System.IO.StreamWriter(Server.MapPath("~/Response.log"), true);
        _file.WriteLine(query);
        _file.Close();
        //Below line is working fine in aspx pages
        System.Web.HttpContext.Current.Response.Write("Redirect=" + ConfigurationManager.AppSettings["BaseURL"].ToString() + query);

        //Tried below two, not working
        //System.Web.HttpContext.Current.Response.Redirect(ConfigurationManager.AppSettings["BaseURL"].ToString() + query);  
        //Response.RedirectPermanent(ConfigurationManager.AppSettings["BaseURL"].ToString() + query);
    }
</script>

Payment gateway response for mvc action response handler: MVC操作响应处理程序的支付网关响应:
If I pass site URL with following " checkout/PaymentResult " I get below error. 如果我通过以下“ checkout/PaymentResult ”传递站点URL, checkout/PaymentResult以下错误。

09:38:40,872 FATAL event.com.aciworldwide.commerce.gateway.payment.MerchantNotificationService [TP-Processor5]  - Hack characer/length check failed on redirect URL:
         <!DOCTYPE html>
         <html lang="en">
         <head>
             <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
             <meta http-equiv="X-UA-Compatible" content="IE=9">
             <title>XXXXXXXss.com - Free home Delivery</title>

Also, I have noticed that in ASPX, the page gets called twice for some reason. 另外,我注意到在ASPX中,由于某种原因该页面被两次调用。 First from payment gateway with all values, second time with blank values. 首先从付款网关获取所有值,第二次从空白值开始。 See the log file details below. 请参阅下面的日志文件详细信息。

checkout/PaymentResult?result=CAPTURED&paymentid=582000001361270&responsecode=00&error=&errortext=&trackid=300009
checkout/PaymentResult?result=&paymentid=&responsecode=&error=&errortext=&trackid=

UPDATE 更新
Controller code: 控制器代码:

public ActionResult PaymentResult(string result, string paymentid, string responsecode, string error, string errortext, string trackid)
        {
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
              .LimitPerStore(_storeContext.CurrentStore.Id)
              .ToList();

            // transaction response code
            String _result = (!string.IsNullOrEmpty(result)) ? result : "null";

            String _paymentId = (!string.IsNullOrEmpty(paymentid)) ? paymentid : "null";

            String _response = (!string.IsNullOrEmpty(responsecode)) ? responsecode : "null";

            String _err = (!string.IsNullOrEmpty(error)) ? error : "null";

            String _errMessage = (!string.IsNullOrEmpty(errortext)) ? errortext : "null";

            String _trackID = (!string.IsNullOrEmpty(trackid)) ? trackid : "null";

            // define message string for errors
            String _message = getResponseDescription(_response);
            Session["PaymentMessage"] = String.Format("Message: {0}, Code: {1}", _message, responsecode);

            try
            {

                var order = _orderService.GetOrderById(Convert.ToInt32(_trackID));
                if (_result.Equals("CAPTURED"))
                {
                    try
                    {
                        try
                        {
                            order.OrderNotes.Add(new OrderNote
                            {
                                Note = String.Format("Bank Response= {0}, Code= {1}", _result, _response),
                                DisplayToCustomer = false,
                                CreatedOnUtc = DateTime.UtcNow
                            });
                            _orderService.UpdateOrder(order);
                        }
                        catch (Exception ex)
                        {
                            LogException(ex);
                        }
                        cart.ToList().ForEach(sci => _shoppingCartService.DeleteShoppingCartItem(sci, false));
                        order.CaptureTransactionResult = _message;
                        _orderService.UpdateOrder(order);
                        _orderProcessingService.MarkOrderAsPaid(order);
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }

                    return RedirectToRoute("CheckoutCompleted", new { orderId = order.Id });
                }
                else
                {
                    _orderService.UpdateOrder(order);
                    order.CaptureTransactionResult = _message;
                    _orderProcessingService.CancelOrder(order, true);
                    return Redirect(Url.Action("Cart", "ShoppingCart"));
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                return Redirect(Url.Action("Cart", "ShoppingCart"));
            }

        }

I added, !IsPostBack , but it still wont do anything, the blank lines are still coming in. 我添加了!IsPostBack ,但它仍然无法执行任何操作,空白行仍会出现。

Update 2: 更新2:
I think the problem is that the session is getting lost after I redirect back from gateway to application. 我认为问题在于,当我从网关重定向回应用程序后,会话会丢失。 Also I am using a web garden, so I believe the worker process gets changed. 另外,我正在使用网络花园,因此我认为工作进程已更改。 However, I am using ASP.NET out of process session state. 但是,我正在使用ASP.NET进程外会话状态。

How do I share session data across the web garden? 如何在整个网络花园中共享会话数据?

The way we do redirection is we supply full url from webform application and not just the controller / action bit. 重定向的方式是从Webform应用程序提供完整的url,而不仅仅是控制器/操作位。 So try appending the domain part eg http://www.yoururl.com/checkout/paymentresult ... 因此,请尝试附加域部分,例如http://www.yoururl.com/checkout/paymentresult ...

NB Both our websites, mvc and webforms are deployed on separate iis sites with different port numbers. 注意:我们的网站,mvc和webforms均部署在具有不同端口号的单独iis站点上。 Both share session information. 两者共享会话信息。

Hope it helps. 希望能帮助到你。

Update: just noticed you are appending BaseUrl so there must be something else. 更新:刚注意到您要追加BaseUrl,所以必须还有其他内容。 :) :)

Also, I think we have to put if(!isPostBack()) for page load method. 另外,我认为我们必须将if(!isPostBack())用于页面加载方法。 That can solve one problem of double posting 可以解决重复发布的一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM