Embedding a XML-based policy as a resource
In order to embed a XML-based authorization policy into an assembly's manifest,
you have to add the XML file (typically with the .caze extension) to the application's project and mark
it as "Embedded Resource" (in the file's property window).
After compiling the project, you can use code like this to load the policy
Dim resourceName As String = "LaMarvin.DocumentApproval._doc.caze"
Dim policy As AuthorizationPolicy = _
string resourceName = "LaMarvin.DocumentApproval._doc.caze";
AuthorizationPolicy policy =
We've used the
class to load the model from an embedded XML resource.
It is important to note that the assembly calling the
method contains the specified XML resource, otherwise the method will throw an
exception. If the calling assembly doesn't contain the XML resource (perhaps it is in another resource-only assembly),
you can load the resource yourself and then pass the resource stream to the
method as the following pseudo-code illustrates:
Dim resAssembly As System.Reflection.Assembly = <load the resource assembly>
Dim s As System.IO.Stream = _
policy = AuthorizationPolicyLoader.LoadFromStream(s)
System.Reflection.Assembly resAssembly = <load the resource assembly>;
System.IO.Stream s = resAssembly.GetManifestResourceStream(resourceName))
policy = AuthorizationPolicyLoader.LoadFromStream(s);