Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
沙盒SharePoint解决方案的错误处理策略_Sharepoint_Sharepoint 2010_Error Handling_Web Parts_Sandbox Solution - Fatal编程技术网

沙盒SharePoint解决方案的错误处理策略

沙盒SharePoint解决方案的错误处理策略,sharepoint,sharepoint-2010,error-handling,web-parts,sandbox-solution,Sharepoint,Sharepoint 2010,Error Handling,Web Parts,Sandbox Solution,我希望为使用沙盒Web部件的SharePoint解决方案开发一种错误处理策略。我最初考虑的是基于此的通用异常处理方法,但这不适用于沙盒Web部件。一旦沙箱中抛出了未经处理的异常,用户代码服务就会接管控制权,从而不会到达基本web部件中的异常处理。沙盒解决方案是否有既定的错误处理方法 如果只是为了将显示的错误消息更改为更用户友好的消息,是否有人知道一种确定沙盒Web部件中何时抛出未处理异常的方法?我想替换标准的“Web部件错误:沙盒代码包装器在部分信任应用程序域中的Execute方法引发了未处理的

我希望为使用沙盒Web部件的SharePoint解决方案开发一种错误处理策略。我最初考虑的是基于此的通用异常处理方法,但这不适用于沙盒Web部件。一旦沙箱中抛出了未经处理的异常,用户代码服务就会接管控制权,从而不会到达基本web部件中的异常处理。沙盒解决方案是否有既定的错误处理方法

如果只是为了将显示的错误消息更改为更用户友好的消息,是否有人知道一种确定沙盒Web部件中何时抛出未处理异常的方法?我想替换标准的“Web部件错误:沙盒代码包装器在部分信任应用程序域中的Execute方法引发了未处理的异常:发生了意外错误”消息


谢谢你,MagicAndi。

事实上,你可以按照你提到的文章建议的方法来做。您只需为您的子web部件要覆盖的所有虚拟属性和方法提供安全的可覆盖项。模式可以描述为:

  • 重写并密封每个虚拟属性和方法,这些虚拟属性和方法应该被可以引发异常的代码重写
  • 使用相同的原型创建可重写的虚拟副本,必要时从中调用基类。这应该被您的后代覆盖
  • 在try&catch中从密封的成员调用新的overridable,并记住在那里捕获的异常
  • 呈现方法要么呈现通常的内容,要么呈现记住的错误消息
  • 这是我使用的基本类躯干:

    public class ErrorSafeWebPart : WebPart {
    
        #region Error remembering and rendering
    
        public Exception Error { get; private set; }
    
        // Can be used to skip some code later that needs not
        // be performed if the web part renders just the error.
        public bool HasFailed { get { return Error != null; } }
    
        // Remembers just the first error; following errors are
        // usually a consequence of the first one.
        public void RememberError(Exception error) {
            if (Error != null)
                Error = error;
        }
    
        // You can do much better error rendering than this code...
        protected virtual void RenderError(HtmlTextWriter writer) {
            writer.WriteEncodedText(Error.ToString());
        }
    
        #endregion
    
        #region Overriddables guarded against unhandled exceptions
    
        // Descendant classes are supposed to override the new DoXxx
        // methods instead of the original overridables They should
        // not catch exceptions and leave it on this class.
    
        protected override sealed void CreateChildControls() {
            if (!HasFailed)
                try {
                    DoCreateChildControls();
                } catch (Exception exception) {
                    RememberError(exception);
                }
        }
    
        protected virtual void DoCreateChildControls()
        {}
    
        protected override sealed void OnInit(EventArgs e) {
            if (!HasFailed)
                try {
                    DoOnInit(e);
                } catch (Exception exception) {
                    RememberError(exception);
                }
        }
    
        protected virtual void DoOnInit(EventArgs e) {
            base.OnInit(e);
        }
    
        // Continue similarly with OnInit, OnLoad, OnPreRender, OnUnload 
        // and/or others that are usually overridden and should be guarded.
    
        protected override sealed void RenderContents(HtmlTextWriter writer) {
            // Try to render the normal contents if there was no error.
            if (!HasFailed)
                try {
                    DoRenderContents(writer);
                } catch (Exception exception) {
                    RememberError(exception);
                }
            // If an error occurred in any phase render it now.
            if (HasFailed)
                RenderError(writer);
        }
    
        protected virtual void DoRenderContents(HtmlTextWriter writer) {
            base.RenderContents(writer);
        }
    
        #endregion
    }
    

    ---费达

    你能把你用过的样品放在沙箱里吗?我想你收到的消息实际上是未处理的异常冒泡了。在本文中,作者简单地包装了所有事件。我认为这种方法应该很有效。