Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > System.IO.Directoryinfo throwing exception

Reply
Thread Tools

System.IO.Directoryinfo throwing exception

 
 
=?Utf-8?B?R2xlbm4gVmVuemtl?=
Guest
Posts: n/a
 
      07-25-2005
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

 
Reply With Quote
 
 
 
 
John Timney \(ASP.NET MVP\)
Guest
Posts: n/a
 
      07-25-2005
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/de...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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2xlbm4gVmVuemtl?=
Guest
Posts: n/a
 
      07-25-2005
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/de...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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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
> >

>
>
>

 
Reply With Quote
 
John Timney \(ASP.NET MVP\)
Guest
Posts: n/a
 
      07-25-2005
glad your sorted

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Glenn Venzke" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/de...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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >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
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert.aspx throwing exception =?Utf-8?B?RXVzdGljZSBTY3J1YmI=?= ASP .Net 0 09-23-2005 03:51 AM
WebRequest.GetResponse() throwing exception (Internal Server error =?Utf-8?B?VGVycnk=?= ASP .Net 4 01-13-2005 10:25 PM
Problem of throwing an exception (System.Net.Sockets.OverlappedAsyncResult::CompletionPortCallback) VincentWong ASP .Net 1 12-29-2003 09:32 AM
Throwing Exception in a composite control KJ ASP .Net 5 07-25-2003 01:33 PM
Re: Is there an overhead in throwing an Exception instead of SQLException? John C. Bollinger Java 3 07-17-2003 06:46 AM



Advertisments