【问题标题】:session destroy problem after redirect back from payment gateway in ASP.NET MVC 5从 ASP.NET MVC 5 中的支付网关重定向回来后的会话破坏问题
【发布时间】:2021-09-30 07:47:41
【问题描述】:

我正在使用 ASP.NET MVC 5 应用程序。从支付网关重定向回来后,我遇到了会话被破坏的问题。

是会议系统。我每年只使用 3 个月,直到去年才出现这样的问题,当我现在使用它时 我特别遇到了 Mozilla 和 google chrome 的问题,但在 Microsoft Edge 中没有遇到这样的会话问题

这是我的 Session 相关代码:

ConferenceSession profileData = new ConferenceSession
                {
                    username = log.emailID,
                    cid = log.confid
                };
Session["TstConfSESSION"] = profileData;

过滤器:

public class CustomFilter : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (filterContext.HttpContext.Session["TstConfSESSION"] == null)
        {
            //filterContext.Controller.TempData.Add("RedirectReason", "Session destroyed - try again!");
            filterContext.Result = new RedirectResult("/");
        }
    }
}

响应控制器

[CustomFilter]
[HttpPost]
public ActionResult payment(string id, FormCollection frm)
{ 
    // payment gateway response code 
}

我在web.config 中添加了这些设置以增加会话时间:

<system.web>
    <!-- Increase session time for payment gateway -->
    <sessionState timeout="20"></sessionState>
</system.web>

【问题讨论】:

    标签: c# session asp.net-mvc-5 session-state


    【解决方案1】:

    默认会话状态超时为20 minutes。您应该尝试增加,因为在您的代码中您实际上设置了默认值。

    因此,默认配置与您当前的配置没有区别。他们指向同一个。

    供参考:https://docs.microsoft.com/en-us/dotnet/api/system.web.sessionstate.httpsessionstate.timeout?view=netframework-4.8

    【讨论】:

    • 好的,但我等了不到 20 分钟。只需几秒钟,我就会重定向回来,然后会话结束
    • 您是否阻止存储 cookie?也许可以尝试这样的事情:
    • 我现在试过了,但没有遇到同样的问题
    • 我在 Mozilla 和 google chrome 中特别遇到了这个问题,但在 Microsoft Edge 中没有遇到这样的会话问题
    猜你喜欢
    • 2021-01-09
    • 2020-12-01
    • 2021-05-26
    • 2022-07-21
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 1970-01-01
    相关资源
    最近更新 更多