【问题标题】:Issue in Redirecting onActionExecuting重定向 onActionExecuting 的问题
【发布时间】:2016-01-01 22:58:58
【问题描述】:

我有 2 种方法用于会话到期检查,第一种用于控制器,第二种用于 API 控制器...我在重定向时遇到问题我尝试了很多方法但无法重定向...代码如下..

  public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext ctx = HttpContext.Current;
        // check  sessions here

        if (HttpContext.Current.Session[Constants.SessionKeys.UserId] == null)
        {
            filterContext.Result = new RedirectToRouteResult(
            new RouteValueDictionary { { "controller", "HomeController" }, { "action", "Redirect" } });
            return;
        }
        base.OnActionExecuting(filterContext);
    }

  public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {

        HttpContext ctx = HttpContext.Current;

        // check  sessions here
        if (HttpContext.Current.Session[Constants.SessionKeys.UserId] == null)
        {
            System.Web.Mvc.ActionExecutingContext filtercontext = new System.Web.Mvc.ActionExecutingContext();
            filtercontext.Result = new System.Web.Mvc.RedirectResult("http://a830edad9050849NDA3307.sharepoint.com/sites/SPBoxUI");
            return;
        }
        base.OnActionExecuted(actionExecutedContext);
    }

在第一个中,我在控制器中有一个动作,并且在那里放置了一个断点,但我认为这没有被调用。我正在使用 MVC4 这两个都没有按预期工作......在此先感谢您的好意帮助

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    尝试如下。这个 sn-p 可能会对你有所帮助。

    Response.Redirect(Url.Action("Redirect", "Home"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2011-03-13
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      相关资源
      最近更新 更多