1

I have an MVC application where I am using the MVC controller to handle logging in and logging out. When I attempt to log out, I call the LogOff action on my MVC Account controller which redirects to the Login action on this controller. I have no problem calling this code and the Login action appears to run successfully. However, the last line of this action is

return View();

I can see my screen flash as if it is drawing a new page. However, I can still see http://localhost:60847/#/home in my browser instead of http://localhost:60847/Account/Login.

Is there something I need to add to the routing to allow it to handle MVC addresses? Currently, my routing is the following:

$routeProvider.when("/home", {
    //controller: "homeController",
    templateUrl: "app/layout/home.html"
});

$routeProvider.otherwise({ redirectTo: "/home" });

Thanks in advance!

1 Answer 1

1

I looked up in several places and concluded that one option for fixing this issue was to call this action only from a hyperlink and include target="_self". I can still add a ng-click attribute on the hyperlink and call code in my angular controller. This is not quite what I wanted to do because I wanted to make the call from my angular controller instead of from the hyperlink, but it will work.

The code I used is as follows:

using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" }))
{
    @Html.AntiForgeryToken()
    <ul data-ng-controller="accountController as acctCtrl">
        <li><a data-ng-click="acctCtrl.logout()" href="javascript:document.getElementById('logoutForm').submit()" target="_self">Log off</a></li>
    </ul>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.