Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:47:24+00:00 2026-05-24T15:47:24+00:00

I’ve seen this question asked a few ways and the solutions are generally for

  • 0

I’ve seen this question asked a few ways and the solutions are generally for other languages and don’t apply to ASP.NET MVC 2.

I am using Jquery & Jquery forms to auto-save user data at a set interval. I still want the application to be able to time out, but the auto-saves via jquery forms keep refreshing the server.

My initial idea to fix this was pretty simple. I’ve already got an ActionFilter I use to see if the session expires. Well, the session won’t ever expire; however, I just keep track of how many auto saves occurr based on a value in session and when it reaches a limit (specified in the web.config), it does a:

 filterContext.Result = new RedirectResult("~/Account.aspx/LogOn");

Well, this doesn’t work because the auto save is doing an ajaxFormSubmit to call the action in the first place. I’ve tried changing the action to redirect to the login page, but the same thing happens….it just doesn’t do a redirect. The only thing the action can return is a Json result. In my latest version (code below) I’m setting the json return value to false and calling a redirectToLogin() function to send the page over to the login page. It doesn’t work and i’m not sure why.

Any thoughts on this would be most helpful.

Excerpt of code that sets up the interval for autosaving on the view (placed just before the form is closed):

<%
    double sessionTimeoutInMinutes = double.Parse(ConfigurationManager.AppSettings["SESSION_TIMEOUT_IN_MINUTES"].ToString());
    double maxContiguousAutoSaves = double.Parse(ConfigurationManager.AppSettings["MAX_CONTIGUOUS_AUTO_SAVES"].ToString());           
    double autoSaveInterval = (sessionTimeoutInMinutes / maxContiguousAutoSaves) * 60 * 1000;               
%>

    <%= Html.Hidden("autoSaveInterval", autoSaveInterval) %>

    <script type="text/javascript">
        $(document).ready(function() {
            var autoSaveFrequency = $('[id=autoSaveInterval]').val();
            //alert(' Auto Save Interval in miliseconds: ' + autoSaveFrequency);                
            setInterval(
                "initAutoSave('AutoSaveGoals', 'message')"
                , autoSaveFrequency);
        });

    </script>       

“AutoSaveGoals” goals is the name of one of my actions. It handles the post, updates certain items in session, and calls the repository.update. It is defined below:

   [HttpPost]
    public ActionResult AutoSaveGoals(Data data)
    {
        Data sessdata = Data();
        sessdata.MpaGoals = data.Goals;
        sessdata.MpaStatus = data.MpaStatus;
        sessdata.StartPeriodDate = data.StartPeriodDate;
        sessdata.EndPeriodDate = data.EndPeriodDate;
        sessdata.AssociatePassword = data.AssociatePassword;

        try
        {
            _repository.update(sessdata);
        }
        catch (Exception e)
        {
            LogUtil.Write("AutoSaveGoals", "Auto Save Goals Failed");
            LogUtil.WriteException(e);
        }

                    if (!autoLogOffUser(RouteData.GetRequiredString("action")))
            return Json(new { success = true });
        else
            return Json(new { success = false });

    }

The initAutoSave function is javascript that uses Jquery & Jquery Forms plugin. Here it is:

function initAutoSave(targetUrl, messageDivId) {
    var options = {
        url: targetUrl,
        type: 'POST',
        beforeSubmit: showRequest,
        success: function(data, textStatus) {
            //alert('Returned from save! data: ' + data);
            if (data.success) {
                var currDateAndTime = " Page last saved on: " + getCurrentDateAndTime();
                $('[id=' + messageDivId + ']').text(currDateAndTime).show('normal', function() { })
            }
            else {
                alert('redirecting to login page');
                redirectToLogin();
                //$('[id=' + messageDivId + ']').text(' An error occurred while attempting to auto save this page.').show('normal', function() { })
                //alert('ERROR: Page was not auto-saved properly!!!!');
            }
        }
    };
    $('form').ajaxSubmit(options);
}

I try doing a javascript redirect in redirectToLogin() but it doesn’t seem to get the url or something behind the scenes is blowing up. Here is how it’s defined:

function redirectToLogin() {    
    window.location = "Account.aspx/LogOn";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:47:25+00:00Added an answer on May 24, 2026 at 3:47 pm

    Now this is just absurd…So, I was looking over my applications (I’ve got several going to QA soon) and noted that I’ve already solved this very question with a much better solution – it was ALL handled in an ActionFilter. I wanted this from the getgo when I asked this question, but to have already implemented it, forgot about that, AND ask again on Stack Overflow…well, I hope my memory issues helps somebody with this. Below is the full action filter code. As always, I’m open to criticism so mock it, revise it, copy it, etc, etc.

    public class UserStillActiveAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
    
            int sessionTimeoutInMinutes = int.Parse(ConfigurationManager.AppSettings["SESSION_TIMEOUT"].ToString());
            int maxContiguousAutoSaves = int.Parse(ConfigurationManager.AppSettings["MAX_CONSEC_SAVES"].ToString());
            int autoSaveIntervalInMinutes = int.Parse(ConfigurationManager.AppSettings["AUTO_SAVE_INTERVAL"].ToString());
    
            string actionName = filterContext.ActionDescriptor.ActionName;
            string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
    
            HttpContext currentSession = HttpContext.Current;      
    
            LogAssociateGoalsSessionStatus(filterContext.HttpContext, actionName);
    
            if (actionName.ToLower().Contains("autosave"))
            {
                int autoSaveCount = GetContigousAutoSaves(filterContext.HttpContext);
                if (autoSaveCount == maxContiguousAutoSaves)
                {
                    var result = new RedirectResult("~/Account.aspx/LogOff");
                    if (result != null && filterContext.HttpContext.Request.IsAjaxRequest())
                    {
                        //Value checked on Logon.aspx page and message displayed if not null
                        filterContext.Controller.TempData.Add(PersistenceKeys.SessionTimeOutMessage,
                            StaticData.MessageSessionExpiredWorkStillSaved);
    
                            string destinationUrl = UrlHelper.GenerateContentUrl(
                                                    result.Url,
                                                    filterContext.HttpContext);
                        filterContext.Result = new JavaScriptResult()
                        {
                            Script = "window.location='" + destinationUrl + "';"
                        };
                    }
                }
                else
                {
                    RefreshContiguousAutoSaves(filterContext.HttpContext, autoSaveCount + 1);
                }
            }
            else
            {
                RefreshContiguousAutoSaves(filterContext.HttpContext, 1);
            }
    
        }
    
        private int GetContigousAutoSaves(HttpContextBase context)
        {
            Object o = context.Session[PersistenceKeys.ContiguousAutoUpdateCount];
            int contiguousAutoSaves = 1;
    
            if (o != null && int.TryParse(o.ToString(), out contiguousAutoSaves))
            {
                return contiguousAutoSaves;
            }
            else
            {
                return 1;
            }
        }
    
        private void RefreshContiguousAutoSaves(HttpContextBase context,
                                                int autoSavecount)
        {
            context.Session.Remove(PersistenceKeys.ContiguousAutoUpdateCount);
            context.Session.Add(PersistenceKeys.ContiguousAutoUpdateCount,
                                        autoSavecount);
        }
    
        private void LogAssociateGoalsSessionStatus(HttpContextBase filterContext, string actionName)
        {
            AssociateGoals ag = (AssociateGoals)filterContext.Session[(PersistenceKeys.SelectedAssociateGoals)];
            bool assocGoalsIsNull = false;
            bool assocGoalsInformationIsNull = false;
    
            if (ag == null)
            {
                assocGoalsIsNull = true;
                assocGoalsInformationIsNull = true;
            }
            else if (ag != null && ag.AssociateInformation == null)
                assocGoalsInformationIsNull = true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.