I am using Web API project built with c# and I have a few controllers in it.
The controllers have their own constructor methods and in the constructor I am checking for authentication.
When the authentication is successful then it should execute the desired function, if not I want it to return JSON as invalid authorization.
I have the following code in place to do it:-
public class UsersController : Controller
{
private RM.Data.IUserData _userData;
private String APIToken = AppConfig.GetConfigValue("APIToken");
public UsersController()
{
if (match)
{
// then execute function
}
else
{
// stop execution
}
}
}
I have tried the following things to stop the execution of the function.
return;
HttpResponse.End();
System.Threading.Thread.CurrentThread.Interrupt();
System.Threading.Thread.CurrentThread.Abort();
System.Web.HttpContext.Current.Response.Close();
Enviorment.Exit(0);
Enviorment.Exit(1);
Enviorment.Exit(-1);
Some terminate the app and the others let the api to continue processing.
I have about 50 API and cannot attach this function to each and every API. What can be done in this case.
Nothing worked for me from the above. Can you guys please help?