我在做ASP.NET发布的时候出现了以下的问题。
因为要读取服务器端的数据库,而且数据库是随机配置的。配置信息存放在一个名字叫RGsys.ini的文件中。
这个配置文件和代码是放在一起的。读取配置用的是classIniFile.cs
相关代码:
  IniFiles SysIni = new IniFiles("RGsys");
  SysIni.FileName = "c:\\RGsys.ini";
  MainVariable.h_DataSourse = SysIni.ReadString("SYS", "Data Source", "");
  MainVariable.h_Database = SysIni.ReadString("SYS", "Initial Catalog", "");
  MainVariable.h_DBmanager = SysIni.ReadString("SYS", "User ID", "");
  MainVariable.h_DBmanagerpwd = SysIni.ReadString("SYS", "Password", "");
我在发布的时候出现了以下的问题“/ceshi”应用程序中的服务器错误。
--------------------------------------------------------------------------------对路径“C:\WINDOWS\system32\RGsys”的访问被拒绝。  
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。  异常详细信息: System.UnauthorizedAccessException: 对路径“C:\WINDOWS\system32\RGsys”的访问被拒绝。  ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}\ASPNET,在 IIS 6 上为网络服务)。如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。  要将 ASP.NET 访问权限授予某个文件,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。源错误:  
行 27:       { //|| (FileAttributes.Directory in fileInfo.Attributes))
行 28:         //文件不存在,建立文件
行 29:         System.IO.StreamWriter sw = new System.IO.StreamWriter(AFileName, false, System.Text.Encoding.Default);
行 30:         try
行 31:         {
 源文件: e:\c#\c#实验程序\发布带INI\App_Code\classIniFile.cs 行: 29  堆栈跟踪:  
[UnauthorizedAccessException: 对路径“C:\WINDOWS\system32\RGsys”的访问被拒绝。]
  System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7714255
  System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
  System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) +65
  System.IO.StreamWriter.CreateFile(String path, Boolean append) +62
  System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) +58
  System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) +29
  IniFiles..ctor(String AFileName) in e:\c#\c#实验程序\发布带INI\App_Code\classIniFile.cs:29
  _Default.Page_Load(Object sender, EventArgs e) in e:\c#\c#实验程序\发布带INI\Default.aspx.cs:18
  System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
  System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
  System.Web.UI.Control.OnLoad(EventArgs e) +99
  System.Web.UI.Control.LoadRecursive() +50
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627