MVC Logout not working when using Areas

Hi:

I have a standard MVC application in which I have incorporated the boiler plate partial in the Navigation bar.  
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated) {
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post,  new { id = "logoutForm", @class = "navbar-right" })) {
        @Html.AntiForgeryToken()

        <ul class="nav navbar-nav navbar-right">
            <li>
                @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
            </li>
            <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
        </ul>
    }}}
}
else {
    <ul class="nav navbar-nav navbar-right">
        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
    </ul>
}

Open in new window


I then created a new Area for Admin and created a new Admin Layout in that area.  The Navbar for the layout in the new area references the original Login Partial.  All works fine unless I try to log out froma page in  the Admin Area in which case I get the following error:

 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /Admin/Account/LogOff

Open in new window

RBSAsked:
Who is Participating?
 
kblauCommented:
tried this.  got same result as you and found best fix w/o having to change your architecture, but would probably change architecture to put ALL of account information in one place, either the area or outside the area, and not split it up.

I created my view and it called a shared partial (this same shared partial was called from my area).
I clicked on logout and it worked.
I clicked on a link to call the area page and while in the area page view, click on logout and it got not found error like you had.

To resolve, I changed my controller name in my view in my area to call "AccountInArea" controller, after copying Account controller outside area to this new controller.

Let me know if you have any questions.
0
 
RBSAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.