Saa*_*ail 10 asp.net asp.net-mvc log4net securityexception shared-hosting
我已经编写了3个ASP.net MVC Web应用程序,并且所有这些应用程序都部署在我的ISP的共享主机服务器上.
所有3个应用程序在配置和设置方面都非常相似.第一个应用程序部署到与第二个和第三个不同的服务器.第一个应用程序没有给我任何错误.
第二个和第三个应用程序稍微吐出以下SecurityException :随机:
替代文字http://i46.tinypic.com/24p9pac.jpg
例外文字:
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.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +58
System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca) +99
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Run Code Online (Sandbox Code Playgroud)
我在部署或编辑web.config后第一次点击页面时收到上述错误.但是,在后续页面重新加载时,我没有得到它.这两个网站将在一天的剩余时间再次罚款,但第二天早上我再次得到同样的错误.
编辑web.config后,错误确实出现,我假设是强制重新编译?
请帮忙.我不确定问题是什么.听起来它与IIS中的安全设置有关.所有3个Web应用程序都以非常类似的方式进行设置和部署,除了第一个不提供错误的Web应用程序位于完全不同的服务器上.
Saa*_*ail 20
事实证明,上述SecurityException的原因是3倍
我的ISP将ASP.net配置为在其较新的服务器上以中等信任模式运行,并在其较旧的服务器上运行完全信任模式.我的Web应用程序在这两个服务器之间分开,这就是为什么我在应用程序之间获得不同的行为,即使它们配置完全相同
我使用log4net进行错误记录,在我的Global.asax文件中,我有以下内容:
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
log4net.Config.XmlConfigurator.Configure();
log.Debug("Logging Initialized.");
}
Run Code Online (Sandbox Code Playgroud)
这一行 - log4net.Config.XmlConfigurator.Configure();是抛出上述异常的原因.它只在应用程序启动时发生一次,或者如果修改了web.config则重新启动.这就是为什么我无法弄清楚问题的来源.
我不得不在web.config中的log4net configSection中添加一个requirePermission ="false":
<section name="log4net" requirePermission="false" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
Run Code Online (Sandbox Code Playgroud)现在如果我在中等信任模式下开发,我会选择这些问题.您可以通过将以下内容添加到我的web.config来强制您的应用以中等信任模式运行:
<system.web>
<trust level="Medium"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
通过强制我的应用程序在中等信任模式下运行,我在开发中确切地选择了源异常,并从那里找出了什么错误.
| 归档时间: |
|
| 查看次数: |
6959 次 |
| 最近记录: |