首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用C#在MVC 5中停止执行过程?

如何用C#在MVC 5中停止执行过程?
EN

Stack Overflow用户
提问于 2015-03-07 04:34:06
回答 1查看 2.4K关注 0票数 1

TODO部分,我需要哪一行代码?

我的应用程序代码是:

代码语言:javascript
复制
/// <summary>
/// Override onAuthorization filter is use for authorization use request.
/// </summary>
/// <param name="filterContext"></param>

protected override void OnAuthorization(AuthorizationContext filterContext)
{
    AuthorizationManager authorizationManager = new AuthorizationManager();

    string FilePath = Convert.ToString(filterContext.HttpContext.Request.FilePath);

    if (!authorizationManager.IsAuthorized(_userSession, FilePath))
    {
        RedirectToControllers(ControllerHelper.Controller.ACCOUNT, ControllerHelper.Controller.Action.ACCOUNT_LOGIN);

        //TODO:
        // 1. Need to stop execution process from here. 
        // 2. No need to execute any line of code from here.
        // I have tested return/Break not working here.
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-07 06:56:42

更改RedirectToControllers以返回ActionResult,然后设置filterContext.Result。

代码语言:javascript
复制
//filterContext.Result = new RedirectResult("~/account/login");

filterContext.Result =  RedirectToControllers(ControllerHelper.Controller.ACCOUNT,  ControllerHelper.Controller.Action.ACCOUNT_LOGIN);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28911408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档