"The application attempted to perform an operation not allowed by the security policy." 可能存在信任问题?

"The application attempted to perform an operation not allowed by the security policy." Possible trust issue?

完整消息是

The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

我最近将 MVC 应用程序上传到 Fasthosts 托管站点。

应用程序在本地 VS 中运行良好,但在服务器上运行不正常。

它最初给出了有关启用远程错误消息的消息,因此我将 <customErrors mode="Off" /> 添加到最初停止此操作的配置文件中。

然后我看到了上面的错误消息,所以在谷歌搜索后我将 <trust level="Full" /> 添加到 <system.web> 但我收到另一条消息说主机已禁用此功能。

事实是,这个应用程序没有任何异常;它只是一个非常基本的 MVC 应用程序。它不使用当前文件夹结构以外的任何其他位置的资源,因此实际上不应该有任何信任问题。

这个问题也被夸大了,因为似乎存在某种服务器端缓存问题。

<system.web> 部分当前如下所示:

  <system.web>
    <customErrors mode="Off" />
    <trust level="Medium" />
    <compilation targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" />
  </system.web>

但它仍然说我需要添加 customErrors mode="Off" 才能看到错误消息。

在配置文件的不同位置添加不同的行最终会 return 它出现在第一条错误消息中,但不是出于我能看到的任何合乎逻辑的原因。

为了完整起见,控制器操作如下所示:

public ActionResult Index(int vehicleId = 0)
{
    ViewBag.VehicleId = vehicleId;
    return View();
}

视图只是 HTML 的一个 shedload,带有一些辅助方法,其中之一如下(其他只是不同的实体,否则代码相同):

public static MvcHtmlString Manufacturers(string id = "manufacturers", string className = "", string style = "", string optionClass = "", string optionStyle = "", int selectedValue = 0, bool showSelect = false)
{
    var result = new StringBuilder();
    try
    {
        using (var context = new DB())
        {
            var selected = selectedValue == 0 ? " selected" : "";
            result.Append($"<select id='{id}' class='{className}' style='{style}'>");
            if (showSelect) result.Append($"<option{selected} value='0' disabled='disabled'>(Select)</option>");
            foreach (var manufacturer in context.Manufacturers)
            {
                selected = manufacturer.ManufacturerId == selectedValue ? " selected" : "";
                result.Append($"<option{selected} value='{manufacturer.ManufacturerId}' class='{optionClass}' style='{optionStyle}'>{manufacturer.Name}</option>");
            }
            result.Append("</select>");
        }
    }
    catch (Exception ex)
    {
        result = new StringBuilder(ex.GetBaseException().Message);
    }
    return new MvcHtmlString(result.ToString());
}

我有一张 Fasthosts 的公开支持票,但我不确定它会很快得到答复:(

原来是主机服务器,后来他们说一定是我的代码。

我找到了另一个供应商,上传了我的代码,第一次一切正常。

有时候不是你,是他们。