Click here to Skip to main content
15,885,792 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This seems like it should be easy to do, but after hours of trying different combinations I haven't had any success.

All I want to do is call the following MVC controller EndSession from javascript:

C#
[HttpGet]
public virtual ActionResult EndSession()
{
    Session.Abandon();
    return new EmptyResult();
}


Here is the js:

JavaScript
function SessionTimeOutHandler() {
    $.ajax({
        url: "/Home/EndSession",
        type: 'Get',
        success: function (result) {
            if (result.success) {
            }
        }
    });
}


I've set a break point on Session.Abondon(), and it is never reached. Any help/suggestions are greatly appreciated.
Posted

1 solution

Did you check whether the SessionTimeOutHandler() method is getting called at all? because when I added a button as below it's working fine for me if I click the button!

<input type="submit" onclick="javascript:SessionTimeOutHandler();" value="Log Off" />
 
Share this answer
 
Comments
littleGreenDude 11-Apr-14 8:03am    
Thank you for the response...
Yes, if I set a break point, it does hit the SessionTimeOutHandler. It isn't routing the request properly. If I put the full URL, it works as expected. I've tried both "/Home/EndSession" and "~/Home/EndSession" and neither of those work.
Abinash_Sahoo 11-Apr-14 11:25am    
full URL means which one? what are you returning in result object? What's your expected output?
littleGreenDude 16-Apr-14 11:53am    
I'm accepting your solution. You are correct, it works as coded. My problem was with route resolution, I corrected url: "/Home/EndSession" and it works correctly. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900