Wednesday, March 28, 2012
System.IO.Directoryinfo throwing exception
directory to a local folder. For some reason, it is being denied access to
the network share. I have the web app running under a domain account that I
know for a fact has access. it works fine when I log on to the network and
browse the directory manually. Even when I grant full control to everyone on
the share and the underlying folder itself, I still can't access it through
code. The funny thing is though, this same code works fine when executed
within a windows service which runs under the same domain account. Help!
Code follows:
**** this first line is the one throwing the exception ********
Dim objFromDirectory As DirectoryInfo = New
DirectoryInfo("\\[server]\[network share]
Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
Dim objToDirectory As DirectoryInfo = New
DirectoryInfo(strNewBackupPath)
Dim objOldBackupFiles() As FileInfo =
objToDirectory.GetFiles()
Dim objNewBackupFiles() As FileInfo =
objFromDirectory.GetFiles()
Dim x As Integer
Dim intNewBackupFileCount As Integer =
UBound(objNewBackupFiles)
Dim objCurrentFile As FileInfo
Dim objBackUpLog As XmlDocument = New XmlDocument
Dim objNewParentNode As XmlElement
Dim objRootNode As XmlElement
Dim objLogEntryDateNode As XmlElement
Dim objNewChildNode As XmlElement
Dim objDateNodeList As XmlNodeList
Dim strStartTime As String
Dim strEndTime As String
Dim intFileSize As Integer = 0
Dim intLogEntryCount As Integer
Dim strBackUpLogPath As String =
"C:\SQLBackUp\SQLBackupLog.xml"
Dim objCurrentDateNode As XmlElement
Try
strStartTime = DateTime.Now.ToLongTimeString()
'-- delete old set of backups. GV 1/28/05
If UBound(objOldBackupFiles) > 0 Then
For x = 0 To UBound(objOldBackupFiles)
File.Delete(objOldBackupFiles(x).FullName)
Next
End If
'-- copy new set of backups. GV 1/28/05
'- if no backup files are found, throw an exception. GV
6/2/05
If intNewBackupFileCount < 1 Then
Throw New ApplicationException("No files were found.")
Else
For x = 0 To intNewBackupFileCount
objCurrentFile = objNewBackupFiles(x)
intFileSize = intFileSize + objCurrentFile.Length
objCurrentFile.CopyTo(strNewBackupPath & "\" &
objCurrentFile.Name)
Next
End If
strEndTime = DateTime.Now.ToLongTimeString()
'-- write file-copy info to XML log. GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)
' time started
objNewChildNode = objBackUpLog.CreateElement("starttime")
objNewChildNode.InnerText = strStartTime
objNewParentNode.AppendChild(objNewChildNode)
' time ended
objNewChildNode = objBackUpLog.CreateElement("endtime")
objNewChildNode.InnerText = strEndTime
objNewParentNode.AppendChild(objNewChildNode)
' total amount copied (in megs)
objNewChildNode = objBackUpLog.CreateElement("dataamount")
objNewChildNode.InnerText = CStr(Math.Round(intFileSize
/ 1048576, 2) & " Mb")
objNewParentNode.AppendChild(objNewChildNode)
' total number of files copied
objNewChildNode = objBackUpLog.CreateElement("nbroffiles")
objNewChildNode.InnerText = CStr(intNewBackupFileCount +
1)
objNewParentNode.AppendChild(objNewChildNode)
'-- delete entries older than 4 months. GV 1/31/05
objDateNodeList =
objBackUpLog.SelectNodes("/log/logentry/date")
For Each objCurrentDateNode In objDateNodeList
If DateValue(CDate(objCurrentDateNode.InnerXml)) <
DateValue(DateAdd("d", -120, DateTime.Now)) Then
objCurrentDateNode.RemoveAll()
objRootNode =
objCurrentDateNode.ParentNode.ParentNode
objRootNode.RemoveChild(objCurrentDateNode.ParentNode)
End If
Next
'-- save changes. GV 1/31/05
objBackUpLog.Save(strBackUpLogPath)
intOperationSuccess = 1
Catch exc As Exception
'-- if exception occurs, write error info to XML log.
GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)
' error header
objNewChildNode =
objBackUpLog.CreateElement("errorheader")
objNewChildNode.InnerText = "** ERROR **"
objNewParentNode.AppendChild(objNewChildNode)
' error description
objNewChildNode =
objBackUpLog.CreateElement("errordescription")
objNewChildNode.InnerText = exc.Message.ToString
objNewParentNode.AppendChild(objNewChildNode)
objBackUpLog.Save(strBackUpLogPath)
objEventLog.WriteEntry("**** ERROR **** " &
exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
intOperationSuccess = 0
'--
Finally
'-- destroy all objects. GV 1/28/05
x = Nothing
intFileSize = Nothing
intLogEntryCount = Nothing
If Not (objBackUpLog Is Nothing) Then objBackUpLog =
Nothing
If Not (objCurrentFile Is Nothing) Then objCurrentFile =
Nothing
intNewBackupFileCount = Nothing
If Not (objNewBackupFiles Is Nothing) Then
objNewBackupFiles = Nothing
If Not (objOldBackupFiles Is Nothing) Then
objOldBackupFiles = Nothing
If Not (objToDirectory Is Nothing) Then objToDirectory =
Nothing
If Not (strNewBackupPath Is Nothing) Then
strNewBackupPath = Nothing
If Not (objFromDirectory Is Nothing) Then
objFromDirectory = Nothing
If Not (strStartTime Is Nothing) Then strStartTime =
Nothing
If Not (strEndTime Is Nothing) Then strEndTime = Nothing
If Not (objRootNode Is Nothing) Then objRootNode = Nothing
If Not (objNewParentNode Is Nothing) Then
objNewParentNode = Nothing
If Not (objNewChildNode Is Nothing) Then objNewChildNode
= Nothing
If Not (objDateNodeList Is Nothing) Then objDateNodeList
= Nothing
If Not (objCurrentDateNode Is Nothing) Then
objCurrentDateNode = Nothing
If Not (objLogEntryDateNode Is Nothing) Then
objLogEntryDateNode = Nothing
If Not (strBackUpLogPath Is Nothing) Then
strBackUpLogPath = Nothing
'--
End TryAnother MVP has written a great article about this
http://west-wind.com/weblog/posts/1572.aspx
The crux is (and its a pain to get working) that using Anonymous
authentication (so no impersonation) the local ASPNET account has to have
the same credentials (username and password) on both machines in order to
delegate security. With basic authentication and impersonation you need to
use a domain account which can delegate and you can check how to mark your
impersonated account able to use security delegation here:
http://msdn.microsoft.com/library/d...>
NetHT05.asp.
This is also required if you want to use NTLM authentication over kerberos
Personally, I would implement a the remote server as an http device and use
http requests, checking the referrer whihc makes life a lot simpler than
using mapped network drives.
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>I have an aspx page that is set up to copy backed-up DB files from a shared
> directory to a local folder. For some reason, it is being denied access to
> the network share. I have the web app running under a domain account that
> I
> know for a fact has access. it works fine when I log on to the network and
> browse the directory manually. Even when I grant full control to everyone
> on
> the share and the underlying folder itself, I still can't access it
> through
> code. The funny thing is though, this same code works fine when executed
> within a windows service which runs under the same domain account. Help!
> Code follows:
> **** this first line is the one throwing the exception ********
> Dim objFromDirectory As DirectoryInfo = New
> DirectoryInfo("\\[server]\[network share]
>
> Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> Dim objToDirectory As DirectoryInfo = New
> DirectoryInfo(strNewBackupPath)
> Dim objOldBackupFiles() As FileInfo =
> objToDirectory.GetFiles()
> Dim objNewBackupFiles() As FileInfo =
> objFromDirectory.GetFiles()
> Dim x As Integer
> Dim intNewBackupFileCount As Integer =
> UBound(objNewBackupFiles)
> Dim objCurrentFile As FileInfo
> Dim objBackUpLog As XmlDocument = New XmlDocument
> Dim objNewParentNode As XmlElement
> Dim objRootNode As XmlElement
> Dim objLogEntryDateNode As XmlElement
> Dim objNewChildNode As XmlElement
> Dim objDateNodeList As XmlNodeList
> Dim strStartTime As String
> Dim strEndTime As String
> Dim intFileSize As Integer = 0
> Dim intLogEntryCount As Integer
> Dim strBackUpLogPath As String =
> "C:\SQLBackUp\SQLBackupLog.xml"
> Dim objCurrentDateNode As XmlElement
> Try
> strStartTime = DateTime.Now.ToLongTimeString()
> '-- delete old set of backups. GV 1/28/05
> If UBound(objOldBackupFiles) > 0 Then
> For x = 0 To UBound(objOldBackupFiles)
> File.Delete(objOldBackupFiles(x).FullName)
> Next
> End If
> '-- copy new set of backups. GV 1/28/05
> '- if no backup files are found, throw an exception. GV
> 6/2/05
> If intNewBackupFileCount < 1 Then
> Throw New ApplicationException("No files were
> found.")
> Else
> For x = 0 To intNewBackupFileCount
> objCurrentFile = objNewBackupFiles(x)
> intFileSize = intFileSize +
> objCurrentFile.Length
> objCurrentFile.CopyTo(strNewBackupPath & "\" &
> objCurrentFile.Name)
> Next
> End If
> strEndTime = DateTime.Now.ToLongTimeString()
> '-- write file-copy info to XML log. GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' time started
> objNewChildNode =
> objBackUpLog.CreateElement("starttime")
> objNewChildNode.InnerText = strStartTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' time ended
> objNewChildNode = objBackUpLog.CreateElement("endtime")
> objNewChildNode.InnerText = strEndTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' total amount copied (in megs)
> objNewChildNode =
> objBackUpLog.CreateElement("dataamount")
> objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> / 1048576, 2) & " Mb")
> objNewParentNode.AppendChild(objNewChildNode)
> ' total number of files copied
> objNewChildNode =
> objBackUpLog.CreateElement("nbroffiles")
> objNewChildNode.InnerText = CStr(intNewBackupFileCount
> +
> 1)
> objNewParentNode.AppendChild(objNewChildNode)
> '-- delete entries older than 4 months. GV 1/31/05
> objDateNodeList =
> objBackUpLog.SelectNodes("/log/logentry/date")
> For Each objCurrentDateNode In objDateNodeList
> If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> DateValue(DateAdd("d", -120, DateTime.Now)) Then
> objCurrentDateNode.RemoveAll()
> objRootNode =
> objCurrentDateNode.ParentNode.ParentNode
> objRootNode.RemoveChild(objCurrentDateNode.ParentNode)
> End If
> Next
> '-- save changes. GV 1/31/05
> objBackUpLog.Save(strBackUpLogPath)
> intOperationSuccess = 1
> Catch exc As Exception
> '-- if exception occurs, write error info to XML log.
> GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' error header
> objNewChildNode =
> objBackUpLog.CreateElement("errorheader")
> objNewChildNode.InnerText = "** ERROR **"
> objNewParentNode.AppendChild(objNewChildNode)
> ' error description
> objNewChildNode =
> objBackUpLog.CreateElement("errordescription")
> objNewChildNode.InnerText = exc.Message.ToString
> objNewParentNode.AppendChild(objNewChildNode)
> objBackUpLog.Save(strBackUpLogPath)
> objEventLog.WriteEntry("**** ERROR **** " &
> exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> intOperationSuccess = 0
> '--
> Finally
> '-- destroy all objects. GV 1/28/05
> x = Nothing
> intFileSize = Nothing
> intLogEntryCount = Nothing
> If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> Nothing
> If Not (objCurrentFile Is Nothing) Then objCurrentFile
> =
> Nothing
> intNewBackupFileCount = Nothing
> If Not (objNewBackupFiles Is Nothing) Then
> objNewBackupFiles = Nothing
> If Not (objOldBackupFiles Is Nothing) Then
> objOldBackupFiles = Nothing
> If Not (objToDirectory Is Nothing) Then objToDirectory
> =
> Nothing
> If Not (strNewBackupPath Is Nothing) Then
> strNewBackupPath = Nothing
> If Not (objFromDirectory Is Nothing) Then
> objFromDirectory = Nothing
> If Not (strStartTime Is Nothing) Then strStartTime =
> Nothing
> If Not (strEndTime Is Nothing) Then strEndTime =
> Nothing
> If Not (objRootNode Is Nothing) Then objRootNode =
> Nothing
> If Not (objNewParentNode Is Nothing) Then
> objNewParentNode = Nothing
> If Not (objNewChildNode Is Nothing) Then
> objNewChildNode
> = Nothing
> If Not (objDateNodeList Is Nothing) Then
> objDateNodeList
> = Nothing
> If Not (objCurrentDateNode Is Nothing) Then
> objCurrentDateNode = Nothing
> If Not (objLogEntryDateNode Is Nothing) Then
> objLogEntryDateNode = Nothing
> If Not (strBackUpLogPath Is Nothing) Then
> strBackUpLogPath = Nothing
> '--
> End Try
>
Problem solved! All I had to do was set "identity impersonate" to "true" in
my web.config. Thank you so much!
"John Timney (ASP.NET MVP)" wrote:
> Another MVP has written a great article about this
> http://west-wind.com/weblog/posts/1572.aspx
> The crux is (and its a pain to get working) that using Anonymous
> authentication (so no impersonation) the local ASPNET account has to have
> the same credentials (username and password) on both machines in order to
> delegate security. With basic authentication and impersonation you need t
o
> use a domain account which can delegate and you can check how to mark your
> impersonated account able to use security delegation here:
> http://msdn.microsoft.com/library/d...
ecNetHT05.asp.
> This is also required if you want to use NTLM authentication over kerberos
> Personally, I would implement a the remote server as an http device and us
e
> http requests, checking the referrer whihc makes life a lot simpler than
> using mapped network drives.
> --
> Regards
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>
>
glad your sorted :)
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:CCC31167-8012-4FC7-9EC7-3F125F515339@.microsoft.com...
> Problem solved! All I had to do was set "identity impersonate" to "true"
> in
> my web.config. Thank you so much!
> "John Timney (ASP.NET MVP)" wrote:
>
System.IO.Directoryinfo throwing exception
directory to a local folder. For some reason, it is being denied access to
the network share. I have the web app running under a domain account that I
know for a fact has access. it works fine when I log on to the network and
browse the directory manually. Even when I grant full control to everyone on
the share and the underlying folder itself, I still can't access it through
code. The funny thing is though, this same code works fine when executed
within a windows service which runs under the same domain account. Help!
Code follows:
**** this first line is the one throwing the exception ********
Dim objFromDirectory As DirectoryInfo = New
DirectoryInfo("\\[server]\[network share]
Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
Dim objToDirectory As DirectoryInfo = New
DirectoryInfo(strNewBackupPath)
Dim objOldBackupFiles() As FileInfo =
objToDirectory.GetFiles()
Dim objNewBackupFiles() As FileInfo =
objFromDirectory.GetFiles()
Dim x As Integer
Dim intNewBackupFileCount As Integer =
UBound(objNewBackupFiles)
Dim objCurrentFile As FileInfo
Dim objBackUpLog As XmlDocument = New XmlDocument
Dim objNewParentNode As XmlElement
Dim objRootNode As XmlElement
Dim objLogEntryDateNode As XmlElement
Dim objNewChildNode As XmlElement
Dim objDateNodeList As XmlNodeList
Dim strStartTime As String
Dim strEndTime As String
Dim intFileSize As Integer = 0
Dim intLogEntryCount As Integer
Dim strBackUpLogPath As String =
"C:\SQLBackUp\SQLBackupLog.xml"
Dim objCurrentDateNode As XmlElement
Try
strStartTime = DateTime.Now.ToLongTimeString()
'-- delete old set of backups. GV 1/28/05
If UBound(objOldBackupFiles) > 0 Then
For x = 0 To UBound(objOldBackupFiles)
File.Delete(objOldBackupFiles(x).FullName)
Next
End If
'-- copy new set of backups. GV 1/28/05
'- if no backup files are found, throw an exception. GV
6/2/05
If intNewBackupFileCount < 1 Then
Throw New ApplicationException("No files were found.")
Else
For x = 0 To intNewBackupFileCount
objCurrentFile = objNewBackupFiles(x)
intFileSize = intFileSize + objCurrentFile.Length
objCurrentFile.CopyTo(strNewBackupPath & "\" &
objCurrentFile.Name)
Next
End If
strEndTime = DateTime.Now.ToLongTimeString()
'-- write file-copy info to XML log. GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)
' time started
objNewChildNode = objBackUpLog.CreateElement("starttime")
objNewChildNode.InnerText = strStartTime
objNewParentNode.AppendChild(objNewChildNode)
' time ended
objNewChildNode = objBackUpLog.CreateElement("endtime")
objNewChildNode.InnerText = strEndTime
objNewParentNode.AppendChild(objNewChildNode)
' total amount copied (in megs)
objNewChildNode = objBackUpLog.CreateElement("dataamount")
objNewChildNode.InnerText = CStr(Math.Round(intFileSize
/ 1048576, 2) & " Mb")
objNewParentNode.AppendChild(objNewChildNode)
' total number of files copied
objNewChildNode = objBackUpLog.CreateElement("nbroffiles")
objNewChildNode.InnerText = CStr(intNewBackupFileCount +
1)
objNewParentNode.AppendChild(objNewChildNode)
'-- delete entries older than 4 months. GV 1/31/05
objDateNodeList =
objBackUpLog.SelectNodes("/log/logentry/date")
For Each objCurrentDateNode In objDateNodeList
If DateValue(CDate(objCurrentDateNode.InnerXml)) <
DateValue(DateAdd("d", -120, DateTime.Now)) Then
objCurrentDateNode.RemoveAll()
objRootNode =
objCurrentDateNode.ParentNode.ParentNode
objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
End If
Next
'-- save changes. GV 1/31/05
objBackUpLog.Save(strBackUpLogPath)
intOperationSuccess = 1
Catch exc As Exception
'-- if exception occurs, write error info to XML log.
GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)
' error header
objNewChildNode =
objBackUpLog.CreateElement("errorheader")
objNewChildNode.InnerText = "** ERROR **"
objNewParentNode.AppendChild(objNewChildNode)
' error description
objNewChildNode =
objBackUpLog.CreateElement("errordescription")
objNewChildNode.InnerText = exc.Message.ToString
objNewParentNode.AppendChild(objNewChildNode)
objBackUpLog.Save(strBackUpLogPath)
objEventLog.WriteEntry("**** ERROR **** " &
exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
intOperationSuccess = 0
'--
Finally
'-- destroy all objects. GV 1/28/05
x = Nothing
intFileSize = Nothing
intLogEntryCount = Nothing
If Not (objBackUpLog Is Nothing) Then objBackUpLog =
Nothing
If Not (objCurrentFile Is Nothing) Then objCurrentFile =
Nothing
intNewBackupFileCount = Nothing
If Not (objNewBackupFiles Is Nothing) Then
objNewBackupFiles = Nothing
If Not (objOldBackupFiles Is Nothing) Then
objOldBackupFiles = Nothing
If Not (objToDirectory Is Nothing) Then objToDirectory =
Nothing
If Not (strNewBackupPath Is Nothing) Then
strNewBackupPath = Nothing
If Not (objFromDirectory Is Nothing) Then
objFromDirectory = Nothing
If Not (strStartTime Is Nothing) Then strStartTime =
Nothing
If Not (strEndTime Is Nothing) Then strEndTime = Nothing
If Not (objRootNode Is Nothing) Then objRootNode = Nothing
If Not (objNewParentNode Is Nothing) Then
objNewParentNode = Nothing
If Not (objNewChildNode Is Nothing) Then objNewChildNode
= Nothing
If Not (objDateNodeList Is Nothing) Then objDateNodeList
= Nothing
If Not (objCurrentDateNode Is Nothing) Then
objCurrentDateNode = Nothing
If Not (objLogEntryDateNode Is Nothing) Then
objLogEntryDateNode = Nothing
If Not (strBackUpLogPath Is Nothing) Then
strBackUpLogPath = Nothing
'--
End TryAnother MVP has written a great article about this
http://west-wind.com/weblog/posts/1572.aspx
The crux is (and its a pain to get working) that using Anonymous
authentication (so no impersonation) the local ASPNET account has to have
the same credentials (username and password) on both machines in order to
delegate security. With basic authentication and impersonation you need to
use a domain account which can delegate and you can check how to mark your
impersonated account able to use security delegation here:
http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
This is also required if you want to use NTLM authentication over kerberos
Personally, I would implement a the remote server as an http device and use
http requests, checking the referrer whihc makes life a lot simpler than
using mapped network drives.
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>I have an aspx page that is set up to copy backed-up DB files from a shared
> directory to a local folder. For some reason, it is being denied access to
> the network share. I have the web app running under a domain account that
> I
> know for a fact has access. it works fine when I log on to the network and
> browse the directory manually. Even when I grant full control to everyone
> on
> the share and the underlying folder itself, I still can't access it
> through
> code. The funny thing is though, this same code works fine when executed
> within a windows service which runs under the same domain account. Help!
> Code follows:
> **** this first line is the one throwing the exception ********
> Dim objFromDirectory As DirectoryInfo = New
> DirectoryInfo("\\[server]\[network share]
>
> Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> Dim objToDirectory As DirectoryInfo = New
> DirectoryInfo(strNewBackupPath)
> Dim objOldBackupFiles() As FileInfo =
> objToDirectory.GetFiles()
> Dim objNewBackupFiles() As FileInfo =
> objFromDirectory.GetFiles()
> Dim x As Integer
> Dim intNewBackupFileCount As Integer =
> UBound(objNewBackupFiles)
> Dim objCurrentFile As FileInfo
> Dim objBackUpLog As XmlDocument = New XmlDocument
> Dim objNewParentNode As XmlElement
> Dim objRootNode As XmlElement
> Dim objLogEntryDateNode As XmlElement
> Dim objNewChildNode As XmlElement
> Dim objDateNodeList As XmlNodeList
> Dim strStartTime As String
> Dim strEndTime As String
> Dim intFileSize As Integer = 0
> Dim intLogEntryCount As Integer
> Dim strBackUpLogPath As String =
> "C:\SQLBackUp\SQLBackupLog.xml"
> Dim objCurrentDateNode As XmlElement
> Try
> strStartTime = DateTime.Now.ToLongTimeString()
> '-- delete old set of backups. GV 1/28/05
> If UBound(objOldBackupFiles) > 0 Then
> For x = 0 To UBound(objOldBackupFiles)
> File.Delete(objOldBackupFiles(x).FullName)
> Next
> End If
> '-- copy new set of backups. GV 1/28/05
> '- if no backup files are found, throw an exception. GV
> 6/2/05
> If intNewBackupFileCount < 1 Then
> Throw New ApplicationException("No files were
> found.")
> Else
> For x = 0 To intNewBackupFileCount
> objCurrentFile = objNewBackupFiles(x)
> intFileSize = intFileSize +
> objCurrentFile.Length
> objCurrentFile.CopyTo(strNewBackupPath & "\" &
> objCurrentFile.Name)
> Next
> End If
> strEndTime = DateTime.Now.ToLongTimeString()
> '-- write file-copy info to XML log. GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' time started
> objNewChildNode =
> objBackUpLog.CreateElement("starttime")
> objNewChildNode.InnerText = strStartTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' time ended
> objNewChildNode = objBackUpLog.CreateElement("endtime")
> objNewChildNode.InnerText = strEndTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' total amount copied (in megs)
> objNewChildNode =
> objBackUpLog.CreateElement("dataamount")
> objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> / 1048576, 2) & " Mb")
> objNewParentNode.AppendChild(objNewChildNode)
> ' total number of files copied
> objNewChildNode =
> objBackUpLog.CreateElement("nbroffiles")
> objNewChildNode.InnerText = CStr(intNewBackupFileCount
> +
> 1)
> objNewParentNode.AppendChild(objNewChildNode)
> '-- delete entries older than 4 months. GV 1/31/05
> objDateNodeList =
> objBackUpLog.SelectNodes("/log/logentry/date")
> For Each objCurrentDateNode In objDateNodeList
> If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> DateValue(DateAdd("d", -120, DateTime.Now)) Then
> objCurrentDateNode.RemoveAll()
> objRootNode =
> objCurrentDateNode.ParentNode.ParentNode
> objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> End If
> Next
> '-- save changes. GV 1/31/05
> objBackUpLog.Save(strBackUpLogPath)
> intOperationSuccess = 1
> Catch exc As Exception
> '-- if exception occurs, write error info to XML log.
> GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' error header
> objNewChildNode =
> objBackUpLog.CreateElement("errorheader")
> objNewChildNode.InnerText = "** ERROR **"
> objNewParentNode.AppendChild(objNewChildNode)
> ' error description
> objNewChildNode =
> objBackUpLog.CreateElement("errordescription")
> objNewChildNode.InnerText = exc.Message.ToString
> objNewParentNode.AppendChild(objNewChildNode)
> objBackUpLog.Save(strBackUpLogPath)
> objEventLog.WriteEntry("**** ERROR **** " &
> exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> intOperationSuccess = 0
> '--
> Finally
> '-- destroy all objects. GV 1/28/05
> x = Nothing
> intFileSize = Nothing
> intLogEntryCount = Nothing
> If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> Nothing
> If Not (objCurrentFile Is Nothing) Then objCurrentFile
> =
> Nothing
> intNewBackupFileCount = Nothing
> If Not (objNewBackupFiles Is Nothing) Then
> objNewBackupFiles = Nothing
> If Not (objOldBackupFiles Is Nothing) Then
> objOldBackupFiles = Nothing
> If Not (objToDirectory Is Nothing) Then objToDirectory
> =
> Nothing
> If Not (strNewBackupPath Is Nothing) Then
> strNewBackupPath = Nothing
> If Not (objFromDirectory Is Nothing) Then
> objFromDirectory = Nothing
> If Not (strStartTime Is Nothing) Then strStartTime =
> Nothing
> If Not (strEndTime Is Nothing) Then strEndTime =
> Nothing
> If Not (objRootNode Is Nothing) Then objRootNode =
> Nothing
> If Not (objNewParentNode Is Nothing) Then
> objNewParentNode = Nothing
> If Not (objNewChildNode Is Nothing) Then
> objNewChildNode
> = Nothing
> If Not (objDateNodeList Is Nothing) Then
> objDateNodeList
> = Nothing
> If Not (objCurrentDateNode Is Nothing) Then
> objCurrentDateNode = Nothing
> If Not (objLogEntryDateNode Is Nothing) Then
> objLogEntryDateNode = Nothing
> If Not (strBackUpLogPath Is Nothing) Then
> strBackUpLogPath = Nothing
> '--
> End Try
Another MVP has written a great article about this
http://west-wind.com/weblog/posts/1572.aspx
The crux is (and its a pain to get working) that using Anonymous
authentication (so no impersonation) the local ASPNET account has to have
the same credentials (username and password) on both machines in order to
delegate security. With basic authentication and impersonation you need to
use a domain account which can delegate and you can check how to mark your
impersonated account able to use security delegation here:
http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
This is also required if you want to use NTLM authentication over kerberos
Personally, I would implement a the remote server as an http device and use
http requests, checking the referrer whihc makes life a lot simpler than
using mapped network drives.
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>I have an aspx page that is set up to copy backed-up DB files from a shared
> directory to a local folder. For some reason, it is being denied access to
> the network share. I have the web app running under a domain account that
> I
> know for a fact has access. it works fine when I log on to the network and
> browse the directory manually. Even when I grant full control to everyone
> on
> the share and the underlying folder itself, I still can't access it
> through
> code. The funny thing is though, this same code works fine when executed
> within a windows service which runs under the same domain account. Help!
> Code follows:
> **** this first line is the one throwing the exception ********
> Dim objFromDirectory As DirectoryInfo = New
> DirectoryInfo("\\[server]\[network share]
>
> Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> Dim objToDirectory As DirectoryInfo = New
> DirectoryInfo(strNewBackupPath)
> Dim objOldBackupFiles() As FileInfo =
> objToDirectory.GetFiles()
> Dim objNewBackupFiles() As FileInfo =
> objFromDirectory.GetFiles()
> Dim x As Integer
> Dim intNewBackupFileCount As Integer =
> UBound(objNewBackupFiles)
> Dim objCurrentFile As FileInfo
> Dim objBackUpLog As XmlDocument = New XmlDocument
> Dim objNewParentNode As XmlElement
> Dim objRootNode As XmlElement
> Dim objLogEntryDateNode As XmlElement
> Dim objNewChildNode As XmlElement
> Dim objDateNodeList As XmlNodeList
> Dim strStartTime As String
> Dim strEndTime As String
> Dim intFileSize As Integer = 0
> Dim intLogEntryCount As Integer
> Dim strBackUpLogPath As String =
> "C:\SQLBackUp\SQLBackupLog.xml"
> Dim objCurrentDateNode As XmlElement
> Try
> strStartTime = DateTime.Now.ToLongTimeString()
> '-- delete old set of backups. GV 1/28/05
> If UBound(objOldBackupFiles) > 0 Then
> For x = 0 To UBound(objOldBackupFiles)
> File.Delete(objOldBackupFiles(x).FullName)
> Next
> End If
> '-- copy new set of backups. GV 1/28/05
> '- if no backup files are found, throw an exception. GV
> 6/2/05
> If intNewBackupFileCount < 1 Then
> Throw New ApplicationException("No files were
> found.")
> Else
> For x = 0 To intNewBackupFileCount
> objCurrentFile = objNewBackupFiles(x)
> intFileSize = intFileSize +
> objCurrentFile.Length
> objCurrentFile.CopyTo(strNewBackupPath & "\" &
> objCurrentFile.Name)
> Next
> End If
> strEndTime = DateTime.Now.ToLongTimeString()
> '-- write file-copy info to XML log. GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' time started
> objNewChildNode =
> objBackUpLog.CreateElement("starttime")
> objNewChildNode.InnerText = strStartTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' time ended
> objNewChildNode = objBackUpLog.CreateElement("endtime")
> objNewChildNode.InnerText = strEndTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' total amount copied (in megs)
> objNewChildNode =
> objBackUpLog.CreateElement("dataamount")
> objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> / 1048576, 2) & " Mb")
> objNewParentNode.AppendChild(objNewChildNode)
> ' total number of files copied
> objNewChildNode =
> objBackUpLog.CreateElement("nbroffiles")
> objNewChildNode.InnerText = CStr(intNewBackupFileCount
> +
> 1)
> objNewParentNode.AppendChild(objNewChildNode)
> '-- delete entries older than 4 months. GV 1/31/05
> objDateNodeList =
> objBackUpLog.SelectNodes("/log/logentry/date")
> For Each objCurrentDateNode In objDateNodeList
> If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> DateValue(DateAdd("d", -120, DateTime.Now)) Then
> objCurrentDateNode.RemoveAll()
> objRootNode =
> objCurrentDateNode.ParentNode.ParentNode
> objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> End If
> Next
> '-- save changes. GV 1/31/05
> objBackUpLog.Save(strBackUpLogPath)
> intOperationSuccess = 1
> Catch exc As Exception
> '-- if exception occurs, write error info to XML log.
> GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' error header
> objNewChildNode =
> objBackUpLog.CreateElement("errorheader")
> objNewChildNode.InnerText = "** ERROR **"
> objNewParentNode.AppendChild(objNewChildNode)
> ' error description
> objNewChildNode =
> objBackUpLog.CreateElement("errordescription")
> objNewChildNode.InnerText = exc.Message.ToString
> objNewParentNode.AppendChild(objNewChildNode)
> objBackUpLog.Save(strBackUpLogPath)
> objEventLog.WriteEntry("**** ERROR **** " &
> exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> intOperationSuccess = 0
> '--
> Finally
> '-- destroy all objects. GV 1/28/05
> x = Nothing
> intFileSize = Nothing
> intLogEntryCount = Nothing
> If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> Nothing
> If Not (objCurrentFile Is Nothing) Then objCurrentFile
> =
> Nothing
> intNewBackupFileCount = Nothing
> If Not (objNewBackupFiles Is Nothing) Then
> objNewBackupFiles = Nothing
> If Not (objOldBackupFiles Is Nothing) Then
> objOldBackupFiles = Nothing
> If Not (objToDirectory Is Nothing) Then objToDirectory
> =
> Nothing
> If Not (strNewBackupPath Is Nothing) Then
> strNewBackupPath = Nothing
> If Not (objFromDirectory Is Nothing) Then
> objFromDirectory = Nothing
> If Not (strStartTime Is Nothing) Then strStartTime =
> Nothing
> If Not (strEndTime Is Nothing) Then strEndTime =
> Nothing
> If Not (objRootNode Is Nothing) Then objRootNode =
> Nothing
> If Not (objNewParentNode Is Nothing) Then
> objNewParentNode = Nothing
> If Not (objNewChildNode Is Nothing) Then
> objNewChildNode
> = Nothing
> If Not (objDateNodeList Is Nothing) Then
> objDateNodeList
> = Nothing
> If Not (objCurrentDateNode Is Nothing) Then
> objCurrentDateNode = Nothing
> If Not (objLogEntryDateNode Is Nothing) Then
> objLogEntryDateNode = Nothing
> If Not (strBackUpLogPath Is Nothing) Then
> strBackUpLogPath = Nothing
> '--
> End Try
Problem solved! All I had to do was set "identity impersonate" to "true" in
my web.config. Thank you so much!
"John Timney (ASP.NET MVP)" wrote:
> Another MVP has written a great article about this
> http://west-wind.com/weblog/posts/1572.aspx
> The crux is (and its a pain to get working) that using Anonymous
> authentication (so no impersonation) the local ASPNET account has to have
> the same credentials (username and password) on both machines in order to
> delegate security. With basic authentication and impersonation you need to
> use a domain account which can delegate and you can check how to mark your
> impersonated account able to use security delegation here:
> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
> This is also required if you want to use NTLM authentication over kerberos
> Personally, I would implement a the remote server as an http device and use
> http requests, checking the referrer whihc makes life a lot simpler than
> using mapped network drives.
> --
> Regards
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
> >I have an aspx page that is set up to copy backed-up DB files from a shared
> > directory to a local folder. For some reason, it is being denied access to
> > the network share. I have the web app running under a domain account that
> > I
> > know for a fact has access. it works fine when I log on to the network and
> > browse the directory manually. Even when I grant full control to everyone
> > on
> > the share and the underlying folder itself, I still can't access it
> > through
> > code. The funny thing is though, this same code works fine when executed
> > within a windows service which runs under the same domain account. Help!
> > Code follows:
> > **** this first line is the one throwing the exception ********
> > Dim objFromDirectory As DirectoryInfo = New
> > DirectoryInfo("\\[server]\[network share]
> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> > Dim objToDirectory As DirectoryInfo = New
> > DirectoryInfo(strNewBackupPath)
> > Dim objOldBackupFiles() As FileInfo =
> > objToDirectory.GetFiles()
> > Dim objNewBackupFiles() As FileInfo =
> > objFromDirectory.GetFiles()
> > Dim x As Integer
> > Dim intNewBackupFileCount As Integer =
> > UBound(objNewBackupFiles)
> > Dim objCurrentFile As FileInfo
> > Dim objBackUpLog As XmlDocument = New XmlDocument
> > Dim objNewParentNode As XmlElement
> > Dim objRootNode As XmlElement
> > Dim objLogEntryDateNode As XmlElement
> > Dim objNewChildNode As XmlElement
> > Dim objDateNodeList As XmlNodeList
> > Dim strStartTime As String
> > Dim strEndTime As String
> > Dim intFileSize As Integer = 0
> > Dim intLogEntryCount As Integer
> > Dim strBackUpLogPath As String =
> > "C:\SQLBackUp\SQLBackupLog.xml"
> > Dim objCurrentDateNode As XmlElement
> > Try
> > strStartTime = DateTime.Now.ToLongTimeString()
> > '-- delete old set of backups. GV 1/28/05
> > If UBound(objOldBackupFiles) > 0 Then
> > For x = 0 To UBound(objOldBackupFiles)
> > File.Delete(objOldBackupFiles(x).FullName)
> > Next
> > End If
> > '-- copy new set of backups. GV 1/28/05
> > '- if no backup files are found, throw an exception. GV
> > 6/2/05
> > If intNewBackupFileCount < 1 Then
> > Throw New ApplicationException("No files were
> > found.")
> > Else
> > For x = 0 To intNewBackupFileCount
> > objCurrentFile = objNewBackupFiles(x)
> > intFileSize = intFileSize +
> > objCurrentFile.Length
> > objCurrentFile.CopyTo(strNewBackupPath & "\" &
> > objCurrentFile.Name)
> > Next
> > End If
> > strEndTime = DateTime.Now.ToLongTimeString()
> > '-- write file-copy info to XML log. GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time started
> > objNewChildNode =
> > objBackUpLog.CreateElement("starttime")
> > objNewChildNode.InnerText = strStartTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time ended
> > objNewChildNode = objBackUpLog.CreateElement("endtime")
> > objNewChildNode.InnerText = strEndTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total amount copied (in megs)
> > objNewChildNode =
> > objBackUpLog.CreateElement("dataamount")
> > objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> > / 1048576, 2) & " Mb")
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total number of files copied
> > objNewChildNode =
> > objBackUpLog.CreateElement("nbroffiles")
> > objNewChildNode.InnerText = CStr(intNewBackupFileCount
> > +
> > 1)
> > objNewParentNode.AppendChild(objNewChildNode)
> > '-- delete entries older than 4 months. GV 1/31/05
> > objDateNodeList =
> > objBackUpLog.SelectNodes("/log/logentry/date")
> > For Each objCurrentDateNode In objDateNodeList
> > If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
> > objCurrentDateNode.RemoveAll()
> > objRootNode =
> > objCurrentDateNode.ParentNode.ParentNode
> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> > End If
> > Next
> > '-- save changes. GV 1/31/05
> > objBackUpLog.Save(strBackUpLogPath)
> > intOperationSuccess = 1
> > Catch exc As Exception
> > '-- if exception occurs, write error info to XML log.
> > GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error header
> > objNewChildNode =
> > objBackUpLog.CreateElement("errorheader")
> > objNewChildNode.InnerText = "** ERROR **"
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error description
> > objNewChildNode =
> > objBackUpLog.CreateElement("errordescription")
> > objNewChildNode.InnerText = exc.Message.ToString
> > objNewParentNode.AppendChild(objNewChildNode)
> > objBackUpLog.Save(strBackUpLogPath)
> > objEventLog.WriteEntry("**** ERROR **** " &
> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> > intOperationSuccess = 0
> > '--
> > Finally
> > '-- destroy all objects. GV 1/28/05
> > x = Nothing
> > intFileSize = Nothing
> > intLogEntryCount = Nothing
> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> > Nothing
> > If Not (objCurrentFile Is Nothing) Then objCurrentFile
> > =
> > Nothing
> > intNewBackupFileCount = Nothing
> > If Not (objNewBackupFiles Is Nothing) Then
> > objNewBackupFiles = Nothing
> > If Not (objOldBackupFiles Is Nothing) Then
> > objOldBackupFiles = Nothing
> > If Not (objToDirectory Is Nothing) Then objToDirectory
> > =
> > Nothing
> > If Not (strNewBackupPath Is Nothing) Then
> > strNewBackupPath = Nothing
> > If Not (objFromDirectory Is Nothing) Then
> > objFromDirectory = Nothing
> > If Not (strStartTime Is Nothing) Then strStartTime =
> > Nothing
> > If Not (strEndTime Is Nothing) Then strEndTime =
> > Nothing
> > If Not (objRootNode Is Nothing) Then objRootNode =
> > Nothing
> > If Not (objNewParentNode Is Nothing) Then
> > objNewParentNode = Nothing
> > If Not (objNewChildNode Is Nothing) Then
> > objNewChildNode
> > = Nothing
> > If Not (objDateNodeList Is Nothing) Then
> > objDateNodeList
> > = Nothing
> > If Not (objCurrentDateNode Is Nothing) Then
> > objCurrentDateNode = Nothing
> > If Not (objLogEntryDateNode Is Nothing) Then
> > objLogEntryDateNode = Nothing
> > If Not (strBackUpLogPath Is Nothing) Then
> > strBackUpLogPath = Nothing
> > '--
> > End Try
>
glad your sorted :)
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:CCC31167-8012-4FC7-9EC7-3F125F515339@.microsoft.com...
> Problem solved! All I had to do was set "identity impersonate" to "true"
> in
> my web.config. Thank you so much!
> "John Timney (ASP.NET MVP)" wrote:
>> Another MVP has written a great article about this
>> http://west-wind.com/weblog/posts/1572.aspx
>>
>> The crux is (and its a pain to get working) that using Anonymous
>> authentication (so no impersonation) the local ASPNET account has to have
>> the same credentials (username and password) on both machines in order to
>> delegate security. With basic authentication and impersonation you need
>> to
>> use a domain account which can delegate and you can check how to mark
>> your
>> impersonated account able to use security delegation here:
>> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
>> This is also required if you want to use NTLM authentication over
>> kerberos
>>
>> Personally, I would implement a the remote server as an http device and
>> use
>> http requests, checking the referrer whihc makes life a lot simpler than
>> using mapped network drives.
>> --
>> Regards
>>
>> John Timney
>> ASP.NET MVP
>> Microsoft Regional Director
>>
>> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
>> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>> >I have an aspx page that is set up to copy backed-up DB files from a
>> >shared
>> > directory to a local folder. For some reason, it is being denied access
>> > to
>> > the network share. I have the web app running under a domain account
>> > that
>> > I
>> > know for a fact has access. it works fine when I log on to the network
>> > and
>> > browse the directory manually. Even when I grant full control to
>> > everyone
>> > on
>> > the share and the underlying folder itself, I still can't access it
>> > through
>> > code. The funny thing is though, this same code works fine when
>> > executed
>> > within a windows service which runs under the same domain account.
>> > Help!
>>> > Code follows:
>>> > **** this first line is the one throwing the exception ********
>> > Dim objFromDirectory As DirectoryInfo = New
>> > DirectoryInfo("\\[server]\[network share]
>>>> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
>> > Dim objToDirectory As DirectoryInfo = New
>> > DirectoryInfo(strNewBackupPath)
>> > Dim objOldBackupFiles() As FileInfo =
>> > objToDirectory.GetFiles()
>> > Dim objNewBackupFiles() As FileInfo =
>> > objFromDirectory.GetFiles()
>> > Dim x As Integer
>> > Dim intNewBackupFileCount As Integer =
>> > UBound(objNewBackupFiles)
>> > Dim objCurrentFile As FileInfo
>> > Dim objBackUpLog As XmlDocument = New XmlDocument
>> > Dim objNewParentNode As XmlElement
>> > Dim objRootNode As XmlElement
>> > Dim objLogEntryDateNode As XmlElement
>> > Dim objNewChildNode As XmlElement
>> > Dim objDateNodeList As XmlNodeList
>> > Dim strStartTime As String
>> > Dim strEndTime As String
>> > Dim intFileSize As Integer = 0
>> > Dim intLogEntryCount As Integer
>> > Dim strBackUpLogPath As String =
>> > "C:\SQLBackUp\SQLBackupLog.xml"
>> > Dim objCurrentDateNode As XmlElement
>> > Try
>> > strStartTime = DateTime.Now.ToLongTimeString()
>>> > '-- delete old set of backups. GV 1/28/05
>> > If UBound(objOldBackupFiles) > 0 Then
>> > For x = 0 To UBound(objOldBackupFiles)
>> > File.Delete(objOldBackupFiles(x).FullName)
>> > Next
>> > End If
>>> > '-- copy new set of backups. GV 1/28/05
>>> > '- if no backup files are found, throw an exception.
>> > GV
>> > 6/2/05
>> > If intNewBackupFileCount < 1 Then
>> > Throw New ApplicationException("No files were
>> > found.")
>>> > Else
>> > For x = 0 To intNewBackupFileCount
>> > objCurrentFile = objNewBackupFiles(x)
>> > intFileSize = intFileSize +
>> > objCurrentFile.Length
>> > objCurrentFile.CopyTo(strNewBackupPath & "\"
>> > &
>> > objCurrentFile.Name)
>> > Next
>> > End If
>>> > strEndTime = DateTime.Now.ToLongTimeString()
>>> > '-- write file-copy info to XML log. GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time started
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("starttime")
>> > objNewChildNode.InnerText = strStartTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time ended
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("endtime")
>> > objNewChildNode.InnerText = strEndTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total amount copied (in megs)
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("dataamount")
>> > objNewChildNode.InnerText =
>> > CStr(Math.Round(intFileSize
>> > / 1048576, 2) & " Mb")
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total number of files copied
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("nbroffiles")
>> > objNewChildNode.InnerText =
>> > CStr(intNewBackupFileCount
>> > +
>> > 1)
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > '-- delete entries older than 4 months. GV 1/31/05
>> > objDateNodeList =
>> > objBackUpLog.SelectNodes("/log/logentry/date")
>> > For Each objCurrentDateNode In objDateNodeList
>> > If DateValue(CDate(objCurrentDateNode.InnerXml))
>> > <
>> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
>> > objCurrentDateNode.RemoveAll()
>> > objRootNode =
>> > objCurrentDateNode.ParentNode.ParentNode
>>> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
>> > End If
>> > Next
>>> > '-- save changes. GV 1/31/05
>> > objBackUpLog.Save(strBackUpLogPath)
>> > intOperationSuccess = 1
>> > Catch exc As Exception
>> > '-- if exception occurs, write error info to XML
>> > log.
>> > GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error header
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errorheader")
>> > objNewChildNode.InnerText = "** ERROR **"
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error description
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errordescription")
>> > objNewChildNode.InnerText = exc.Message.ToString
>> > objNewParentNode.AppendChild(objNewChildNode)
>> > objBackUpLog.Save(strBackUpLogPath)
>> > objEventLog.WriteEntry("**** ERROR **** " &
>> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
>> > intOperationSuccess = 0
>> > '--
>> > Finally
>> > '-- destroy all objects. GV 1/28/05
>> > x = Nothing
>> > intFileSize = Nothing
>> > intLogEntryCount = Nothing
>> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
>> > Nothing
>> > If Not (objCurrentFile Is Nothing) Then
>> > objCurrentFile
>> > =
>> > Nothing
>> > intNewBackupFileCount = Nothing
>> > If Not (objNewBackupFiles Is Nothing) Then
>> > objNewBackupFiles = Nothing
>> > If Not (objOldBackupFiles Is Nothing) Then
>> > objOldBackupFiles = Nothing
>> > If Not (objToDirectory Is Nothing) Then
>> > objToDirectory
>> > =
>> > Nothing
>> > If Not (strNewBackupPath Is Nothing) Then
>> > strNewBackupPath = Nothing
>> > If Not (objFromDirectory Is Nothing) Then
>> > objFromDirectory = Nothing
>> > If Not (strStartTime Is Nothing) Then strStartTime =
>> > Nothing
>> > If Not (strEndTime Is Nothing) Then strEndTime =
>> > Nothing
>> > If Not (objRootNode Is Nothing) Then objRootNode =
>> > Nothing
>> > If Not (objNewParentNode Is Nothing) Then
>> > objNewParentNode = Nothing
>> > If Not (objNewChildNode Is Nothing) Then
>> > objNewChildNode
>> > = Nothing
>> > If Not (objDateNodeList Is Nothing) Then
>> > objDateNodeList
>> > = Nothing
>> > If Not (objCurrentDateNode Is Nothing) Then
>> > objCurrentDateNode = Nothing
>> > If Not (objLogEntryDateNode Is Nothing) Then
>> > objLogEntryDateNode = Nothing
>> > If Not (strBackUpLogPath Is Nothing) Then
>> > strBackUpLogPath = Nothing
>> > '--
>> > End Try
>>>
>>
>
Problem solved! All I had to do was set "identity impersonate" to "true" in
my web.config. Thank you so much!
"John Timney (ASP.NET MVP)" wrote:
> Another MVP has written a great article about this
> http://west-wind.com/weblog/posts/1572.aspx
> The crux is (and its a pain to get working) that using Anonymous
> authentication (so no impersonation) the local ASPNET account has to have
> the same credentials (username and password) on both machines in order to
> delegate security. With basic authentication and impersonation you need to
> use a domain account which can delegate and you can check how to mark your
> impersonated account able to use security delegation here:
> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
> This is also required if you want to use NTLM authentication over kerberos
> Personally, I would implement a the remote server as an http device and use
> http requests, checking the referrer whihc makes life a lot simpler than
> using mapped network drives.
> --
> Regards
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
> >I have an aspx page that is set up to copy backed-up DB files from a shared
> > directory to a local folder. For some reason, it is being denied access to
> > the network share. I have the web app running under a domain account that
> > I
> > know for a fact has access. it works fine when I log on to the network and
> > browse the directory manually. Even when I grant full control to everyone
> > on
> > the share and the underlying folder itself, I still can't access it
> > through
> > code. The funny thing is though, this same code works fine when executed
> > within a windows service which runs under the same domain account. Help!
> > Code follows:
> > **** this first line is the one throwing the exception ********
> > Dim objFromDirectory As DirectoryInfo = New
> > DirectoryInfo("\\[server]\[network share]
> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> > Dim objToDirectory As DirectoryInfo = New
> > DirectoryInfo(strNewBackupPath)
> > Dim objOldBackupFiles() As FileInfo =
> > objToDirectory.GetFiles()
> > Dim objNewBackupFiles() As FileInfo =
> > objFromDirectory.GetFiles()
> > Dim x As Integer
> > Dim intNewBackupFileCount As Integer =
> > UBound(objNewBackupFiles)
> > Dim objCurrentFile As FileInfo
> > Dim objBackUpLog As XmlDocument = New XmlDocument
> > Dim objNewParentNode As XmlElement
> > Dim objRootNode As XmlElement
> > Dim objLogEntryDateNode As XmlElement
> > Dim objNewChildNode As XmlElement
> > Dim objDateNodeList As XmlNodeList
> > Dim strStartTime As String
> > Dim strEndTime As String
> > Dim intFileSize As Integer = 0
> > Dim intLogEntryCount As Integer
> > Dim strBackUpLogPath As String =
> > "C:\SQLBackUp\SQLBackupLog.xml"
> > Dim objCurrentDateNode As XmlElement
> > Try
> > strStartTime = DateTime.Now.ToLongTimeString()
> > '-- delete old set of backups. GV 1/28/05
> > If UBound(objOldBackupFiles) > 0 Then
> > For x = 0 To UBound(objOldBackupFiles)
> > File.Delete(objOldBackupFiles(x).FullName)
> > Next
> > End If
> > '-- copy new set of backups. GV 1/28/05
> > '- if no backup files are found, throw an exception. GV
> > 6/2/05
> > If intNewBackupFileCount < 1 Then
> > Throw New ApplicationException("No files were
> > found.")
> > Else
> > For x = 0 To intNewBackupFileCount
> > objCurrentFile = objNewBackupFiles(x)
> > intFileSize = intFileSize +
> > objCurrentFile.Length
> > objCurrentFile.CopyTo(strNewBackupPath & "\" &
> > objCurrentFile.Name)
> > Next
> > End If
> > strEndTime = DateTime.Now.ToLongTimeString()
> > '-- write file-copy info to XML log. GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time started
> > objNewChildNode =
> > objBackUpLog.CreateElement("starttime")
> > objNewChildNode.InnerText = strStartTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time ended
> > objNewChildNode = objBackUpLog.CreateElement("endtime")
> > objNewChildNode.InnerText = strEndTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total amount copied (in megs)
> > objNewChildNode =
> > objBackUpLog.CreateElement("dataamount")
> > objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> > / 1048576, 2) & " Mb")
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total number of files copied
> > objNewChildNode =
> > objBackUpLog.CreateElement("nbroffiles")
> > objNewChildNode.InnerText = CStr(intNewBackupFileCount
> > +
> > 1)
> > objNewParentNode.AppendChild(objNewChildNode)
> > '-- delete entries older than 4 months. GV 1/31/05
> > objDateNodeList =
> > objBackUpLog.SelectNodes("/log/logentry/date")
> > For Each objCurrentDateNode In objDateNodeList
> > If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
> > objCurrentDateNode.RemoveAll()
> > objRootNode =
> > objCurrentDateNode.ParentNode.ParentNode
> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> > End If
> > Next
> > '-- save changes. GV 1/31/05
> > objBackUpLog.Save(strBackUpLogPath)
> > intOperationSuccess = 1
> > Catch exc As Exception
> > '-- if exception occurs, write error info to XML log.
> > GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error header
> > objNewChildNode =
> > objBackUpLog.CreateElement("errorheader")
> > objNewChildNode.InnerText = "** ERROR **"
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error description
> > objNewChildNode =
> > objBackUpLog.CreateElement("errordescription")
> > objNewChildNode.InnerText = exc.Message.ToString
> > objNewParentNode.AppendChild(objNewChildNode)
> > objBackUpLog.Save(strBackUpLogPath)
> > objEventLog.WriteEntry("**** ERROR **** " &
> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> > intOperationSuccess = 0
> > '--
> > Finally
> > '-- destroy all objects. GV 1/28/05
> > x = Nothing
> > intFileSize = Nothing
> > intLogEntryCount = Nothing
> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> > Nothing
> > If Not (objCurrentFile Is Nothing) Then objCurrentFile
> > =
> > Nothing
> > intNewBackupFileCount = Nothing
> > If Not (objNewBackupFiles Is Nothing) Then
> > objNewBackupFiles = Nothing
> > If Not (objOldBackupFiles Is Nothing) Then
> > objOldBackupFiles = Nothing
> > If Not (objToDirectory Is Nothing) Then objToDirectory
> > =
> > Nothing
> > If Not (strNewBackupPath Is Nothing) Then
> > strNewBackupPath = Nothing
> > If Not (objFromDirectory Is Nothing) Then
> > objFromDirectory = Nothing
> > If Not (strStartTime Is Nothing) Then strStartTime =
> > Nothing
> > If Not (strEndTime Is Nothing) Then strEndTime =
> > Nothing
> > If Not (objRootNode Is Nothing) Then objRootNode =
> > Nothing
> > If Not (objNewParentNode Is Nothing) Then
> > objNewParentNode = Nothing
> > If Not (objNewChildNode Is Nothing) Then
> > objNewChildNode
> > = Nothing
> > If Not (objDateNodeList Is Nothing) Then
> > objDateNodeList
> > = Nothing
> > If Not (objCurrentDateNode Is Nothing) Then
> > objCurrentDateNode = Nothing
> > If Not (objLogEntryDateNode Is Nothing) Then
> > objLogEntryDateNode = Nothing
> > If Not (strBackUpLogPath Is Nothing) Then
> > strBackUpLogPath = Nothing
> > '--
> > End Try
>
glad your sorted :)
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:CCC31167-8012-4FC7-9EC7-3F125F515339@.microsoft.com...
> Problem solved! All I had to do was set "identity impersonate" to "true"
> in
> my web.config. Thank you so much!
> "John Timney (ASP.NET MVP)" wrote:
>> Another MVP has written a great article about this
>> http://west-wind.com/weblog/posts/1572.aspx
>>
>> The crux is (and its a pain to get working) that using Anonymous
>> authentication (so no impersonation) the local ASPNET account has to have
>> the same credentials (username and password) on both machines in order to
>> delegate security. With basic authentication and impersonation you need
>> to
>> use a domain account which can delegate and you can check how to mark
>> your
>> impersonated account able to use security delegation here:
>> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
>> This is also required if you want to use NTLM authentication over
>> kerberos
>>
>> Personally, I would implement a the remote server as an http device and
>> use
>> http requests, checking the referrer whihc makes life a lot simpler than
>> using mapped network drives.
>> --
>> Regards
>>
>> John Timney
>> ASP.NET MVP
>> Microsoft Regional Director
>>
>> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
>> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>> >I have an aspx page that is set up to copy backed-up DB files from a
>> >shared
>> > directory to a local folder. For some reason, it is being denied access
>> > to
>> > the network share. I have the web app running under a domain account
>> > that
>> > I
>> > know for a fact has access. it works fine when I log on to the network
>> > and
>> > browse the directory manually. Even when I grant full control to
>> > everyone
>> > on
>> > the share and the underlying folder itself, I still can't access it
>> > through
>> > code. The funny thing is though, this same code works fine when
>> > executed
>> > within a windows service which runs under the same domain account.
>> > Help!
>>> > Code follows:
>>> > **** this first line is the one throwing the exception ********
>> > Dim objFromDirectory As DirectoryInfo = New
>> > DirectoryInfo("\\[server]\[network share]
>>>> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
>> > Dim objToDirectory As DirectoryInfo = New
>> > DirectoryInfo(strNewBackupPath)
>> > Dim objOldBackupFiles() As FileInfo =
>> > objToDirectory.GetFiles()
>> > Dim objNewBackupFiles() As FileInfo =
>> > objFromDirectory.GetFiles()
>> > Dim x As Integer
>> > Dim intNewBackupFileCount As Integer =
>> > UBound(objNewBackupFiles)
>> > Dim objCurrentFile As FileInfo
>> > Dim objBackUpLog As XmlDocument = New XmlDocument
>> > Dim objNewParentNode As XmlElement
>> > Dim objRootNode As XmlElement
>> > Dim objLogEntryDateNode As XmlElement
>> > Dim objNewChildNode As XmlElement
>> > Dim objDateNodeList As XmlNodeList
>> > Dim strStartTime As String
>> > Dim strEndTime As String
>> > Dim intFileSize As Integer = 0
>> > Dim intLogEntryCount As Integer
>> > Dim strBackUpLogPath As String =
>> > "C:\SQLBackUp\SQLBackupLog.xml"
>> > Dim objCurrentDateNode As XmlElement
>> > Try
>> > strStartTime = DateTime.Now.ToLongTimeString()
>>> > '-- delete old set of backups. GV 1/28/05
>> > If UBound(objOldBackupFiles) > 0 Then
>> > For x = 0 To UBound(objOldBackupFiles)
>> > File.Delete(objOldBackupFiles(x).FullName)
>> > Next
>> > End If
>>> > '-- copy new set of backups. GV 1/28/05
>>> > '- if no backup files are found, throw an exception.
>> > GV
>> > 6/2/05
>> > If intNewBackupFileCount < 1 Then
>> > Throw New ApplicationException("No files were
>> > found.")
>>> > Else
>> > For x = 0 To intNewBackupFileCount
>> > objCurrentFile = objNewBackupFiles(x)
>> > intFileSize = intFileSize +
>> > objCurrentFile.Length
>> > objCurrentFile.CopyTo(strNewBackupPath & "\"
>> > &
>> > objCurrentFile.Name)
>> > Next
>> > End If
>>> > strEndTime = DateTime.Now.ToLongTimeString()
>>> > '-- write file-copy info to XML log. GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time started
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("starttime")
>> > objNewChildNode.InnerText = strStartTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time ended
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("endtime")
>> > objNewChildNode.InnerText = strEndTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total amount copied (in megs)
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("dataamount")
>> > objNewChildNode.InnerText =
>> > CStr(Math.Round(intFileSize
>> > / 1048576, 2) & " Mb")
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total number of files copied
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("nbroffiles")
>> > objNewChildNode.InnerText =
>> > CStr(intNewBackupFileCount
>> > +
>> > 1)
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > '-- delete entries older than 4 months. GV 1/31/05
>> > objDateNodeList =
>> > objBackUpLog.SelectNodes("/log/logentry/date")
>> > For Each objCurrentDateNode In objDateNodeList
>> > If DateValue(CDate(objCurrentDateNode.InnerXml))
>> > <
>> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
>> > objCurrentDateNode.RemoveAll()
>> > objRootNode =
>> > objCurrentDateNode.ParentNode.ParentNode
>>> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
>> > End If
>> > Next
>>> > '-- save changes. GV 1/31/05
>> > objBackUpLog.Save(strBackUpLogPath)
>> > intOperationSuccess = 1
>> > Catch exc As Exception
>> > '-- if exception occurs, write error info to XML
>> > log.
>> > GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error header
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errorheader")
>> > objNewChildNode.InnerText = "** ERROR **"
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error description
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errordescription")
>> > objNewChildNode.InnerText = exc.Message.ToString
>> > objNewParentNode.AppendChild(objNewChildNode)
>> > objBackUpLog.Save(strBackUpLogPath)
>> > objEventLog.WriteEntry("**** ERROR **** " &
>> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
>> > intOperationSuccess = 0
>> > '--
>> > Finally
>> > '-- destroy all objects. GV 1/28/05
>> > x = Nothing
>> > intFileSize = Nothing
>> > intLogEntryCount = Nothing
>> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
>> > Nothing
>> > If Not (objCurrentFile Is Nothing) Then
>> > objCurrentFile
>> > =
>> > Nothing
>> > intNewBackupFileCount = Nothing
>> > If Not (objNewBackupFiles Is Nothing) Then
>> > objNewBackupFiles = Nothing
>> > If Not (objOldBackupFiles Is Nothing) Then
>> > objOldBackupFiles = Nothing
>> > If Not (objToDirectory Is Nothing) Then
>> > objToDirectory
>> > =
>> > Nothing
>> > If Not (strNewBackupPath Is Nothing) Then
>> > strNewBackupPath = Nothing
>> > If Not (objFromDirectory Is Nothing) Then
>> > objFromDirectory = Nothing
>> > If Not (strStartTime Is Nothing) Then strStartTime =
>> > Nothing
>> > If Not (strEndTime Is Nothing) Then strEndTime =
>> > Nothing
>> > If Not (objRootNode Is Nothing) Then objRootNode =
>> > Nothing
>> > If Not (objNewParentNode Is Nothing) Then
>> > objNewParentNode = Nothing
>> > If Not (objNewChildNode Is Nothing) Then
>> > objNewChildNode
>> > = Nothing
>> > If Not (objDateNodeList Is Nothing) Then
>> > objDateNodeList
>> > = Nothing
>> > If Not (objCurrentDateNode Is Nothing) Then
>> > objCurrentDateNode = Nothing
>> > If Not (objLogEntryDateNode Is Nothing) Then
>> > objLogEntryDateNode = Nothing
>> > If Not (strBackUpLogPath Is Nothing) Then
>> > strBackUpLogPath = Nothing
>> > '--
>> > End Try
>>>
>>
>
System.IO.StreamWriter -- Access to path is denied
(Win XP Pro)
Hi, u need to add aspNet User to the folder u trying to accessing and give the account have the permission to write/read it in the folder or file.
System.IO.StreamWriter writer = new System.IO.StreamWriter(@dotnet.itags.org."C:\NetApplicationTest",true);
If u cant see any security tab on ur folder option, do tis below in any folder:
Tools>Folder Options>View>uncheck this "use simple file sharing(Recommended)"
then go to ur file's folder , note: folder
right click then properties> Security>Add > Advance> Find now>
Then u select ASPNET and add it, and set ASPNET to full control.
Hope tis help
life's Ng
beauty, thanks very much! -- I guess that I should study some XP Admin stuff... thanks 'gain ..
Tuesday, March 13, 2012
System.security.securityException: Permission denied in ASP.NET
I have to write into an Excel file through my web application. I wrote a program in VB6 which executes the tasks I need to do on the Excel file, and saved it as a .dll. This .dll was than added into the reference of the web application and it was also registered using regsvr32. When I execute this form then I get the following error:
System.security.securityException: Permission denied.
But, when I create the same form as a Windows application, add the reference & register .dll, then the code gets executed and we are able to make the required changes in the excel file.
Plz help me solve this problem.
Thanks,
JavvymDefinitely a permissions error,
Using windows explorer navigate to the folder where your excel file is stored right click the folder choose properies
Select the Security Tab
Add in Authenticated Users, if that doesn't work add the Everyone group
Try running the code again - should work :wave:
Cheers Al
Hi,
This solution doesn't solve the problem. Is there any other solution that you can give me?
Thanks,
Javvym
First thing; I forgot to say to give the groups write Permissions, if you didn't do that then try the below
Remove the Everyone, and Authenticated Users unless they were already there. If they were already there then remove the write permissions.
On the security tab for the folder in question add in the ASPNet account give the user write permissions
W2K - select the machine name from the top dropdown list, then pick ASPNet from the list
XP - In the "Enter the Object names..." box enter the following [your machine name]\aspnet click check names
Once you've got the account click ok - give the ASPNet account write permissions.
Click Apply/Ok and try again
With a bit of luck you'll have won.
Cheers Al
System.Security.SecurityException: Permission denied Error while invoking methods in a Com
I am getting an error while trying to create an excel file.
"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: Permission denied"
This is what I am doing. we had an app that was written in VB to take
specific dates and create an excel file.
I am using the dll in my .NET app but it displays the error while writing
the file...
I am sure that I have used regsrv32 to register the DLL
any suggestions,
Stephenyou said you are using the COM server DLL directly in .net? If thats
what you are doing.. you need to create an interop assembly before you
can access the methods in that dll
Please let me know if I understoof your question incorrectly
stephen wrote:
Quote:
Originally Posted by
Hi,
I am getting an error while trying to create an excel file.
"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: Permission denied"
>
This is what I am doing. we had an app that was written in VB to take
specific dates and create an excel file.
I am using the dll in my .NET app but it displays the error while writing
the file...
>
I am sure that I have used regsrv32 to register the DLL
>
any suggestions,
Stephen
Are you trying to run the application over the network? If so, see
http://blogs.msdn.com/shawnfa/archi...6/20/57023.aspx. (If you're
using version 2.0 of the .NET framework, ClickOnce is another option for
permissions elevation.)
If you're not attempting to run the applicaiton over the network, could you
please post the complete exception details (including call stack listing),
as returned from its ToString method?
"stephen" <stephen_jn@.hotmail.comwrote in message
news:%23F0g$XxuGHA.324@.TK2MSFTNGP06.phx.gbl...
Quote:
Originally Posted by
>
Hi,
I am getting an error while trying to create an excel file.
"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: Permission denied"
>
This is what I am doing. we had an app that was written in VB to take
specific dates and create an excel file.
I am using the dll in my .NET app but it displays the error while writing
the file...
>
I am sure that I have used regsrv32 to register the DLL
>
any suggestions,
Stephen
>
Hi Kumar and Nicole,
This is how I am working on this project. I have a DLL given to me by
another developer that generates Excel files and he created it using VB6.
I registered it on my box, referenced it and I am trying to use it
This is the error I am getting along with stack trace:
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: Permission denied
[SecurityException: Permission denied]
CBAS_DTStoExcel.CBQueryDTStoExcelClass.set_OutPath (Object ) +0
cbas.QueryDB.ExportToExcel(DateTime dBeginDate, DateTime dEndDate) in
C:\Inetpub\wwwroot\CBAS_Deploy\QueryDB.aspx.vb:74
cbas.QueryDB.btnRunReport_Click(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\CBAS_Deploy\QueryDB.aspx.vb:53
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +2112
System.Web.UI.Page.ProcessRequest() +217
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication+IExecutionStep.Execute()
+179
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +87
"Kumar Reddi" <kumarreddi@.gmail.comwrote in message
news:1155062429.705709.30770@.h48g2000cwc.googlegro ups.com...
Quote:
Originally Posted by
you said you are using the COM server DLL directly in .net? If thats
what you are doing.. you need to create an interop assembly before you
can access the methods in that dll
>
Please let me know if I understoof your question incorrectly
>
stephen wrote:
Quote:
Originally Posted by
>Hi,
>I am getting an error while trying to create an excel file.
>"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: Permission denied"
>>
>This is what I am doing. we had an app that was written in VB to take
>specific dates and create an excel file.
>I am using the dll in my .NET app but it displays the error while writing
>the file...
>>
>I am sure that I have used regsrv32 to register the DLL
>>
>any suggestions,
>Stephen
>
It looks like your ASP.NET application is not probably not running with
unrestricted CAS permissions (aka full trust). Unless you have restricted
CAS permissions via your own application's web.config file, adjusting this
is a task for the server administrator. (If you are in shared hosting, it's
likely that the administrator will be unwilling to increase your
application's permissions, and you may need to move to dedicated hosting.)
"stephen" <stephen_jn@.hotmail.comwrote in message
news:%23DomAH0uGHA.5044@.TK2MSFTNGP05.phx.gbl...
Quote:
Originally Posted by
Hi Kumar and Nicole,
>
This is how I am working on this project. I have a DLL given to me by
another developer that generates Excel files and he created it using VB6.
I registered it on my box, referenced it and I am trying to use it
This is the error I am getting along with stack trace:
>
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: Permission denied
>
>
[SecurityException: Permission denied]
CBAS_DTStoExcel.CBQueryDTStoExcelClass.set_OutPath (Object ) +0
cbas.QueryDB.ExportToExcel(DateTime dBeginDate, DateTime dEndDate) in
C:\Inetpub\wwwroot\CBAS_Deploy\QueryDB.aspx.vb:74
cbas.QueryDB.btnRunReport_Click(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\CBAS_Deploy\QueryDB.aspx.vb:53
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +2112
System.Web.UI.Page.ProcessRequest() +217
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
>
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication+IExecutionStep.Execute()
+179
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +87
>
>
>
>
>
>
"Kumar Reddi" <kumarreddi@.gmail.comwrote in message
news:1155062429.705709.30770@.h48g2000cwc.googlegro ups.com...
Quote:
Originally Posted by
>you said you are using the COM server DLL directly in .net? If thats
>what you are doing.. you need to create an interop assembly before you
>can access the methods in that dll
>>
>Please let me know if I understoof your question incorrectly
>>
>stephen wrote:
Quote:
Originally Posted by
>>Hi,
>>I am getting an error while trying to create an excel file.
>>"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: Permission denied"
>>>
>>This is what I am doing. we had an app that was written in VB to take
>>specific dates and create an excel file.
>>I am using the dll in my .NET app but it displays the error while
>>writing
>>the file...
>>>
>>I am sure that I have used regsrv32 to register the DLL
>>>
>>any suggestions,
>>Stephen
>>
>
>