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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:38:10+00:00 2026-05-28T18:38:10+00:00

I have an existing asp.net mvc website that uses basic forms authentication. The site

  • 0

I have an existing asp.net mvc website that uses basic forms authentication. The site has a login page that posts back to a login action, which logs the user in via FormsAuthentication.SetAuthCookie(). I am looking to add an api to the site, as an mvc2 area, where users would be authenticated based on a token passed as an http header. This area will consist of only json actions, so redirecting the user to a login page doesn’t make sense. Instead, I want the users to just pass a token along with each request. That token is mapped to each user account and the user would be authenticated automatically.

I’m struggling with where to put this logic. At this point, the best choice seems to be adding the header lookup logic and authentication to the Global.asax in the Application_AuthenticateRequest method. I want to avoid needing to redirect the user after calling FormsAuthentication.SetAuthCookie(), though. I want the login action to be transparent to them.

Am I approaching this the wrong way?

As a side note: Requiring a username/password for api requests is not possible, as the site has a mix of users. Some joined using OpenID while the rest joined with a username/password.

  • 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-28T18:38:11+00:00Added an answer on May 28, 2026 at 6:38 pm

    Went down the road of adding header lookup to the Application_AuthenticateRequest event in Global.asax. The code looks something like:

    private const string AuthorizationHeader = "Authorization";
    
    if (!string.IsNullOrWhiteSpace(request.Headers[AuthorizationHeader]))
    {
      try
      {
        // Remove Basic from beginning and then decode the string
        var token = request.Headers[AuthorizationHeader].Substring(6);
        token = new ASCIIEncoding().GetString(Convert.FromBase64String(token)).Split(':')[0];
    
        return UserService.FetchByApiToken(token);
      }
      catch
      {
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Curious what recommendations anyone has. I have an existing asp.net forms application that does
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
I have an existing complex website built using ASP.NET MVC, including a database backend,
I have an existing ASP.Net MVC project that is using entities / repositories in
I have an existing asp.net web application that I'm updating to include some MVC
I have an existing ASP.NET web application that I'm converting to MVC 1.0. The
I have an existing website developped using ASP.NET MVC 3 and Entity Framework 4
I have an existing ASP.NET MVC 2 application that I've been asked to extend.
I have an existing ASP.NET website with some custom routing, within a Solution that
I have an existing ASP.NET MVC based website. Very typical: XHTML, CSS, jQuery, C#,

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.