Asp.net PostSharp不在共享主机上工作
最近,我发现了令人惊叹的AOP框架Asp.net PostSharp不在共享主机上工作,asp.net,asp.net-mvc-4,postsharp,Asp.net,Asp.net Mvc 4,Postsharp,最近,我发现了令人惊叹的AOP框架PostSharp,它似乎是开箱即用的。一切都很好,我还使用log4net实现了一个自定义日志方面,直到我决定将我的应用程序上传到共享主机上 它在我的共享主机上不工作。在使用自定义特性的页面上,我发现以下错误: Sorry, an error occurred while processing your request. 我想知道是否有什么我需要调整,让PostSharp在共享主机上工作 另外,当我收到的消息根本没有帮助时,如何在失败的页面上抛出有用的异常消息
PostSharp
,它似乎是开箱即用的。一切都很好,我还使用log4net实现了一个自定义日志方面,直到我决定将我的应用程序上传到共享主机上
它在我的共享主机上不工作。在使用自定义特性的页面上,我发现以下错误:
Sorry, an error occurred while processing your request.
我想知道是否有什么我需要调整,让PostSharp在共享主机上工作
另外,当我收到的消息根本没有帮助时,如何在失败的页面上抛出有用的异常消息
我的观点如下:
[Serializable]
public class LoggingAspect : OnMethodBoundaryAspect
{
//Here is the once-per-class call to initialize the log object
//[NonSerialized]
//private static readonly ILog log = LogManager.GetLogger("Logger");
private string methodName;
private string className;
private Type declaringType;
/// <summary>
/// Method executed at build time. Initializes the aspect instance. After the execution
/// of <see cref="CompileTimeInitialize"/>, the aspect is serialized as a managed
/// resource inside the transformed assembly, and deserialized at runtime.
/// </summary>
/// <param name="method">Method to which the current aspect instance
/// has been applied.</param>
/// <param name="aspectInfo">Unused.</param>
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
{
this.methodName = method.Name;
this.className = method.DeclaringType.FullName;
this.declaringType = method.DeclaringType;
}
/// <summary>
/// Method invoked before the execution of the method to which the current
/// aspect is applied.
/// </summary>
/// <param name="args">Information about the method being executed.</param>
public override void OnEntry(MethodExecutionArgs args)
{
//log.Debug(this.className + "." + this.methodName + ": Enter");
}
/// <summary>
/// Method invoked after successfull execution of the method to which the current
/// aspect is applied.
/// </summary>
/// <param name="args">Information about the method being executed.</param>
public override void OnSuccess(MethodExecutionArgs args)
{
//log.Debug(this.className + "." + this.methodName + ": Success");
}
/// <summary>
/// Method invoked after failure of the method to which the current
/// aspect is applied.
/// </summary>
/// <param name="args">Information about the method being executed.</param>
public override void OnException(MethodExecutionArgs args)
{
//log.Error(this.className + "." + this.methodName + ": Exception " + args.Exception.Message);
}
}
这是否意味着我需要联系共享主机提供商以更改应用程序的信任级别?我希望有解决此问题的方法?您的错误消息显示
SecurityException
源于BinarySpectSerializer
。这是用于序列化方面的默认类,您可以使用[Serializable]
属性对其进行标记
这里最好的解决方案是就这个问题联系您的主机提供商,正如前面提到的
作为一种解决方法,您可以尝试为您的方面使用另一个序列化程序
如果将属性改为应用于方面,则将使用,并且不需要完全信任
[PSerializable]
public class LoggingAspect : OnMethodBoundaryAspect
您还可以完全避免序列化,但这意味着不使用CompileTimeInitialize
方法,并在应用程序运行时执行所有方面的初始化,可能会损失一些性能
在这种情况下,您应该在方面的RuntimeInitialize
方法中使用和初始化方面。这里记录了这一点:
错误消息显示
SecurityException
源于BinarySpectSerializer
。这是用于序列化方面的默认类,您可以使用[Serializable]
属性对其进行标记
这里最好的解决方案是就这个问题联系您的主机提供商,正如前面提到的
作为一种解决方法,您可以尝试为您的方面使用另一个序列化程序
如果将属性改为应用于方面,则将使用,并且不需要完全信任
[PSerializable]
public class LoggingAspect : OnMethodBoundaryAspect
您还可以完全避免序列化,但这意味着不使用CompileTimeInitialize
方法,并在应用程序运行时执行所有方面的初始化,可能会损失一些性能
在这种情况下,您应该在方面的RuntimeInitialize
方法中使用和初始化方面。这里记录了这一点:
托管提供商设置了一项策略,限制某些功能的使用,这显然是PostSharp需要的。您需要联系您的主机提供商。如果主机提供商不想更改,是否有解决办法,或者我是否坚持使用主机提供商策略?主机提供商已设置策略限制某些功能的使用,这显然是PostSharp需要的。您需要联系您的主机提供商。如果他们不想更改,是否有解决方法,或者我是否坚持主机提供商策略?非常感谢Alex,我刚刚尝试了
MsilAspectSerializer
,它可以在我的共享主机上工作,而无需请求提供商更改其服务器策略。非常感谢Alex,我刚刚尝试了MsilAspectSerializer
,它可以在我的共享主机上工作,而无需请求提供商更改其服务器策略。
[OnMethodBoundaryAspectConfiguration(SerializerType=typeof(MsilAspectSerializer))]
public class LoggingAspect : OnMethodBoundaryAspect