Answer the question
In order to leave comments, you need to log in
How to execute code before passing it to controller in ASP.NET?
Good day.
There is a task to check authorization data at the user. The request looks like this
/user_id/token/controller/function/argument1/argument2
It is necessary to execute a method that checks id and token before the function is called in the controller (that is, before calling the View). How can I do that?
Answer the question
In order to leave comments, you need to log in
public class AuthorizeUserAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if( httpContext.Request.RequestContext.RouteData.Values["token"]&&httpContext.Request.RequestContext.RouteData.Values["id_пользователя"])//ваша логика проверки на валидность
{
return true;
}
return false;
}
}
[AuthorizeUser]
public ActionResult ВашеДействие()
{
//...
return View();
}
[AuthorizeUser]
public class TestController
{
//...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question