Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I've been going down many roads with this, and still no satisfactory result. So let me start with just basics so I can at least get the general direction.

What we have:
- Web site using VS2012, MVC4, C#
- Supports desktop and mobile views (in case that matters)
- Login page directs to home page with links to open new pages in the same window or detail type pages in a new window
- some pages implement partial views inside Kendo UI panes

What I'm looking for:
When a timeout occurs (SessionState or forms - whichever is best - I tried both) I want to open the login screen in it's own window and other windows should be closed. This should happen no matter which window the user is active on when the timeout happens.

What happens now:
Let's say I was on one of the detail pages in a 2nd window and allowed a timeout to occur. I click on a link in the treeview that should load a partial view into a Kendo UI pane. What happens is that the login screen gets loaded into the pane and I still have 2 windows open.

At this point I'll take any help at all, no matter how general or just a pointer to some thread that I missed.
Posted
Comments
Sampath Lokuge 18-Jan-14 2:52am    
Can you put the source code snippets for the way you implemented time out operation and the way you redirected to the log in page ?
Trak4Net 20-Jan-14 14:47pm    
This may or may not be helpful.
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
}

This should tell you if it is an ajax call and then maybe return some javascript instead of a redirect to handle redirecting the entire site.

I also read that if you need to determine if it is a partialview you can use OnActionExecuted and see if the filterContext.result is a partialviewresult ??

Hope this is helpful.

1 solution

It's not much, but:
For the Forms Authentication timeout I just set the Web.Config and let it do it's thing:

<authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="1"/>
    </authentication>


For the sessionState timeout I modified a suggestion I found in one of these threads:

Web.Config:
<sessionstate timeout="1" />


In the Global:asax.cs:
Added in RegisterGlobalFilters() (called from Application_Start())

filters.Add(new CheckSessionOutAttribute());


Added this class:
C#
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class CheckSessionOutAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
        if (!controllerName.Contains("account"))
        {
            HttpSessionStateBase session = filterContext.HttpContext.Session;
            var user = session["UserName"]; //Key 2 should be User or UserName
            if (((user == null) && (!session.IsNewSession)) || (session.IsNewSession))
            {
                //send them off to the login page
                var url = new UrlHelper(filterContext.RequestContext);
                var loginUrl = url.Content("~/Account/Login");
                filterContext.HttpContext.Response.Redirect(loginUrl, true);
            }
        }
    }
}


Note: for testing each I modify the Web.Config timeout values so that I know which one I'm getting.

I know the application is just doing what it's told to do - the click in the KendoUI treeview is directing to the detail-pane, which is where the Login screen in getting loaded. I'm trying to figure out how to intercept all that at a higher level and just go to a full login screen, and close extra pages. Perhaps I need code in every view?

Here is the code for the treeview select to show the redirect, but I need to take a comprehensive action no matter what page/control is touched.

function Selected(e) {
    var id = $('#ItemId').val();
    var treeItem = treeview.dataItem(e.node);
    $.post('@Url.Action("_Detail")', {
        id: treeItem.id, actid: id
    }, function (data) {
        $('#detail-pane').empty()
        $('#detail-pane').append(data)
    });
}


Thanks - I'm relatively new on the MVC learning curve so I appreciate your patience.
 
Share this answer
 
Comments
Member 10052344 20-Jan-14 15:12pm    
Sorry - this was not meant to be the solution - just a response to the request for a code snippet.

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