I have a parent class classA with a variable defined as public string variable. This variable var is initialized in the OnActionExecuting method defined as protected override void OnActionExecuting(ActionExecutingContext test) A child class inherits from this class as public class classB : classA However, ths code below fails
public class classB : classA{
string h;
public classB(){
h = this.variable
}
}
That is, the variable var is null. However, if I declare a public variable variable2 in classA and initialize it on the fly public string variable2 = "test", I can retrieve it in the controller. How can I edit this code so that initialization happening in OnActionExecuting can be accessed in the constructor of the inheriting classes?
OnActionExecutingis invoked after the constructor, so: there is no way to get the value of something that hasn't happened yet.If the inheriting class needs a value that is only available when the base-type's
OnActionExecutingmethod has fired, then: access it then: