1and1 Help Centre Categories

print article

What is a "Security Exception" Error?

When using ASP.NET, you may encounter a "Security Exception" error called "Exception Details: System.Security.SecurityException: Security error."

This indicates that 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. 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.

You can get detailed error messages by placing the following code in the 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>
For additional information, you may want to reference: