razor - MVC Partial View Postback calling wrong method -
i have following partial view html.formbegin helper method;
@if (session["userspecific"]!=null) //(request.isauthenticated) { using (html.beginform("logoff", "account", formmethod.post, new { id = "logoutform", @class = "navbar-right" })) { @html.antiforgerytoken() @* @html.actionlink("hello " + user.identity.getusername() + "!", "index", "manage", routevalues: null, htmlattributes: new { title = "manage" })*@ <input type="button" class="menu-button nav navbar-nav navbar-right" data-target=".customer-list" data-toggle="collapse" /> <div class="customer-list-container"> <div class="customer-list collapse"> <ul> @{ string[] array = { "steel company", "recycling company", "other company", "random name here" }; } @foreach (string name in array) { <li>@html.actionlink(name, "", "", routevalues: null, htmlattributes: new { @class = "customer-link" })</li><hr/> } <li><input type="submit" /></li> </ul> <div class="col-xs-6">@html.actionlink("settings", "index", "manage", routevalues: null, htmlattributes: new { title = "manage" })</div><div class="col-xs-6"><!--<input type="submit" value="log off"/>-><!--<a href="javascript:document.getelementbyid('logoutform').submit()">log off</a></div><div class="clearfix">--></div> </div> </div> } }
the problem is, whenever click on submit button, instead of logging out, runs through login method again, , modifies url read:
account/login?returnurl=%2faccount%2flogoff
i don't why running through login method again, since html.beginform method specifies use logoff method in account controller.
the login method gets called:
// get: /account/login [allowanonymous] public actionresult login(string returnurl) { viewbag.returnurl = returnurl; return view(); }
the logoff method should called:
[httppost] [validateantiforgerytoken] public actionresult logoff() { //authenticationmanager.signout(); session.remove("userspecific"); session["userspecific"] = null; return redirecttoaction("index", "home"); }
it looks index
action method on homecontroller
not marked [allowanonymous]
attribute, means when browser attempts access after being logged out gets redirected login page again because you're trying access page accessible authenticated users.
try adding [allowanonymous]
:
public class homecontroller : controller { [allowanonymous] // <-- add public actionresult index() { return view(); } // other stuff }
Comments
Post a Comment