Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I would like to know how can setup argument for the following code, as it currently outputting an compiling error - 'user_feb2014.BasicAuthHandler' does not contain a constructor that takes 0 arguments - error.

Global.aspx class
C#
GlobalConfiguration.Configuration.MessageHandlers.Add(new BasicAuthHandler());

I have tried adding user parameters but it outputs even more error. If someone could please provide me with some guidance, that would be very helpful.

C#
public class BasicAuthHandler : DelegatingHandler
    {

        private const string BasicAuthResponseHeader = "WWW-Authenticate";
        private const string BasicAuthResponseHeaderValue = "Basic";

        private readonly iUser repository;

        public BasicAuthHandler(iUser repository)
      {
         this.repository = repository;
      }


Many thanks
Posted
Comments
Jackson K T 20-Feb-14 7:21am    
Add a constructor with 0 arguments
public BasicAuthHandler()
{

}
miss786 20-Feb-14 7:27am    
I tired adding that but that gives me error - "Object reference not set to an instance of an object"

on the following line of code:

api_login user = repository.Validate2(credentials[0], credentials[1]);

Thank you for your response and help.

1 solution

Your constructor expects a parameter: an iUser class / interface instance to load into the repository variable in your class.

If you don't have one available (and I suspect you need to find one) then you will have to create a constructor that takes no arguments - but what that will do with your repository variable later is anybodies guess. It' will probably cause a failure later in the system.
 
Share this answer
 
Comments
miss786 20-Feb-14 7:50am    
Thank you so much for your response. I manage to update the global.aspx code to the following:
GlobalConfiguration.Configuration.MessageHandlers.Add(new BasicAuthHandler(new User()));
OriginalGriff 20-Feb-14 7:54am    
:thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900