Saturday, March 31, 2012
System.InvalidCastException
PAGE.ASPX
private class Blah
public bVar as boolean
end class
On page load this class is added to the collection ColBlah and sent to the
function in business layer which has identical class defined.
BusLayer.vb
private class Blah
bVar as boolean
end class
class BusLayer
Public function Process(oCol as collection)
dim oObject, oBlah as Blah
for each oObject in oCol
oBlah=CType(oObject,Blah)
next oCol
end class
the line oBlah=CType(oObject,Blah) generates the following exception
System.InvalidCastException
Why? Anybody?A class can't exist in two places at the same time. Just because they have
the same name and share all the same members, doesn't make them the same.
As far as .NET is concerned, you might as well be trying to cast a textbox
to a database connection.
This class should be defined in your business layer ONLY...and your aspx
page should create an instance of THAT class.
Karl
http://www.openmymind.net/
http://www.codebetter.com/
"Mike Kansky" <MikeKansky@.discussions.microsoft.com> wrote in message
news:8DD38BB8-E1A6-4C92-8629-918A5F3FAC83@.microsoft.com...
>I have UI Page.aspx which has this class:
> PAGE.ASPX
> private class Blah
> public bVar as boolean
> end class
>
> On page load this class is added to the collection ColBlah and sent to the
> function in business layer which has identical class defined.
> BusLayer.vb
> private class Blah
> bVar as boolean
> end class
> class BusLayer
> Public function Process(oCol as collection)
> dim oObject, oBlah as Blah
> for each oObject in oCol
> oBlah=CType(oObject,Blah)
> next oCol
> end class
> the line oBlah=CType(oObject,Blah) generates the following exception
> System.InvalidCastException
> Why? Anybody?
>
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.File class and IP paths?
"\\10.100.100.1\myfolder\test.txt"
When running the aspx file on the server (the server is
also the client) it works, but when using another NT
client it does not work.
The err.description says "Could not find file ..."
System.IO.File.Exists return false here.
But If I manually paste in \\10.100.100.1
\myfolder\test.txt in the IE address field and press "Go"
the file is found.
Strange or not?Hi,
I don't think that the default asp.net user got rights to access network
resources.
Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Monday, March 26, 2012
system.net.mail network host cache?
I need to change the name of the mail server for my .NET application. I changed it in web.config and on the .aspx page that sends the message. However, I still get an error message saying that the remote name could not be resolved, and the error message has the name of theold mail server. I have tried rebooting the server, but still get the same error.
Does .NET save configuration settings somewhere other than web.config? Is something getting cached? Other ideas?
Are you running VS debugger or testing on IIS server?
You can delete all files in cache.
Do you use only one config file?
If you have BLL and DAL, sometimes you have also config files here.
Visit this?site.
http://www.systemwebmail.com/
As Johan said, delete your temporary files, and build your web site again
Thanks
Thanks for the responses.
JohanNL, this site is on an IIS server. There is only one web.config file for the site. I did not implement BLL/DAL.
JohanNL and e_screw - this is probably a dumb question - when you say to delete cache/temp files, do you mean the ones in c:\windows\temp? Or what is the correct location?
You need to clear the ASP.NET temporary files
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Thanks
System.Net.Mail RadioButton Capture
I've been working on emailing the results of a form. My pervious post can be found herehttp://forums.asp.net/thread/1515150.aspx THANKS TO ALL FOR YOUR HELP, everything is working well now but I've got one last question.
I've got two RadioButtons, they post back to the db fine, they're working exactly how they should. How do I correctly capture RadioButtons results in the email?
Thanx
Answered my own question
I was using RadioButton.Text I changed it to RadioButton.Checked looks to be working Ok.
Thanx
Saturday, March 24, 2012
System.Net.Sockets.SocketException+webservice+Sourabh Das
I have placed a webservice in the webserver. When I access it from a webpage, default.aspx on a click of a button i get the following error:
No connection could be made because the target machine actively refused it
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
Source Error:
Line 91: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/getProducts", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 92: public System.Data.DataSet getProducts(int productid) {
Line 93: object[] results = this.Invoke("getProducts", new object[] {
Line 94: productid});
Line 95: return ((System.Data.DataSet)(results[0]));
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\6dcecb27\a382a372\App_WebReferences.lgdo8f58.0.cs Line: 93
Stack Trace:
[SocketException (0x274d): No connection could be made because the target machine actively refused it]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +1002082
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetRequestStream() +1504461
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +103
localhost.ProductsService.getProducts(Int32 productid) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\6dcecb27\a382a372\App_WebReferences.lgdo8f58.0.cs:93
_Default.btnCategory_Click(Object sender, EventArgs e) in D:\users\Padmajamvl\arete\www\Default.aspx.vb:40
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
Please tell me what is the error. Its urgent.
Regards."Unable to connect to the remote server"
This means, you must update the web reference to access the web service (Rebuild the WSDL file automatically)
Or the server doesn't allow access to the web service folder (not marked as a web application on IIS)
System.Net.WebClient.DownloadFile doesn't work with http attachments
I have an aspx page at the web server that provides PDF documents for smart
client applications.
Here is the code in aspx page that defines content type:
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename=test.pdf");
I tested the aspx page by using browser and it works just fine.
Now I need to receive that file by using the
System.Net.WebClient.DownloadFile. The problem is that DownloadFile method
returns the following exception:
"Unable to read data from the transport connection: The connection was
closed."
I tested the DownloadFile method to open a direct pdf file like the
following statement:
(new
System.Net.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.pdf
");
It works just fine.
How can I use System.Net.WebClient. DownloadFile to download http
attachments?
Any help would be apprecited,
AlanThe answer is in your question, but you may not recognize it.
An HTTP Request is for a single resource, identified by the URL of the
resource, or in the case of the WebClient, a URI plus a file descriptor. You
have an ASPX page that returns a file with a couple of special Response
Headers in it. Those Response Headers read:
Response.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
"attachment;filename=test.pdf");
This header indicates that the client should prompt the client to make a
second request for the file descriptor specified (text.pdf), and that the
Content-Type of that file is binary.
So, what you have to do is read the Response Headers, and make a second
request for that file specified.
IETF RFC 1806 has a detailed explanation of this Response Header:
http://www.ietf.org/rfc/rfc1806.txt
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
A watched clock never boils.
"A.M-SG" <alanalan@.newsgroup.nospam> wrote in message
news:eY7l5Zu3FHA.1148@.tk2msftngp13.phx.gbl...
> Hi,
> I have an aspx page at the web server that provides PDF documents for
> smart
> client applications.
> Here is the code in aspx page that defines content type:
> Response.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
> "attachment;filename=test.pdf");
> I tested the aspx page by using browser and it works just fine.
> Now I need to receive that file by using the
> System.Net.WebClient.DownloadFile. The problem is that DownloadFile method
> returns the following exception:
> "Unable to read data from the transport connection: The connection was
> closed."
> I tested the DownloadFile method to open a direct pdf file like the
> following statement:
> (new
> System.Net.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.p
df");
> It works just fine.
> How can I use System.Net.WebClient. DownloadFile to download http
> attachments?
> Any help would be apprecited,
> Alan
>
System.Net.WebClient.DownloadFile doesnt work with http attachments
I have an aspx page at the web server that provides PDF documents for smart
client applications.
Here is the code in aspx page that defines content type:
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename=test.pdf");
I tested the aspx page by using browser and it works just fine.
Now I need to receive that file by using the
System.Net.WebClient.DownloadFile. The problem is that DownloadFile method
returns the following exception:
"Unable to read data from the transport connection: The connection was
closed."
I tested the DownloadFile method to open a direct pdf file like the
following statement:
(new
System.Net.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.pdf");
It works just fine.
How can I use System.Net.WebClient. DownloadFile to download http
attachments?
Any help would be apprecited,
AlanThe answer is in your question, but you may not recognize it.
An HTTP Request is for a single resource, identified by the URL of the
resource, or in the case of the WebClient, a URI plus a file descriptor. You
have an ASPX page that returns a file with a couple of special Response
Headers in it. Those Response Headers read:
Response.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
"attachment;filename=test.pdf");
This header indicates that the client should prompt the client to make a
second request for the file descriptor specified (text.pdf), and that the
Content-Type of that file is binary.
So, what you have to do is read the Response Headers, and make a second
request for that file specified.
IETF RFC 1806 has a detailed explanation of this Response Header:
http://www.ietf.org/rfc/rfc1806.txt
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
"A.M-SG" <alanalan@.newsgroup.nospam> wrote in message
news:eY7l5Zu3FHA.1148@.tk2msftngp13.phx.gbl...
> Hi,
> I have an aspx page at the web server that provides PDF documents for
> smart
> client applications.
> Here is the code in aspx page that defines content type:
> Response.ContentType = "application/octet-stream";
> Response.AppendHeader("Content-Disposition",
> "attachment;filename=test.pdf");
> I tested the aspx page by using browser and it works just fine.
> Now I need to receive that file by using the
> System.Net.WebClient.DownloadFile. The problem is that DownloadFile method
> returns the following exception:
> "Unable to read data from the transport connection: The connection was
> closed."
> I tested the DownloadFile method to open a direct pdf file like the
> following statement:
> (new
> System.Net.WebClient()).DownloadFile(http://localhost/test.pdf,"c:\\test.pdf");
> It works just fine.
> How can I use System.Net.WebClient. DownloadFile to download http
> attachments?
> Any help would be apprecited,
> Alan