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

  • Home
  • SEARCH
  • 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 9222117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:44:45+00:00 2026-06-18T03:44:45+00:00

A data-collection site using MVC3 with jQuery and Ajax. The site is using tabs

  • 0

A data-collection site using MVC3 with jQuery and Ajax. The site is using tabs (jquery ui tabs), loaded as partials and each connected to ajax-forms. So each tab is loaded and submitted only within “itself”.

But this creates a problem with the auto-logout and redirection to LogOn. The logout will fire when I, for example, press a new tab. This tab will then be rendered with the full LogOn-page, instead of refreshing the “parent/top” window. So the entire site is mirrored in one of the tabs (like often happens when using frames). The is no frame or iframe usage on the site though.

One way to perhaps solve it would be to itercept the ajax-call, maybe in the OnBegin, to check if the user is logged in. If not redirect the entire window url to /Account/LogOn. I’m not sure on how to accomplish this though, or if it’s the best way to go. Any ideas on execution or tips for better handling of this?

Some code examples:

Edit.cshtml, snippet: the tabs

<div id="tabs">
<ul>
    <li><a href="@Url.Action("PatientGeneralTab", new { guid = @Model })"><span>General</span></a></li>
    <li><a href="@Url.Action("PatientVisitTab", new { guid = @Model })"><span>Visit</span></a></li>
    <li><a href="@Url.Action("PatientDiaryTab", new { guid = @Model })"><span>Treatment</span></a></li>
    <li><a href="@Url.Action("PatientReactionTab", new { guid = @Model })"><span>Adverse Drug Reaction</span></a></li>
</ul>
</div>

General.cshtml, partial, snippet: Ajax.BeginForm()

@using (Ajax.BeginForm("StoreGeneral",
new { },
new AjaxOptions { HttpMethod = "POST", OnBegin = "Saving", OnSuccess = "SavedOk(); reloadPatientHeader();" },
new { id = "form-general" }))
{
    form content here.
}

Web.config, authentication

<authentication mode="Forms">
  <!-- TODO: Change back to 60 -->
  <forms loginUrl="/Account/LogOn" timeout="2" />
</authentication>

Not sure if I need to post any other code-snippets. If so just let me know.

Edit

I stumbled on this question that has similar problems to mine. But I can’t add any code to the controllers since the entire controller-class is wrapped in “[Authorize(Roles=”xxx,yyy”)]”, so the check for login happens before the actual controller actions.

I tried to intercept the call in the AccountController instead, under “LogOn”, but then it just ends up in an infinite loop 🙂

    public ActionResult LogOn()
    {
        bool isAjaxRequest = Request.Headers["X-Requested-With"] == "XMLHttpRequest";
        if (isAjaxRequest && !Request.IsAuthenticated)
        {
            //Response.Headers["X-Requested-With"] = "";
            return RedirectToAction("LogOn");
        }
        return View();
    }

The solution

For reference, this is what I ended up using:

    public ActionResult LogOn()
    {
        bool isAjaxRequest = Request.Headers["X-Requested-With"] == "XMLHttpRequest";
        if (isAjaxRequest && !Request.IsAuthenticated)
        {
            return JavaScript("window.location = '/Account/LogOn'");
        }
        return View();
    }
  • 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-06-18T03:44:46+00:00Added an answer on June 18, 2026 at 3:44 am

    Try using

    Request.IsAjaxRequest()
    

    to detect ajax requests. It’s an extension method in System.Web.Mvc.

    Or you can check manually:

    bool isAjaxRequest = request.Headers["X-Requested-With"] == "XMLHttpRequest";
    

    With this you can do your intercept and test for authentication, and act accordingly. You could either choose not to show layout or stop the whole request and send to login page instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have constructed a collection of data series items. Each data series has multiple
I use WebMatrix to write my site (C#/MVC3) and I am using a local
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
I have a small data collection app which has a single button to start
We have a data collection system that collects measurements from environmental sensors that measure
We have a large internal data collection website. I don't have time to create
I am trying to group a data collection and send it to the View
I just realized that I need to synchronize a significant amount of data collection
I have a MongoDB collection with data that was not saved through my Derby
Im trying to store a list,collection of data objects in Hbase. For example ,a

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.