Access Denied

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpajoe2001
    New Member
    • Jan 2007
    • 9

    #1

    Access Denied

    I am having an issue and after searching around online for a day and half now and finding others with the same problem but yet no solution to my issue I am looking for help.

    What i have is ServerA which is a webserver running Win2k3 with IIS6, my domain account is a local administrator on this machine. The web app I am running is trying to write a file to ServerB which is also a Win2k3 machine. On the folder of the machine I am writing to I have NTFS Full control permissions to both me and the domain account that the IIS App Pool is running as. The IIS App Pool isn't running as Network Services but as a domain account that has administrative rights on ServerA and Full Control on the folder on Server B.

    Some background on the webApp, it is a ASP.net 2.0 web page using C#. I have a onclick event that calls a Class passing a String[] Servers and a string Event.
    Code:
    public string WriteServersToTextFiles(string [] theServerNames, string theServerProdGroup)
    
    {
    
    //String for the location of the server.txt file
    
    string thePath = "";
    
    int i;
    
    //Pass the patch group into the path
    
    thePath = @"\\ServerB\TEST\" + theServerProdGroup + @"\servers.txt";
    
    //Check to see if file already exists. If so, call function that makes a backup copy and renames it.
    
    if (File.Exists(thePath))
    
    {
    
    changeFileName(theServerProdGroup);
    
    }
    
    
    // create a writer and open the file
    
    TextWriter tw = new StreamWriter(thePath);
    
    // Write server names to the file
    
    for (i = 0; i < theServerNames.Length; i++)
    
    {
    
    tw.WriteLine(theServerNames[i].ToString());
    
    }
    
    
    // close the stream
    
    tw.Close();
    
    //Call method, and return a string which confirms file was written successfully, or returns an error stating otherwise
    
    return confirmTextFilesWereWritten(theServerNames, theServerProdGroup); 
    
    private void changeFileName(string theServerProdGroup)
    
    {
    
    //Create DateTime object that stores current date and time
    
    DateTime currentDate = DateTime.Now;
    
    //http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx
    
    string newFileName = currentDate.ToString("yyyyMMddHHmmss") + "_servers.txt";
    
    //Change file name
    
    File.Move(@"\\ServerB\TEST\" + theServerProdGroup + 
    
    @"\servers.txt", @"\\ServerB\TEST\" + theServerProdGroup + @"\" + newFileName);
    
    }
    
    }
    When I run this WebApp as Localhost from ServerA everything works like it should and is great, however when I run the WebApp from my WinXP machine and I click the button to generate the text files I get prompted to login to ServerA even though the file is being wrote to ServerB. In my web.config I do have impersonate set to true as I need to for security reasons. No matter what account I try to use I get the following error.

    Access to the path '\\ServerB\TEST \Dev2_2000-0400\servers.tx t' is denied.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Unauthor izedAccessExcep tion: Access to the path '\\ServerB\TEST \Dev2_2000-0400\servers.tx t' is denied.

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNE T on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="tr ue"/>, the identity will be the anonymous user (typically IUSR_MACHINENAM E) or the authenticated request user.

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties " and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

    Source Error:

    Line 72:
    Line 73: // create a writer and open the file
    Line 74: TextWriter tw = new StreamWriter(th ePath);
    Line 75:
    Line 76: // Write server names to the file


    Source File: c:\Inetpub\wwwr oot\WSIHarveste r\App_Code\Serv ersTextFileWrit er.cs Line: 74

    Stack Trace:

    [UnauthorizedAcc essException: Access to the path '\\ServerB\TEST \Dev2_2000-0400\servers.tx t' is denied.]
    System.IO.__Err or.WinIOError(I nt32 errorCode, String maybeFullPath) +2013027
    System.IO.FileS tream.Init(Stri ng path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIB UTES secAttrs, String msgPath, Boolean bFromProxy) +998
    System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) +115
    System.IO.Strea mWriter.CreateF ile(String path, Boolean append) +58
    System.IO.Strea mWriter..ctor(S tring path, Boolean append, Encoding encoding, Int32 bufferSize) +91
    System.IO.Strea mWriter..ctor(S tring path) +27
    ServersTextFile Writer.WriteSer versToTextFiles (String[] theServerNames, String theServerProdGr oup) in c:\Inetpub\wwwr oot\WSIHarveste r\App_Code\Serv ersTextFileWrit er.cs:74
    Generate_Patch_ Group_Text_File s.getPatchGroup s_Click(Object sender, EventArgs e) in c:\Inetpub\wwwr oot\WSIHarveste r\Generate_Patc h_Group_Text_Fi les.aspx.cs:72
    System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +105
    System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String eventArgument) +107
    System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +7
    System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
    System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +5102

    Version Information: Microsoft .NET Framework Version:2.0.507 27.42; ASP.NET Version:2.0.507 27.42
    When this happens the event log for ServerA has a Application Event of

    Event Type: Information
    Event Source: ASP.NET 2.0.50727.0
    Event Category: Web Event
    Event ID: 1314
    Date: 1/11/2007
    Time: 8:38:39 AM
    User: N/A
    Computer: ServerA
    Description:
    Event code: 4011
    Event message: An unhandled access exception has occurred.
    Event time: 1/11/2007 8:38:39 AM
    Event time (UTC): 1/11/2007 1:38:39 PM
    Event ID: 1313c5a9caa548e 0a681ca9502a48d 28
    Event sequence: 136
    Event occurrence: 1
    Event detail code: 0

    Application information:
    Application domain: /LM/W3SVC/1/Root/WSIHarvester-1-128129961851916 396
    Trust level: Full
    Application Virtual Path: /WSIHarvester
    Application Path: C:\Inetpub\wwwr oot\WSIHarveste r\
    Machine name: ServerA

    Process information:
    Process ID: 2576
    Process name: w3wp.exe
    Account name: Domain\ASPuserA ccount

    Request information:
    Request URL: http://ServerA/WSIHarvester/SchemeCurrent.a spx
    Request path: /WSIHarvester/SchemeCurrent.a spx
    User host address: 192.168.14.96
    User: Domain\MyUserNa me
    Is authenticated: True
    Authentication Type: Negotiate
    Thread account name: Domain\ASPuserA ccountASPuserAc count

    Custom event details:

    For more information, see Help and Support Center at http://go.microsoft.co m/fwlink/events.asp.
    And Also Security Events of

    Event Type: Success Audit
    Event Source: Security
    Event Category: Logon/Logoff
    Event ID: 576
    Date: 1/11/2007
    Time: 8:38:42 AM
    User: Domain\MyUserNa me
    Computer: ServerA
    Description:
    Special privileges assigned to new logon:
    User Name: MyUserName
    Domain: Domain
    Logon ID: (0x0,0xE5170)
    Privileges: SeSecurityPrivi lege
    SeBackupPrivile ge
    SeRestorePrivil ege
    SeTakeOwnership Privilege
    SeDebugPrivileg e
    SeSystemEnviron mentPrivilege
    SeLoadDriverPri vilege
    SeImpersonatePr ivilege

    For more information, see Help and Support Center at http://go.microsoft.co m/fwlink/events.asp.
    Event Type: Success Audit
    Event Source: Security
    Event Category: Logon/Logoff
    Event ID: 540
    Date: 1/11/2007
    Time: 8:38:42 AM
    User: Domain\MyUserNa me
    Computer: ServerA
    Description:
    Successful Network Logon:
    User Name: MyUserName
    Domain: Domain
    Logon ID: (0x0,0xE5170)
    Logon Type: 3
    Logon Process: NtLmSsp
    Authentication Package: NTLM
    Workstation Name: MyWinXPMachine
    Logon GUID: -
    Caller User Name: -
    Caller Domain: -
    Caller Logon ID: -
    Caller Process ID: -
    Transited Services: -
    Source Network Address: 192.168.14.96
    Source Port: 4762

    For more information, see Help and Support Center at http://go.microsoft.co m/fwlink/events.asp.
    I am at my wits end on how to solve this Issue. Any Help would greatly be appreciated. Also if you need to know any more information feel free to ask.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I believe that the only guaranteed way that you are going to get this to work is to upgrade the XP machine to the same specs as the other machines. I code on an XP and serve to Win Server 2003 test & production machines, so I know where you are coming from.

    I would check IIS & .NET versions on all machines, if you can't upgrade the OS at least ensure that these are the same. Its not like the old client-side browser compatability issues where you can serve up different code.

    Normally I would say that I hope this helps, but I don't see a solution arising from code for this problem.

    Comment

    Working...