C# multiple Attributes Calling Sequence -
i have multiple attributes want apply on controller .which need call them in order of sequence ,because if first attributes executes ,i initialize variables following attribute use.
[authorizelicense] [merchantloggedin] [merchantauthorize] public class merchantcontroller : basecontroller { }
definition of attributes
public class authorizelicense:authorizeattribute { protected override bool authorizecore(httpcontextbase httpcontext) { if(somecondition true){ //initialize variables next attribute use; } } protected override void handleunauthorizedrequest(authorizationcontext filtercontext) { } }
next attribute
public class merchantloggedin:authorizeattribute { protected override bool authorizecore(httpcontextbase httpcontext) { //use initialize variables previous attribute } protected override void handleunauthorizedrequest(authorizationcontext filtercontext) { } }
the challenge facing attributes not called in sequence have defined them on class ; top bottom. please ..what doing wrong.
you can use order parameter
[authorizelicense(order = 1)] [merchantloggedin(order = 2)] public class ...
Comments
Post a Comment