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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:05:09+00:00 2026-06-11T01:05:09+00:00

I’ve got a Web API that I’ve added [Authorize] attributes to, which means that

  • 0

I’ve got a Web API that I’ve added [Authorize] attributes to, which means that the unit tests I had previously now fail due to them being unauthorised. Here’s a sample of a basic test along with an initialiser method:

[TestInitialize]
public void CreateServer() {
    var config = new HttpConfiguration();
    WebApiConfig.Configure(config); // Create the routes
    var server = new HttpServer(config);
    this.client = new HttpClient(server);
}

[TestMethod]
public void MyThings_GET_Returns_All_MyThings() {
    var response = this.client.GetAsync("http://localhost/api/1.0/mythings").Result;

    var mythings = response.Content.ReadAsAsync<IEnumerable<MyThing>>().Result;

    Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
    Assert.AreEqual(4, mythings.Count());
}

What I’m wondering is if there’s any way that I can either make my test log in so that it passes the authorization filter, or if there’s any way that I can pass as ASPXAUTH cookie along with the HttpClient request? Or another way of passing authorization that I haven’t thought of?

Nothing I’ve tried seems to work and I’m struggling to find any helpful info anywhere.

Thanks in advance.

  • 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-11T01:05:10+00:00Added an answer on June 11, 2026 at 1:05 am

    I decided that the way I was going about the problem was fundamentally wrong. Using cookie-based authorisation with Web API is just not a good idea, so I’ve decided to get rid of the authorize attributes and perform API-Key-based authentication instead. This makes it easier to test as I can just pass the correct API key in the request, but also means that I’m not relying on cookies for authorisation.

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

Sidebar

Related Questions

We've got an incredibly frustrating situation with a CF Web Services-based API that we
I've got a web API that provides data to users without authentication (the website
I've got an MVC solution that hosts a few routes for Web API services.
I've got a client that would like to use Magento's web services API to
I got a web service that I protect with basic authentication and use ssl.
I got a web DMZ server, that hosts an Extranet ASP.NET application. I want
I've got a web service that is returning objects for me, along with a
I've got a web application that's running really slowly and occasionally hanging. It's a
Currently we got a web service up and running that handles all our C.R.U.D
We've got several web-based applications that are launched from our ERP system (SAP R/3

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.