Pregunta

I have an web service call where I get a list of 5 access codes, a user will be able to login with one of those codes(basically feel special that they have the code, but nothing secure about it, as they could share codes if they wanted to)

I would want to be able to use the [Authorize] if at all possible. Won't be using a database, just that one api call. Is this possible?

¿Fue útil?

Solución

Check the codes on login with a simple if statement

if{code1 == "edgwreggw" || code2 == "etgwg"....)
{
FormsAuthentication.RedirectFromLoginPage(data.username, true);
}

else
{
 login fail
}

Webconfig

<authentication mode="Forms">
  <forms loginUrl="~/UserAuthentication/SignIn" timeout="10" defaultUrl="~\Home\Index" />
</authentication>

Otros consejos

So.. you really don't care about security but you want to hand out 1 of 5 codes to random people to use your web service.

Simple enough. Put the codes in an array. Check if the code passed in is one of those values. If not, end the request. If it is, process the request.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top