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 7681579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:22:25+00:00 2026-05-31T18:22:25+00:00

I am seeing odd behavior with MVC 3 methods that return a JsonResult when

  • 0

I am seeing odd behavior with MVC 3 methods that return a JsonResult when used with the Authorize attribute. What looks like happens is the Authorize is correctly evaluated when I am not logged in but instead of redirecting to the logon form the Json response is the logon form. Is there an addition attribute that directs the response to not return a value but instead redirect the user to the logon form, preferebly with the correct returnUrl value? What I did as a demo was to setup a new MVC3 site and added AspNetMembership to my DB using the aspnet_regsql.exe command. All that is setup and logging me in correctly. The behavior of the JsonResult doesn’t seem right and I’m hoping I have just missed an attribute to make it work properly. Any help is greatly appreciated, thanks in advance.

Here is the Account Controller (leaving out the Post action which is not part of this question).

public class AccountController : Controller
{
    public ActionResult LogOn()
    {
        return View();
    }

    [Authorize]
    public JsonResult AuthorizedAction()
    {
        return Json("Only returns if I am authorized");
    }
}

Here is the Html markup:

<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnTest").click(function () {
            $.ajax({
                type: "POST",
                url: "Account/AuthorizedAction",
                data: {},
                success: function (result) {
                    $("#testMe").html(result);
                },
                error: function (result) {
                    $("#testMe").html('Something broke in the ajax request');
                }
            });             
        });
    });
</script>

<input type="button" id="btnTest" value="Test me" />
<div id="testMe">I have initial text</div>

The Result:

1) When logged in I get ‘Only returns if I am authorized’ in my test div
2) When not logged and I have a break point in my Logon() method I see this value
Request[“returnUrl”]
“/Account/AuthorizedAction”

The test div I have displays the logon form 🙂 this seems like I’m just not handling this properly.

  • 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-31T18:22:26+00:00Added an answer on May 31, 2026 at 6:22 pm

    You may take a look at the following blog post in which Phil Haack explains a very nice technique allowing you to detect that a request to an unauthenticated resource has been made and act accordingly by intercepting the 401 HTTP status code.

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

Sidebar

Related Questions

We are seeing odd behavior with JSF inputs that we dont see on regular
I'm seeing an odd behavior with trying to get seconds since epoch in objective
I am seeing some odd behavior in SQL Server AVG calcuation. On manual calculation,
I've got a simple MVC (RC1) app set up, and I'm seeing some odd
I'm seeing an odd behavior connecting to a development webserver running on my local
I'm seeing really odd behavior in string concatenation in PowerShell. At first I was
I have the following R code and am seeing odd behavior - when I
I'm working with javascript Date objects and seeing very odd behavior. If I keep
This is an odd question, but only commensurate with the strange behavior I'm seeing.
I'm seeing odd behavior in my application running on standalone jetty. Starting the application

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.