Authorization Handler tutorial

Topics: Policy Injection Application Block
Aug 22, 2007 at 7:22 PM
Hi All
I'm lookiong Authorization Handler tutorial or sample code to use it like Attribute for Method and Class.

Thanks
Aug 22, 2007 at 9:56 PM
Hi,

Can you provide more details about your scenario? Do you want to specify authorization requirements with attributes on methods using the AuthorizationCallHandlerAttribute?

Fernando
Aug 23, 2007 at 1:37 PM
Hi Fernando,

Thanks for the reply.
Yes you are right.
Basically, i want to to use Authorization Handler's attibute on methods as well as classes.

-sha


fsimonazzi wrote:
Hi,

Can you provide more details about your scenario? Do you want to specify authorization requirements with attributes on methods using the AuthorizationCallHandlerAttribute?

Fernando

Aug 23, 2007 at 2:06 PM
//Here is the code
public class MyClass : MarshalByRefObject
{
AuthorizationCallHandler("What should I write here")//<---What should i write here???
public void MyMethod()
{
string str1 = "xyz";
}
}

//calling from another class
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;

class Program { public void AnotherMethod()
{
TargetClass tc = PolicyInjection.Create<MyClass >(); //<<<--- Runtime error "Could not load file or assembly...in .Common dll ...doesnt match assembly"
tc.MyMethod();
}
}
Aug 23, 2007 at 3:16 PM
Hi,



sha wrote:
//Here is the code
public class MyClass : MarshalByRefObject
{
AuthorizationCallHandler("What should I write here")//<---What should i write here???
public void MyMethod()
{
string str1 = "xyz";
}
}


You should specify the name of the authorization provider you want to use to authorize, as defined in the configuration for the security block, and the name of the operation to use when querying for authorization for this method.



//calling from another class
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;

class Program { public void AnotherMethod()
{
TargetClass tc = PolicyInjection.Create<MyClass >(); //<<<--- Runtime error "Could not load file or assembly...in .Common dll ...doesnt match assembly"
tc.MyMethod();
}
}


This is not related to any particular block. It's very likely the set of assemblies referenced by your configuration file does not match the set of assemblies referenced by your code. This usually happens if you reference the EntLib projects but do not set the configuration set on your solution; please see this post from Tom for details http://blogs.msdn.com/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx.

Fernando