Security Exception when using Custom ASP.NET Healthmonitoring event in medium trust
- by Elementenfresser
Hi, I'm using custom healthmonitoring events in ASP.NET
We recently moved to a new server with default High Trust Permissions. Literature says that healthmonitoring and custom events should work under Medium or higher trust (http://msdn.microsoft.com/en-us/library/bb398933.aspx).
Problem is - it doesn't. In less than full trust I get a SecurityException saying
The application attempted to perform an operation not allowed by the security policy
It works in Full trust or when I remove the inheritance of System.Web.Management.WebErrorEvent.
Any suggestions anyone?
Here is the super simple code behind with a custom event defined:
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
CallCustomEvent();
}
catch (Exception ex)
{
Response.Write(ex.Message);
throw ex;
}
}
/// <summary>
/// this metho is never called due to lacking permissions...
/// </summary>
private void CallCustomEvent()
{
try
{
//do something useful here
}
catch (Exception)
{
//code to instantiate the forbidden inheritance...
WebBaseEvent.Raise(new CustomEvent());
}
}
}
/// <summary>
/// custom error inheriting WebErrorEvent which is not allowed in high trust? can't believe that...
/// </summary>
public class CustomEvent : WebErrorEvent
{
public CustomEvent()
: base("test", HttpContext.Current.Request, 100001, new ApplicationException("dummy"))
{
}
}
and the Web Config excerpt for high trust:
<system.web>
<trust level="High" originUrl="" />