引入https后,ng-click不起作用

时间:2016-07-18 16:16:13

标签: jquery angularjs asp.net-mvc

我实现了登录和注销功能。我使用的是.NET MVC和angularJS。在我输入HTTPS之前,一切正常。

这是我用于注销的angularJS代码:

function getCareersView(myPath, myView) {
    //var path = $window.location.pathname;
    var pathParts = myPath.split('/');
    var result = '/';
    for (var i = 0; i < pathParts.length; i++) {
        if (pathParts[i] !== 'Careers' && pathParts[i] !== '') {
            result += pathParts[i];
            result += '/';
        };
        if (pathParts[i] === 'Careers') {
            result += pathParts[i];
            break;
        };
    };
    result += myView;
    return result;
};


var mainModule = angular.module('main', ['ngAnimate', 'ui.bootstrap']);

mainModule.controller('mainController', function ($http, $scope, $location, $window) {
    $scope.currentUserName = $window.sessionStorage.getItem('userName');
    $scope.currentUserID = $window.sessionStorage.getItem('userID');
    $scope.currentProfileID = $window.sessionStorage.getItem('profileID');

    $scope.logOut = function () {
        $window.sessionStorage.setItem('userName', null);
        $window.sessionStorage.setItem('userID', null);
        $window.sessionStorage.setItem('profileID', null);
        $window.sessionStorage.setItem('currentJobID', null);
        $window.sessionStorage.setItem('justApplied', 'false');

        $scope.currentUserName = undefined;
        $scope.currentUserID = undefined;
        $scope.currentProfileID = undefined;
        $window.location.href = getCareersView($window.location.pathname, '/JoinBlueScope');

    };

});

这是我的HTML代码:

        @*<li ng-click="logOut()" ng-show="currentUserName != undefined && currentUserName !=='null'"><a href="#" id="careerLoginLogoutLink">log out</a> </li>
        <li ng-show="currentUserName == undefined || currentUserName ==='null'">@Html.ActionLink("Log in / Register", "Login", "Careers", routeValues: null, htmlAttributes: new { id = "careerLoginLogoutLink" })</li>*@

        <li ng-show="currentUserName != undefined && currentUserName !=='null'"><a href="#" id="careerLoginLogoutLink" ng-click="logOut()">log out</a> </li>
        <li ng-show="currentUserName == undefined || currentUserName ==='null'">@Html.ActionLink(linkText: "Log in / Register", actionName: "Login", controllerName: "Careers", protocol: "https", hostName: Request.Url.Authority, fragment: null, routeValues: null, htmlAttributes: new { id = "careerLoginLogoutLink" })</li>

注释掉的2个li标签是以前没有HTTPS的代码。

我用[RequiredHttps]和所有其他控制器[ExitHttps]修饰了我的CareersController。我按照此链接实现了ExitHttps属性:

http://www.primaryobjects.com/2012/04/23/moving-in-and-out-of-ssl-https-in-c-mvc-asp-net/

如果需要,我可以提供此代码和控制器。当他们点击&#34;退出&#34;时,我只是重置会话并将其重新路由到安全页面。我的控制器中没有注销操作。我确实有登录操作。

我的问题是当我退出时,我无法重新登录。我有一个JQuery异常抱怨href属性无效。我认为我的内容情况喜忧参半,但我不知道如何解决它。

你能给我一些建议吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

事实证明,这只发生在本地机器的IIS Express中。我向Azure发布了相同的代码,一切正常。