Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/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
共享主机上OpenWebConfiguration的ASP.NET安全异常_Asp.net_Security_Iis_Web Config - Fatal编程技术网

共享主机上OpenWebConfiguration的ASP.NET安全异常

共享主机上OpenWebConfiguration的ASP.NET安全异常,asp.net,security,iis,web-config,Asp.net,Security,Iis,Web Config,将网站从本地开发环境移动到共享主机后,我得到: 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

将网站从本地开发环境移动到共享主机后,我得到:

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.
问题发生在我的web应用程序中的任何地方,称为:

WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
由于我的web应用程序只是试图打开自己的web.config文件,我不知道为什么会将其标记为安全异常。也许有人能解释。。。但更重要的是,我需要一个解决方案,我通过谷歌找到的两个解决方案是痛苦的

许多帖子中的一个解决方案说可以将信任级别配置为完全信任,但我被告知这在我的共享主机上是不可能的

来自的另一个解决方案表示不使用OpenWebConfiguration,但我需要使用它来加密配置部分,例如使用DPAPI的连接字符串。有关更多信息,请参阅


请说明为什么IIS会在我的web应用程序上尝试打开自己的web.config,以及如何使用DPAPI对web.config的部分内容进行加密。

我过去曾遇到过这个问题。OpenWebConfiguration方法还读取machine.config文件。在部分信任下,如果没有正确的权限,则无法使用此方法

如果要在Visual Studio 2008/2010中使用调试器进入.NET Framework程序集,则可以确切地看到正在发生的情况

以下是在进入WebConfiguration Manager.OpenWebConfiguration时捕获的调用堆栈:

不幸的是,您唯一的选择是使用WebConfiguration Manager.GetSection,它的功能并不丰富


关于加密连接字符串。遗憾的是,这项功能需要完全信任,没有其他办法可以绕过它。

我过去曾遇到过这个问题。OpenWebConfiguration方法还读取machine.config文件。在部分信任下,如果没有正确的权限,则无法使用此方法

如果要在Visual Studio 2008/2010中使用调试器进入.NET Framework程序集,则可以确切地看到正在发生的情况

以下是在进入WebConfiguration Manager.OpenWebConfiguration时捕获的调用堆栈:

不幸的是,您唯一的选择是使用WebConfiguration Manager.GetSection,它的功能并不丰富


关于加密连接字符串。遗憾的是,这项功能需要完全信任,没有其他解决办法。

我刚刚发现一个旧的堆栈溢出帖子>,它表明DPAPI需要完全信任,这对于使用机器级密钥是有意义的。但是,我仍然希望能够在我自己的web.config per Request.ApplicationPath上使用OpenWebConfiguration,以便轻松访问appSettings部分。这真的需要完全信任吗?我刚刚发现一个旧的堆栈溢出POST>,它表明DPAPI需要完全信任,这对于使用机器级密钥很有意义。但是,我仍然希望能够在我自己的web.config per Request.ApplicationPath上使用OpenWebConfiguration,以便轻松访问appSettings部分。这真的需要完全信任吗?我还可以使用ConfigurationManager.AppSettings.Getkeyname,这样我就可以用最少的工作量获得应用程序设置。我还可以使用ConfigurationManager.AppSettings.Getkeyname,这样我就可以用最少的工作量获得应用程序设置。 mscorlib.dll!System.IO.FileStream.Init(string path = "C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\Config\\machine.config", System.IO.FileMode mode = Open, System.IO.FileAccess access = Read, int rights = 0, bool useRights = false, System.IO.FileShare share = Read, int bufferSize = 4096, System.IO.FileOptions options = None, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs = null, string msgPath = "machine.config", bool bFromProxy = false) Line 326 C# mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) Line 259 C# System.Configuration.dll!System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(string streamName) + 0x56 bytes System.Configuration.dll!System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(string streamName, bool assertPermissions) + 0x7d bytes System.Configuration.dll!System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(string streamName) + 0xb bytes System.Configuration.dll!System.Configuration.Internal.DelegatingConfigHost.OpenStreamForRead(string streamName) + 0xe bytes System.Configuration.dll!System.Configuration.UpdateConfigHost.OpenStreamForRead(string streamName) + 0x2f bytes System.Configuration.dll!System.Configuration.BaseConfigurationRecord.InitConfigFromFile() + 0x126 bytes System.Configuration.dll!System.Configuration.BaseConfigurationRecord.Init(System.Configuration.Internal.IInternalConfigRoot configRoot, System.Configuration.BaseConfigurationRecord parent, string configPath, string locationSubPath) + 0xaa5 bytes System.Configuration.dll!System.Configuration.MgmtConfigurationRecord.Init(System.Configuration.Internal.IInternalConfigRoot configRoot, System.Configuration.Internal.IInternalConfigRecord parent, string configPath, string locationSubPath) + 0x39 bytes System.Configuration.dll!System.Configuration.MgmtConfigurationRecord.Create(System.Configuration.Internal.IInternalConfigRoot configRoot, System.Configuration.Internal.IInternalConfigRecord parent, string configPath, string locationSubPath) + 0x2a bytes System.Configuration.dll!System.Configuration.Internal.InternalConfigRoot.GetConfigRecord(string configPath) + 0x12d bytes System.Configuration.dll!System.Configuration.Configuration.Configuration(string locationSubPath, System.Type typeConfigHost, object[] hostInitConfigurationParams) + 0xfd bytes System.Configuration.dll!System.Configuration.Internal.InternalConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(System.Type typeConfigHost, object[] hostInitConfigurationParams) + 0x1e bytes System.Web.dll!System.Web.Configuration.WebConfigurationHost.OpenConfiguration(System.Web.Configuration.WebLevel webLevel, System.Configuration.ConfigurationFileMap fileMap, System.Web.VirtualPath path, string site, string locationSubPath, string server, string userName, string password, System.IntPtr tokenHandle) Line 862 C# System.Web.dll!System.Web.Configuration.WebConfigurationManager.OpenWebConfigurationImpl(System.Web.Configuration.WebLevel webLevel, System.Configuration.ConfigurationFileMap fileMap, string path, string site, string locationSubPath, string server, string userName, string password, System.IntPtr userToken) Line 77 + 0x1c bytes C# System.Web.dll!System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(string path) Line 140 + 0x25 bytes C#