如果在Asp.net MVC中AbpAuthorize失败,如何重定向到登录页面? [英] How to redirect to login page if AbpAuthorize is failed in asp.net mvc?

查看:282
本文介绍了如果在Asp.net MVC中AbpAuthorize失败,如何重定向到登录页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修改了asp.net样板mvc模板css,但是不知何故,我可能会弄乱代码.现在,如果用户未登录/未授权,则会弹出错误,单击确定",而不是重定向到登录页面,而是重定向到app.js中的默认$ urlRouterProvider.这是应用程序配置的一部分:

I have modified the asp.net boilerplate mvc template css, but somehow, I might mess up with the code. Now if the user is not logged in/not authorized, the error pops out, click ok, instead of redirecting to the login page, it redirects to the default $urlRouterProvider in the app.js. Here is part of the app config:

    app.config([
    '$stateProvider', '$urlRouterProvider', '$locationProvider', '$qProvider',
    function ($stateProvider, $urlRouterProvider, $locationProvider, $qProvider) {
        $locationProvider.hashPrefix('');
        $urlRouterProvider.otherwise("/");
        $qProvider.errorOnUnhandledRejections(false);


        $stateProvider
            .state('login', {
                url: '/Account/Login',
                templateUrl:'/Views/Account/Login.cshtml'
            })
           .state('dashboard', {
                url: '/',
                templateUrl: '/App/Main/views/dashboard/dashboard.html',
                data: { pageTitle: '' }
            })
]);

任何人都可以解释一下幕后发生的事情吗?不管您在angularjs中定义了什么,将用户重定向到登录页面的魔术代码是什么?

Can any one please explain what happens behind the scenes? What is the magic code that redirects the user to the login page regardless of what you defined in the angularjs?

提前谢谢!

推荐答案

经过几天的搜索,我发现它不起作用的原因是因为该响应未由HandleUnauthorizedRequest方法处理.当收到401未经授权的状态时,它应该重定向到您在启动中定义的路径.

After days of search, I found out the reason why it did not work is because the response is not handled by HandleUnauthorizedRequest method. It is supposed to redirect to the path you defined in the startup when receiving 401 unauthorized status.

为什么它没有触发HandleUnauthorizedRequest是因为我在Home控制器中删除了AbpMvcAuthorize.

And why it did not trigger the HandleUnauthorizedRequest is because I removed the AbpMvcAuthorize in Home controller.

这篇关于如果在Asp.net MVC中AbpAuthorize失败,如何重定向到登录页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆