Click here to Skip to main content
15,895,084 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Converting aspx pages into ascx pages Pin
Blikkies9-Apr-14 22:55
professionalBlikkies9-Apr-14 22:55 
GeneralRe: Converting aspx pages into ascx pages Pin
indian14310-Apr-14 6:08
indian14310-Apr-14 6:08 
GeneralRe: Converting aspx pages into ascx pages Pin
Blikkies10-Apr-14 23:25
professionalBlikkies10-Apr-14 23:25 
QuestionGridviews and hyperlinks help please Pin
Tumtum219-Apr-14 1:21
Tumtum219-Apr-14 1:21 
Questioni am not able to insert images to word document created through C# Pin
sonu jnnce8-Apr-14 22:42
sonu jnnce8-Apr-14 22:42 
AnswerRe: i am not able to insert images to word document created through C# Pin
Schatak10-Apr-14 2:06
professionalSchatak10-Apr-14 2:06 
Questionhow to drag usercontrol to page Pin
Nico Haegens8-Apr-14 5:51
professionalNico Haegens8-Apr-14 5:51 
Questionweb api query - 401 error Pin
miss7868-Apr-14 4:57
miss7868-Apr-14 4:57 
Dear all,

When I call 'api/values', it only allows me login as 'full' user details, but if a login as 'trial' user login details, it throws a 401 error. I would like to ask, if I am missing something in the queries in the user class below or the basicAuthn class:
C#
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     {
         AuthenticationHeaderValue authValue = request.Headers.Authorization;

         if (authValue == null || authValue.Scheme != BasicAuthResponseHeaderValue)
         {
             return Unauthorized(request);
         }

         string[] credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authValue.Parameter)).Split(new[] { ':' });
         if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0]) || string.IsNullOrEmpty(credentials[1]))
         {
             //return Unauthorized(request);
             var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
             {
                 Content = new StringContent(string.Format("access denied")),
             };
         }

         ClaimRole user = repository.trial(credentials[0], credentials[1]);
         ClaimRole user2 = repository.unlim(credentials[0], credentials[1]);

             if (user == null || user2  == null)
         {
             var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
             {
                 Content = new StringContent(string.Format("access denied")),
             };

         }
         else
         {

            IPrincipal principal = new GenericPrincipal(new GenericIdentity(user.Username, BasicAuthResponseHeaderValue), new string[] { user.role });
             Thread.CurrentPrincipal = principal;
             HttpContext.Current.User = principal;
         }

         return base.SendAsync(request, cancellationToken);

     }

User Class
C#
public ClaimRole trial(string username, string password)
     {
         var query = (from s in db.subs
                     join u in db.user on s.sUID equals u.uID
                     where s.sExpiryDate >= DateTime.Now &&
                     u.uUsername == username &&
                     u.uPassword == password
                     select u).FirstOrDefault();

         if (query != null)
         {
             // Build a user and add the appropriate Trial role
             return new ClaimRole { Username = query.uUsername, Password = query.uPassword, role = "Trial" };
         }
         else
         {
             // No user was found
             return null;
         }
     }

     public ClaimRole full(string username, string password)
     {
         var query = (from s in db.subs
                     join u in db.user on s.sUID equals u.uID
                     where s.sPID.Value == 163 &&
                     u.uUsername == username &&
                     u.uPassword == password
                     select u).FirstOrDefault();

         if (query != null)
         {
             // Build a user and add the appropriate Trial role
             return new ClaimRole { Username = query.uUsername, Password = query.uPassword, role = "full" };
         }
         else
         {
             // No user was found
             return null;
         }
     }


Please advise
many thanks
AnswerRe: web api query - 401 error Pin
Bernhard Hiller8-Apr-14 22:18
Bernhard Hiller8-Apr-14 22:18 
GeneralRe: web api query - 401 error Pin
miss7868-Apr-14 23:57
miss7868-Apr-14 23:57 
GeneralRe: web api query - 401 error Pin
Bernhard Hiller9-Apr-14 2:19
Bernhard Hiller9-Apr-14 2:19 
GeneralRe: web api query - 401 error Pin
miss78614-Apr-14 6:24
miss78614-Apr-14 6:24 
QuestionHow to save secured password for individual users Pin
antony beula8-Apr-14 2:32
antony beula8-Apr-14 2:32 
AnswerRe: How to save secured password for individual users Pin
Peter Leow8-Apr-14 2:44
professionalPeter Leow8-Apr-14 2:44 
AnswerRe: How to save secured password for individual users Pin
Richard Deeming8-Apr-14 3:07
mveRichard Deeming8-Apr-14 3:07 
QuestionExporting Repeater values in to Excel Pin
indian1437-Apr-14 14:39
indian1437-Apr-14 14:39 
AnswerRe: Exporting Repeater values in to Excel Pin
Schatak8-Apr-14 2:24
professionalSchatak8-Apr-14 2:24 
GeneralRe: Exporting Repeater values in to Excel Pin
indian1438-Apr-14 7:08
indian1438-Apr-14 7:08 
GeneralRe: Exporting Repeater values in to Excel Pin
Schatak8-Apr-14 21:18
professionalSchatak8-Apr-14 21:18 
GeneralRe: Exporting Repeater values in to Excel Pin
indian1439-Apr-14 7:33
indian1439-Apr-14 7:33 
GeneralRe: Exporting Repeater values in to Excel Pin
Schatak10-Apr-14 2:08
professionalSchatak10-Apr-14 2:08 
GeneralRe: Exporting Repeater values in to Excel Pin
indian14310-Apr-14 6:31
indian14310-Apr-14 6:31 
GeneralRe: Exporting Repeater values in to Excel Pin
indian14310-Apr-14 6:58
indian14310-Apr-14 6:58 
QuestionTFS build error Pin
indian1437-Apr-14 8:55
indian1437-Apr-14 8:55 
QuestionImage galleries Pin
Keith888887-Apr-14 5:53
Keith888887-Apr-14 5:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.