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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:24:27+00:00 2026-06-10T16:24:27+00:00

We have a Login enforcement app which only allows a user to be logged

  • 0

We have a Login enforcement app which only allows a user to be logged into a single session in our app. This is done in the postauthenticate request event handler.

If the user needs to be logged out (they have another session) we do:

FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

This has worked fine for a long time. Now we are adding a web api to our app. When you hit a web api Url the PostAuthentication event does fire, it sees the user has logged in elsewhere… however, it does a redirect to login.. well that’s expected due to the code.

I attempted to change the code above to set the Response.StatusCode = 401 and then end the request. Well, that works fine, but asp.net is being “nice” and auto redirecting to the login page.

Is there a way I can respond with a 401 and not have it redirect to the login page if this request came from web api URL?

  • 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-10T16:24:28+00:00Added an answer on June 10, 2026 at 4:24 pm

    The problem is that the FormsAuthenticationModule catches all outbound requests at EndRequest and if the status is 401 AND the URL isn’t the configured login location, you get redirected to the login location.

    There’s not any great way to fix that. Basically I’ve seen two ways, neither of which are awesome:

    1. Implement your own FormsAuthenticationModule. Rather than use the out-of-the-box one, roll your own that knows about the exceptions and lets the 401 through.
    2. Add some logic to the login page that issues the 401 for you. Look at the inbound URL. If the URL is one of the redirects from the FormsAuthenticationModule but the user is already logged in, issue a 401 rather than displaying the login form. The FormsAuthModule won’t do a circular redirect to the login form, so you’re OK.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have login controller in my CI app: function index() { if($this->session->userdata('logged_in')==TRUE) redirect('/success'); $data['error']=$this->session->flashdata('errormessage');
I have login page, once logged in I create a session variable to store
When starting the app, if the user doesn't have login information stored, I want
In ASP.NET web app, I have login.aspx. I force that every user access through
We have login credentials for our database stored in some config file which checked
on my web site I want to have login/registration form in modal window done
Hi I want to create a WCF service that have login method, which is
i am doing one small application , wheich have login functionality, in the user
I have a login page (an activity in Android), during which I run an
I have login screen when the app is launched. And am able to switch

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.