I have a base AsyncController
BaseController : AsyncController
{
[Authorize("Admin")]
public virtual async Task<ActionResult> SomeMethod()
{
//code
}
}
How it is correct to inheritance and override SomeMethod?
UserController : BaseController
{
[Authorize("User")]
public override Task<ActionResult> SomeMethod()
{
return base.SomeMethod()
}
}
OR
UserController : BaseController
{
[Authorize("User")]
public override async Task<ActionResult> SomeMethod()
{
return await base.SomeMethod()
}
}
P.S. Sorry for my english
SomeMethod()is defined within yourBaseControllerclass. Therefore child classes should inherit fromBaseControllerrather thanAsyncController. To override the method, just addvirtualkeyword into the definition.Inheritance and override
Also I have noticed something odd in your
Authorizeattributes. If the base method is allow to Admin only and the child method is allow to User only, then you most likely end up being unable to execute the base method from the child class.