asp.net site throwing a System.Security.SecurityException

微笑、不失礼 提交于 2019-12-11 20:38:57

问题


I have an ASP.NET application that was working fine on my server up until last night when I installed a bunch of windows updates, now it's throwing this exception :

System.Security.SecurityException: Requested registry access is not allowed.

Unfortunately there is some things that makes this hard to debug. I added the debug="true" attribute to the web.config file to get the line where the exception is lauched. The line identified in my code is an End If and the code just before seems benign :

<body id="body" runat="server">
   <div class="conteneur-confirmation">
      <%
         If Not Session("confirmation") Is Nothing Then
            Response.Write("<ul><li>" & Session("confirmation") & "</li></ul>")
            Session.Remove("confirmation")
         End If
      %>
   </div>
   <div class="conteneur-alerte">
      <%
         If Not Session("Alerte") Is Nothing Then
            Response.Write("<ul><li>" & Session("Alerte") & "</li></ul>")
            Session.Remove("Alerte")
         End If <!-- The exception is supposedly launch from here -->
      %>
<!-- more code -->

The next thing I tough could help me is the stack trace. Here it is :

[SecurityException: Accès au registre demandé non autorisé.]
   System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) +52
   Microsoft.Win32.RegistryKey.InternalOpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, Int32 rights) +9434757
   Microsoft.Win32.RegistryKey.OpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights) +15
   System.TimeZoneInfo.TryCompareTimeZoneInformationToRegistry(TimeZoneInformation timeZone, String id, Boolean& dstDisabled) +234
   System.TimeZoneInfo.FindIdFromTimeZoneInformation(TimeZoneInformation timeZone, Boolean& dstDisabled) +258
   System.TimeZoneInfo.GetLocalTimeZone() +307
   System.TimeZoneInfo.get_Local() +116
   System.DateTime.ToLocalTime() +60
   System.IO.File.GetLastWriteTime(String path) +34
   System.Web.Handlers.AssemblyResourceLoader.GetAssemblyInfoWithAssertInternal(Assembly assembly) +93
   System.Web.Handlers.AssemblyResourceLoader.GetAssemblyInfo(Assembly assembly) +67
   System.Web.Handlers.AssemblyResourceLoader.GetWebResourceUrlInternal(Assembly assembly, String resourceName, Boolean htmlEncoded, Boolean forSubstitution, IScriptManager scriptManager) +1159
   System.Web.Handlers.AssemblyResourceLoader.GetWebResourceUrl(Type type, String resourceName, Boolean htmlEncoded, IScriptManager scriptManager) +722
   System.Web.UI.ClientScriptManager.GetWebResourceUrl(Page owner, Type type, String resourceName, Boolean htmlEncoded, IScriptManager scriptManager) +167
   System.Web.UI.ClientScriptManager.RenderWebFormsScript(HtmlTextWriter writer) +158
   System.Web.UI.Page.RenderWebFormsScript(HtmlTextWriter writer) +58
   System.Web.UI.Page.BeginFormRender(HtmlTextWriter writer, String formUniqueID) +8910479
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +57
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
   ASP.masters_sigiweb2_master.__Renderbody(HtmlTextWriter __w, Control parameterContainer) in C:\Inetpub\v3\Masters\sigiweb2.master:96
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
   System.Web.UI.Page.ProcessRequest() +78
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.default_aspx.ProcessRequest(HttpContext context) +37
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

It looks like the exception is launch when System.TimeZoneInfo.TryCompareTimeZoneInformationToRegistry try to access the registry and the asp.net identity, IWAM_MACHINENAME, doesn't have the rights. I suppose, one of the Windows update changed the right to some registry keys or the behavior of this function. I did a search on the web for "TryCompareTimeZoneInformationToRegistry" thinking I would find someone else who would have had the same error as me. However Google only return two pages with reference to this function and they're both in Italian.

I guess the solution will be to simply change the access rights to some part of the registry, but I don't know which and it seems there is virtually no informations about this function on the web (weird, no?).

I'd like to add that my server is French version of Windows Server 2003. That and the fact that the only other information I found about it on the Internet is in Italian let me think it may be a problem that would not occur on the English version of Windows, but I can't confirm this.

Thanks for your help.


回答1:


The registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TimeZones\Bangladesh Standard Time had their permissions set wrong (probably a problem cause by the Windows Update I had just done). I simply copied the permission from another Time Zone Key, that is all right to everyone, and the problem went away.

Now, I hope Google will send people with this problem over here. It was kind of weird to find almost no information about the TryCompareTimeZoneInformationToRegistry function on the web.




回答2:


The page says that the problem is caused by antivirus software blocking access to the registry. That sounds like a reasonable place to start.



来源:https://stackoverflow.com/questions/4692644/asp-net-site-throwing-a-system-security-securityexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!