Understanding CAS security is important in order to develop and architecture .NET applications and libraries.
A good way to understand CAS security is to think about the problem faced by people writing libraries that will be installed in client machines. How do you go protecting those libraries from being misused by untrusted code (e.g. EvilMethod() running in Evil.dll in an .xbap hosted in www.evil.com)?
CAS answers that question by doing checks based on qualities of the calling code, like its strong name, the permissions granted by the system to the calling code, the zone code is being run from, etc.
I'll give you an example: say you are assigned the task of developing a special purpose printing library that will be installed (GAC'ed) in the client machines of a big company, and that library has to be called only by methods residing in assemblies owned by the company.
CAS can help you here. Basically, you should be able to check the strong name of the callers in the publicly exposed methods:
void Print(string toPrint)
{
new System.Security.Permissions.StrongNameIdentityPermission(blob, "My Company Inc.", new Version("1.0.0.0")).Demand();
// print code
}
Now, say you have to expose a method to print a test page. You may want that method to be called by everyone, not only your company's assemblies. What to do?
You can Assert() the permission, so the stack walk (demand) is cut in your frame and doesn't check your callers:
void PrintTestPage()
{
new System.Security.Permissions.StrongNameIdentityPermission(blob, "My Company Inc.", new Version("1.0.0.0")).Assert();
Print("Test Page");
}
See how we only Assert() the permission when exposing a safe version of an API (think of an Assert() like a frame saying "stop checking my callers! - I know what I'm doing, and I'm safe to be called by malicious code").
This is a good reading for the subject.