Runtime Exception when using Custom Healthmonitoring event in medium trust

Posted by Elementenfresser on Stack Overflow See other posts from Stack Overflow or by Elementenfresser
Published on 2010-06-13T09:28:07Z Indexed on 2010/06/13 9:32 UTC
Read the original article Hit count: 331

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 high 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="" /> 

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about medium-trust