我正试图将农场解决方案搬到一个沙箱,我无法弄清楚如何搬出这段代码:

[ToolboxItem(false)]
public partial class vClockPartSB : System.Web.UI.WebControls.WebParts.WebPart
{
    [Personalizable(PersonalizationScope.User)]
    public Collection<String> ClockTimeZones { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public int NumberOfClocks { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlMain { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubOne { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubTwo { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubThree { get; set; }
    [Personalizable(PersonalizationScope.User)]
    public string DdlSubFour { get; set; }



    protected override void OnInit(EventArgs e)
    {
        ClockTimeZones = new Collection<string>();
        base.OnInit(e);
        InitializeControl();
    }
.

我收到以下错误:

web部件错误:沙盒代码抛出未处理的异常 包装器在Partial Trust App域中的执行方法:Web部件 属性'clockTimeZones'使用不受支持的类型 (system.collections.ObjectModel.collection`1 [[system.string,mscorlib, 版本= 2.0.0.0,文化=中性,PublicKeyToken= B77A5C561934E089]]), 并且不能作为沙箱代码网部分运行。

我该如何接近它?

有帮助吗?

解决方案

我将被诱惑只是为了存储一个字符串 - 而不是集合 - 并执行自己的序列化/解序列化。可能使用string.split()函数和合适的分隔符。

其他提示

在沙箱中不允许使用System.Collections.ObjectModel命名空间。

对于您的场景,您可以使用 list 相反?

显然,仅支持以下类型作为沙箱解决方案中的网页的属性:
  • 字符串
  • Bool
  • enum
  • int
  • Guid
  • Uri
  • 字节
  • char
  • long
  • 浮子
  • 十进制
  • Double

    这里是alan dahl的博客文章其中Alan Dahls'Log的搜索。

许可以下: CC-BY-SA归因
scroll top