覆盖 OnActionExecuting 和 .ashx 文件上传
我有一个使用第三方上传 .ashx 页面的 MVC 项目。我还对 OnActionExecuting(ActionExecutingContext filterContext) 进行了以下覆盖:
public override void OnActionExecuting(ActionExecutingContext filterContext) {
SessionContext context = (SessionContext)filterContext.HttpContext.Session[SessionConstants.SessionContext];
if (context == null || context.Ticket == null) {
filterContext.Result = new RedirectResult(TimeoutRedirectUrl);
return;
}
base.OnActionExecuting(filterContext);
}
这是为了确保用户在访问 MVC 页面时仍然处于登录状态。但是,在用户上传文件后,“上下文”似乎为空,然后 OnActionExecuting() 会重定向用户。
为什么用户上传文件后不再有上下文?我希望他们仍然处于登录状态。
I have a MVC project that uses a 3rd party upload .ashx page. I also have the following override for OnActionExecuting(ActionExecutingContext filterContext):
public override void OnActionExecuting(ActionExecutingContext filterContext) {
SessionContext context = (SessionContext)filterContext.HttpContext.Session[SessionConstants.SessionContext];
if (context == null || context.Ticket == null) {
filterContext.Result = new RedirectResult(TimeoutRedirectUrl);
return;
}
base.OnActionExecuting(filterContext);
}
This is here to make sure users are still logged in when they visit MVC pages. However, after a user uploads a file it looks like the "context" is null and then OnActionExecuting() redirects the user.
Why would there no longer be a context after a user uploads a file? I want them to still be logged in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用控制器操作方法而不是通用处理程序来上传文件?处理程序的级别非常低,默认情况下无法访问 cookie、会话等。
Have you tried using a controller action method to upload the file instead of the generic handler? Handlers are very low level and by default have no access to cookies, session, etc.