未经授权的webapi调用返回登录页面而不是401
如何配置我的mvc / webapi项目,以使从剃刀视图调用的webapi方法在未经授权时不返回登录页面? 它是一个MVC5应用程序,还具有用于通过javascript进行调用的WebApi控制器。 下面的两种方法 [Route("api/home/LatestProblems")] [HttpGet()] public List<vmLatestProblems> LatestProblems() { // Something here } [Route("api/home/myLatestProblems")] [HttpGet()] [Authorize(Roles = "Member")] public List<vmLatestProblems> mylatestproblems() { // Something there } 通过以下角度代码调用: angular.module('appWorship').controller('latest', ['$scope', '$http', function ($scope,$http) { var urlBase = baseurl + '/api/home/LatestProblems'; $http.get(urlBase).success(function (data) { $scope.data = data; }).error(function (data) { …