Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to give the access to users to access the API methods.

For Example : Please see the below action method which can be access by user "hrushi",
But in my scenario we want to put user list from database.

Is there any best way to do this ?

I hope question is clear now....




namespace myApp.Controllers
{
using myApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;

[Authorize(Users = "hrushi")]
public class ValidateController : ApiController
{
// GET: Validate
public object Get()
{
IEnumerable<string> headerValues = null;
string stuid = "";
string dob = "";
if (Request.Headers.TryGetValues("id", out headerValues) == true)
{
stuid = headerValues.FirstOrDefault();
}
ErrorReply objreply = new ErrorReply();
string baseUrl = Request.RequestUri.AbsolutePath;

DateTime STUDOB = Convert.ToDateTime(dob);
ValidateReply objValidReply = new ValidateReply();
if (CommonClass.STUDENT_EXISTS(stuid, STUDOB, ref objValidReply))
{
return objValidReply;
}


//return new string[] { "Hello REST API", "I am Authorized" };
}
}
}

What I have tried:

I am still waiting for the solution
Posted
Updated 3-Mar-19 19:21pm
v2
Comments
OriginalGriff 3-Mar-19 7:20am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So you are going to have to explain exactly what you mean, concentrating particularly on what you mean by "access", and when this access control should take place. For example, run time or compile time? How do you tell what user it is? And so forth.

Use the "Improve question" widget to edit your question and provide better information.
Member 14161968 4-Mar-19 1:21am    
Hi dear,
I have updated question hope this is clear for you...

1 solution

What you're asking for isn't clear. What framework are you using? What security methods are you using? Is this public or private APIs. Without information like that, it's literally impossible to answer your question.
 
Share this answer
 
Comments
Member 14161968 4-Mar-19 1:22am    
Hi James,
I have updated the question hope this is clear for you...

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



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