2015-08-24 24 views
1

我在我的mvc單頁面應用程序中使用Controller和ApiController。我使用會話超時從web config.I能夠從控制器重定向但不能從apiController重定向。在MVC中使用API​​控制器會話超時後重定向頁面

檢查會話變量後,是否可以從apiController重定向url?

如果是的話,請給我提供幫助。

在此先感謝。 卡米尼

回答

1

我知道它的老,但也許它可以幫助別人...... 你應該攔截在您的客戶端的響應並重新加載頁面時,HTTP狀態== 401 這裏是攔截所有應用程序的角度比如http迴應:

angular.module('myApp', ['ngRoute']) 
.config(['$routeProvider', '$httpProvider', 
    function ($routeProvider, $httpProvider) { 
     $httpProvider.interceptors.push(function() { 
      return { 
       'response': function(response) 
       { 
        if (response.status === 401) 
         location.reload(); 
        return response; 
       } 
      } 
     }); 

    }]) 
相關問題