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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:53:47+00:00 2026-06-01T11:53:47+00:00

How do I even begin coding authentication using ASP.NET Web API so it is

  • 0

How do I even begin coding authentication using ASP.NET Web API so it is cross-platform to support desktop, mobile and web? I’d read of some methods of doing RESTful authentication, such as using tokens in the header.

Are there any example projects out there that utilizes this method?

Questions:

  1. If not how do I fix the [Authorize] attribute to read the token?
  2. How do I generate this token? I dont think i can use formsauthentication because that uses cookies.
  3. How do I handle the actual authorization, do the client send raw password and username then I generate the token or is there some other way?
  4. How do I handle when my website is using it? I heard this is handled differently than when an app is using it, such as getting the domain and authorizing it.
  • 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-01T11:53:48+00:00Added an answer on June 1, 2026 at 11:53 am

    I think tokens would be a solid way to go. Forms authentication is based on cookies for the web. Not the most idea situation for all non browser clients though.

    What I’d suggest is creating a custom AuthorizationFilterAttribute and overriding the OnAuthorization method. In that method, you could check for the existence of a token that you’ve issued to the client after they’ve supplied valid credentials. You can use this attribute on any method or controller you want validated. Here’s a sample you might reference

     public class AuthorizeTokenAttribute : AuthorizationFilterAttribute 
    {      
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (actionContext != null)
            {                
                    if (!AuthorizeRequest(actionContext.ControllerContext.Request))
                    {
                        actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized) { RequestMessage = actionContext.ControllerContext.Request }; 
                    }
                    return;
            }
        }
    
        private bool AuthorizeRequest(System.Net.Http.HttpRequestMessage request)
        {
            bool authorized = false;
            if (request.Headers.Contains(Constants.TOKEN_HEADER))
            {               
                var tokenValue = request.Headers.GetValues("TOKEN_HEADER");
                if (tokenValue.Count() == 1) {
                    var value = tokenValue.FirstOrDefault();               
                   //Token validation logic here
                   //set authorized variable accordingly
                }                
            }
            return authorized;
        } }
    

    TOKEN_HEADER is just a string representing an HTTP header that the client should pass back for authenticated requests.

    So let’s walk through it

    1. Client requests secure data
    2. Client is not authorized, return a response with an Unauthorized status code
    3. Client sends credentials to authenticate, which should be secured via HTTPS
    4. Once validated, client receives a token via an HTTP header, or whatever works for you
    5. Client tries requesting secure data again, this time attached the token to the request
    6. The AuthorizeTokenAttribute will validate the token and allow the action to execute.

    Also, check this post by John Petersen. Making your ASP.NET Web API’s secure

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

Sidebar

Related Questions

I'm building a basic web application in ASP.NET 4.0 with C# in Visual Studio
I am working on an web application using flask, postgresql and sqlalchemy and coding
To begin with, I'm not even sure, if it is the right way to
Even though it is possible to write generic code in C using void pointer(generic
I'm not sure where to even begin to fix this myself, so I am
I'm not sure where to even begin solving this, but I'm getting an exception
I honestly don't know what this is called or even begin how I search
I ran my app in the emulator. Where do I even begin? First line
I really don't even know where to begin. I was trying to do some
I am not sure where to even begin describing the issue I'm having. I

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.