本文介绍了没有找到的App_Data访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整理我的web项目并增加了一个小错误日志功能。它在App_Data文件夹一个过时的文件中写入异常的详细信息。

I am finishing my web project and have added a little error log feature. It writes details of exceptions in a dated file in the App_Data folder.

当我这样做,我的开发机上,它的工作原理。但是,当我切换到我的IIS的机器,它停止工作,我得到一个UnauthorizedAccessException。

When I do this on my development machine, it works. But when I switch over to my IIS machine, it stops working and I get a UnauthorizedAccessException.

堆栈跟踪:

[UnauthorizedAccessException: Der Zugriff auf den Pfad "c:\inetpub\wwwroot\App_Data\Error_Logs\" wurde verweigert.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +9726526
   System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj) +9431442
   System.IO.Directory.CreateDirectory(String path) +146
   WerIstWo.Logger.writeToLog(String text) in c:\Users\Teichler\Dropbox\Praktikum\IHK-Projekt\WerIstWo\WerIstWo\Logger.cs:18
   WerIstWo.NeuerBenutzer.btnSpeichern_Click(Object sender, EventArgs e) in c:\Users\Teichler\Dropbox\Praktikum\IHK-Projekt\WerIstWo\WerIstWo\NeuerBenutzer.aspx.cs:325
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

code:

        public static void writeToLog( string text )
        {
            string date = DateTime.Today.ToShortDateString().ToString();
            string path = AppDomain.CurrentDomain.GetData( "DataDirectory" ).ToString() + "\\Error_Logs\\";

            if (!Directory.Exists( path ))
            {
                Directory.CreateDirectory( path );
            }

            string fullPath = path + date + ".txt";

            if (!File.Exists( path + date ))
            {
                File.Create( fullPath ).Close();
            }

            using (StreamWriter writer = new StreamWriter( fullPath, true ))
            {
                writer.Write( text );
            }
        }

在错误的详细信息,它告诉我,我需要为IUSR_计算机设置权限在此文件夹,但我不知道这是否是一个好主意,或者如何做,在IIS 5.1(这我使用)。

In the error details, it tells me that I need to set permission for IUSR_MachineName to this folder but I'm not sure if this is a good idea or how to do it in IIS 5.1 (which I am using).

推荐答案

这的确是你需要做什么。在开发计算机上的IIS(或IIS前preSS)的可执行文件有你的的App_Data 目录的写权限。在一个生产机器,你平时不默认。只有一个解决办法,那就是授予对目录中的 IUSR_计算机用户写入权限。没有什么根本性的错误是,只要你知道,这意味着在相同的IIS实例中运行潜在的其他网站也可能写入该目录。

That is indeed what you need to do. On your development machine, the IIS (or IIS express) executable has write permissions for your App_Data directory. On a production machine, you usually don't by default. There is only one solution and that is to grant the IUSR_MachineName user write permission on the directory. There is nothing fundamentally wrong with that, as long as you are aware that this means that other websites running in the same IIS instance potentially could also write to that directory.

这篇关于没有找到的App_Data访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:06