You are Here: FAQ ->Scripting & Programming->ASP .Net->Article #7


WebHosting Microsoft-Edition This Article is for 1&1 Microsoft Web Hosting Only.


What does "Security Exception" error mean?



"Security Exception"
"Exception Details: System.Security.SecurityException: Security error."

This basically means a class during runtime is linked against a restricted class.
By default ASP.NET error messages are optimised for compile-time and run-time
errors only. So the real error sources are not displayed for linked errors.

These errors arise for example, if you try to access registry variables or system
variables etc.

Sometimes you can get detailed error messages by placing the following code in global.asax file.

<%@ Application %>

<script runat="server" language="c#">
protected void Application_Error(Object sender, EventArgs e) 
{
     Exception ex = Server.GetLastError();
     Server.ClearError();

     Response.Write("<pre>");
     Response.Write(Environment.NewLine);
     Response.Write("Caught Exception: " + ex.ToString() + Environment.NewLine);

     if (ex.InnerException != null)
     {
          Response.Write(Environment.NewLine);
          Response.Write("Inner Exception: " + ex.InnerException.ToString() + Environment.NewLine);
          Response.Write(Environment.NewLine);
     }

     System.Security.SecurityException ex_security = ex as   System.Security.SecurityException;

     if (ex_security != null)
     {
          Response.Write(Environment.NewLine);
          Response.Write("Security Exception Details:");
          Response.Write(Environment.NewLine);
          Response.Write("===========================");
          Response.Write(Environment.NewLine);
          Response.Write("PermissionState: " + ex_security.PermissionState + Environment.NewLine);
          Response.Write("PermissionType: " + ex_security.PermissionType + Environment.NewLine);
          Response.Write("RefusedSet: " + ex_security.RefusedSet + Environment.NewLine);
      }

      Response.Write("</pre>");
}
</script>


Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not Very Useful at all):
1 2 3 4 5