【问题标题】:What do I do when my ASP.Net website is not allowed to perform some operations defined by the security policy of my web hosting service?当我的 ASP.Net 网站不允许执行我的虚拟主机服务的安全策略定义的某些操作时,我该怎么办?
【发布时间】:2014-03-10 13:57:22
【问题描述】:

我用 C# 编码的 asp.net 站点在我的本地系统上运行良好,但是当我通过 plesk 将文件上传到 httpdocs 文件夹时,我收到以下错误:

Server Error in '/' Application.
________________________________________
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0246: The type or namespace name 'Xyz' could not be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 1:  <%@ Application Language="C#" %>
Line 2:  <%@ Import Namespace="xyz" %>
Line 3:  <%@ Import Namespace="System.Web.Optimization" %>
Line 4:  <%@ Import Namespace="System.Web.Routing" %>

Source File: g:\PleskVhosts\xyz.com\httpdocs\Xyz\Global.asax    Line: 2 

Show Detailed Compiler Output:


C:\Windows\SysWOW64\inetsrv> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /out:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\ba70df64\8ad7fdd9\App_global.asax.8gpjfmvi.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699;1701;612;618 /warnaserror-  "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\ba70df64\8ad7fdd9\App_global.asax.8gpjfmvi.0.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\ba70df64\8ad7fdd9\App_global.asax.8gpjfmvi.1.cs"


Microsoft (R) Visual C# Compiler version 4.0.30319.17929

for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

g:\PleskVhosts\xyz.com\httpdocs\Xyz\Global.asax(2,11): error CS0246: The type or namespace name 'Xyz' could not be found (are you missing a using directive or an assembly reference?)
g:\PleskVhosts\xyz.com\httpdocs\Xyz\Global.asax(3,22): error CS0234: The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
g:\PleskVhosts\xyz.com\httpdocs\Xyz\Web.config(24,21): error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)


________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18056

任何帮助都会很棒。

## 新错误

****“/”应用程序中的服务器错误。

Security Exception

Description: 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. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Delegate.DelegateConstruct(Object target, IntPtr slot) +0
   Owin.Loader.DefaultLoader..ctor(Func`3 next, Func`2 activator, IEnumerable`1 referencedAssemblies) +69
   Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +65
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18056****

【问题讨论】:

  • GoDaddy 没什么不好 - “在我的机器上工作”是 prgorammers 不考虑需要什么的已知问题。那么,命名空间 Xyz 包含什么?你引用它,所以 - 它必须在那里。
  • 你上传了所有的文件和文件夹吗?
  • 当我创建项目时,所有文件都保存在 C:\User\Mydocuments\VisualStudio2013\Websites\xyz\ 中。
  • 我在 Projects 文件夹中添加了除解决方案文件之外的所有文件和文件夹。
  • 我投票决定将此问题作为题外话结束,因为这应该直接提交给 Godaddy 客户支持

标签: c# asp.net


【解决方案1】:

您需要右键单击您的项目,然后选择“发布”。您可以发布到文件系统,以便在将 Web.config 上传到 godaddy 之前更改它,或者您可以将其设置为发布到 godaddy 站点。我会选择文件系统方法。一步一个脚印。

正如您在 cmets 中所说,“我在 Projects 文件夹中添加了除解决方案文件之外的所有文件和文件夹”,这没有任何作用。要从中执行,它需要在 Visual Studio IDE 中运行。要正确设置所有文件应该用于生产用途的位置,您必须发布您的 Web 项目。

【讨论】:

  • 嗨,非常感谢,我这样做了,但我收到了一个错误,在我看来,必须对 web.config 文件进行一些更改。此外,我将设置更改为 ASP.net 版本 4(我的网站内置于 .net 4.5),因为 4.5 不可用,将语言更改为 C3(我的编码是 C#)身份验证设置为无,自定义错误设置为关闭。错误是这个
  • 错误是今天添加到原始帖子中的错误(在新错误行之后)非常感谢您帮助我
  • 我不确定抛出的异常是指什么。也许尝试连接到您的数据存储,也许不是。但是,由于这是一个与您仅复制项目文件结构而不是发布的原始问题无关的错误,因此这个新的错误消息实际上应该是它自己的问题。不过,在您发布之前,我会尝试添加一些异常捕获,看看您是否可以找到它发生的位置,以便人们有更好的机会帮助您。
【解决方案2】:

遇到同样的问题,可以使用web.config 修复错误。将level="Full" 级别添加到trust 元素中,如下所示:

<system.web>
   ...
   <trust level="Full" />
   ...
</system.web>

【讨论】:

    【解决方案3】:

    您发布的新错误肯定与安全有关。 转到网站和域选项卡。在您帐户的主域下,单击“ASP.NET 设置”图标。页面加载时,您应该能够在“代码访问安全性”下将权限设置为完全。试一试,让我们知道这是否有效

    【讨论】:

      【解决方案4】:

      除了之前的 cmets,我注意到 GoDaddy 同时具有 MVC 和 WebForms 应用程序的一件事是 GoDaddy 讨厌 Roslyn。这是来自 Visual Studio 的新应用程序的默认编译器。除了将您的 CAS 设置为完全访问权限之外,请确保您从项目中删除 Microsoft.Net.Compilers 包及其依赖项,在发布之前删除所有现有文件(使用发布设置中的复选框 - 实际上不要从您的帐户!),你应该很高兴。每次 GoDaddy 从 Visual Studio 发布应用程序时,我都会遇到这个问题。

      祝所有找到这个的人好运!

      【讨论】:

        【解决方案5】:

        要解决 GoDaddy 的安全/权限问题,请登录您的 GoDaddy Windows Plesk 帐户并展开“虚拟主机”选项卡。然后,单击“启动”按钮访问“网站与域”控制面板。从那里找到您当前正在处理的网站、域或子域。单击“ASP.NET 设置”按钮,将“CAS 信任级别”调整为“完整”,将“默认网页语言”调整为“C#”。您还可以在此处输入并保存您的连接字符串、身份验证模式(通常是表单)、ASP.NET 版本等。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-05-27
          • 1970-01-01
          • 2021-04-09
          • 1970-01-01
          • 2021-01-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多