Wednesday, March 28, 2012
System.IO.FileNotFoundException using file.copy
was wondering if someone here would be willing to take a stab. I am trying
to copy a file to a network drive. I can do it on the web server but not
from a client. Here is the code:
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity
=CType(User.Identity,System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
dim Temp as string="TestFile"
File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
impersonationContext.Undo()
I get the error "System.IO.FileNotFoundException: Could not find file
\\Server\File..." when running it from the [authenticated] client browse
r.
I searched everywhere on the web and MSDN on this error but found nothing.
The error it occurs on the file copy statement The file.copy statement is
trying to copy a file on a different server than the web server.
Any help is appreciated.
P.S. The web server is a backup domain w2k controller also, and the asp.net
user had to be changed to IWAM_Machine.to copy to another server you need to impersonate a primary token, not an
impersonation. to quickly test this, on the actual server, run ie and test -
it should work because the principal will be a primary token, if not, turn
off anonymous.
to get around this, your code will need to logon as a domain account with
enough permission to do the copy.
-- bruce (sqlwork.com)
"Stephen Witter" <switter@.enpathmed.com> wrote in message
news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
> I had previously posted this on the security ng, but haven't had a hit so
I
> was wondering if someone here would be willing to take a stab. I am
trying
> to copy a file to a network drive. I can do it on the web server but not
> from a client. Here is the code:
> Dim impersonationContext As
> System.Security.Principal.WindowsImpersonationContext
> Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity
> currentWindowsIdentity
> =CType(User.Identity,System.Security.Principal.WindowsIdentity)
> impersonationContext = currentWindowsIdentity.Impersonate()
> dim Temp as string="TestFile"
> File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
> impersonationContext.Undo()
> I get the error "System.IO.FileNotFoundException: Could not find file
> \\Server\File..." when running it from the [authenticated] client brow
ser.
> I searched everywhere on the web and MSDN on this error but found nothing.
> The error it occurs on the file copy statement The file.copy statement is
> trying to copy a file on a different server than the web server.
> Any help is appreciated.
> P.S. The web server is a backup domain w2k controller also, and the
asp.net
> user had to be changed to IWAM_Machine.
>
The funny thing is I have tried to run the process from every server, even
the one where the file resides (and where it is being copied to), and they
all give the same message, that is, that the file does not exist. The only
place it works is on the web server. Anonymous access is turn off on the web
site.
I added the following code to test it:
Dim FilePermission As New FileIOPermission(FileIOPermissionAccess.AllAccess,
" \\MyServer\MyShare\SomeDirectory\Templat
e.doc") FilePermission.Assert()
If System.IO.File.Exists(" \\MyServer\MyShare\SomeDirectory\Templat
e.doc")
then
response.write("OK User: ") response.write(User.Identity.Name)
response.end
Else
Try
FilePermission.Demand()
response.write("Exists But Access Denied , User: ")
response.write(User.Identity.Name)
Catch se As Exception
response.write("Realy doesn't exist")
End Try
End If
It always returns "Exists But Access Denied , User: DOMAIN\User"
Thanks for your reply though. I know these situations can be caused by alot
of different factors.
"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:u3sAi2OREHA.2716@.tk2msftngp13.phx.gbl...
> to copy to another server you need to impersonate a primary token, not an
> impersonation. to quickly test this, on the actual server, run ie and
test -
> it should work because the principal will be a primary token, if not, turn
> off anonymous.
> to get around this, your code will need to logon as a domain account with
> enough permission to do the copy.
> -- bruce (sqlwork.com)
> "Stephen Witter" <switter@.enpathmed.com> wrote in message
> news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
so
> I
> trying
not
> System.Security.Principal.WindowsIdentity
browser.
nothing.
is
> asp.net
>
System.IO.FileNotFoundException using file.copy
was wondering if someone here would be willing to take a stab. I am trying
to copy a file to a network drive. I can do it on the web server but not
from a client. Here is the code:
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity
=CType(User.Identity,System.Security.Principal.Win dowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
dim Temp as string="TestFile"
File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
impersonationContext.Undo()
I get the error "System.IO.FileNotFoundException: Could not find file
\\Server\File..." when running it from the [authenticated] client browser.
I searched everywhere on the web and MSDN on this error but found nothing.
The error it occurs on the file copy statement The file.copy statement is
trying to copy a file on a different server than the web server.
Any help is appreciated.
P.S. The web server is a backup domain w2k controller also, and the asp.net
user had to be changed to IWAM_Machine.to copy to another server you need to impersonate a primary token, not an
impersonation. to quickly test this, on the actual server, run ie and test -
it should work because the principal will be a primary token, if not, turn
off anonymous.
to get around this, your code will need to logon as a domain account with
enough permission to do the copy.
-- bruce (sqlwork.com)
"Stephen Witter" <switter@.enpathmed.com> wrote in message
news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
> I had previously posted this on the security ng, but haven't had a hit so
I
> was wondering if someone here would be willing to take a stab. I am
trying
> to copy a file to a network drive. I can do it on the web server but not
> from a client. Here is the code:
> Dim impersonationContext As
> System.Security.Principal.WindowsImpersonationCont ext
> Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity
> currentWindowsIdentity
> =CType(User.Identity,System.Security.Principal.Win dowsIdentity)
> impersonationContext = currentWindowsIdentity.Impersonate()
> dim Temp as string="TestFile"
> File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
> impersonationContext.Undo()
> I get the error "System.IO.FileNotFoundException: Could not find file
> \\Server\File..." when running it from the [authenticated] client browser.
> I searched everywhere on the web and MSDN on this error but found nothing.
> The error it occurs on the file copy statement The file.copy statement is
> trying to copy a file on a different server than the web server.
> Any help is appreciated.
> P.S. The web server is a backup domain w2k controller also, and the
asp.net
> user had to be changed to IWAM_Machine.
The funny thing is I have tried to run the process from every server, even
the one where the file resides (and where it is being copied to), and they
all give the same message, that is, that the file does not exist. The only
place it works is on the web server. Anonymous access is turn off on the web
site.
I added the following code to test it:
Dim FilePermission As New FileIOPermission(FileIOPermissionAccess.AllAccess,
"\\MyServer\MyShare\SomeDirectory\Template.doc") FilePermission.Assert()
If System.IO.File.Exists("\\MyServer\MyShare\SomeDirectory\Template.doc")
then
response.write("OK User: ") response.write(User.Identity.Name)
response.end
Else
Try
FilePermission.Demand()
response.write("Exists But Access Denied , User: ")
response.write(User.Identity.Name)
Catch se As Exception
response.write("Realy doesn't exist")
End Try
End If
It always returns "Exists But Access Denied , User: DOMAIN\User"
Thanks for your reply though. I know these situations can be caused by alot
of different factors.
"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:u3sAi2OREHA.2716@.tk2msftngp13.phx.gbl...
> to copy to another server you need to impersonate a primary token, not an
> impersonation. to quickly test this, on the actual server, run ie and
test -
> it should work because the principal will be a primary token, if not, turn
> off anonymous.
> to get around this, your code will need to logon as a domain account with
> enough permission to do the copy.
> -- bruce (sqlwork.com)
> "Stephen Witter" <switter@.enpathmed.com> wrote in message
> news:#XzRmfOREHA.2408@.tk2msftngp13.phx.gbl...
> > I had previously posted this on the security ng, but haven't had a hit
so
> I
> > was wondering if someone here would be willing to take a stab. I am
> trying
> > to copy a file to a network drive. I can do it on the web server but
not
> > from a client. Here is the code:
> > Dim impersonationContext As
> > System.Security.Principal.WindowsImpersonationCont ext
> > Dim currentWindowsIdentity As
> System.Security.Principal.WindowsIdentity
> > currentWindowsIdentity
> > =CType(User.Identity,System.Security.Principal.Win dowsIdentity)
> > impersonationContext = currentWindowsIdentity.Impersonate()
> > dim Temp as string="TestFile"
> > File.Copy("\\MyServer\Template.doc", "\\MyServer\" & Temp &".doc")
> > impersonationContext.Undo()
> > I get the error "System.IO.FileNotFoundException: Could not find file
> > \\Server\File..." when running it from the [authenticated] client
browser.
> > I searched everywhere on the web and MSDN on this error but found
nothing.
> > The error it occurs on the file copy statement The file.copy statement
is
> > trying to copy a file on a different server than the web server.
> > Any help is appreciated.
> > P.S. The web server is a backup domain w2k controller also, and the
> asp.net
> > user had to be changed to IWAM_Machine.
Saturday, March 24, 2012
System.Net.WebPermission Error?
machin. once it's at Magma i run into this error.
Security Exception
Description: The application attempted to perform an operation not
allowed by the security policy. To grant this application the required
permission please contact your system administrator or change the
application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the
permission of type 'System.Net.WebPermission, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 31: //XmlTextReader xmlReader = new
XmlTextReader(RSSURL);
Line 32: DataSet ds = new DataSet();
Line 33: ds.ReadXml(RSSURL); <<<<<<<<<<<<<<<<<error
Line 34: return ds.Tables[2];
Line 35: }
Source File: d:\users\cahrp\html\Controls\MedicalNewsFeeds.ascx .cs
Line: 33
What should i be doing to solve this any help or hints would be
greatley apreciated.
Thanks,
Bilal
www.bilalhamdan.comyou using webclient, or using a web reference, but your website is not
allowed to access http resouces. talk to hoster to supply the permissions.
-- bruce (sqlwork.com)
<bilal.hamdan@.gmail.comwrote in message
news:1155581685.889730.98870@.h48g2000cwc.googlegro ups.com...
Quote:
Originally Posted by
Hi, I' trying to read some RSS feeds and all works fine on the DEV
machin. once it's at Magma i run into this error.
>
Security Exception
Description: The application attempted to perform an operation not
allowed by the security policy. To grant this application the required
>
permission please contact your system administrator or change the
application's trust level in the configuration file.
>
>
Exception Details: System.Security.SecurityException: Request for the
permission of type 'System.Net.WebPermission, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
>
>
Source Error:
>
>
Line 31: //XmlTextReader xmlReader = new
XmlTextReader(RSSURL);
Line 32: DataSet ds = new DataSet();
Line 33: ds.ReadXml(RSSURL); <<<<<<<<<<<<<<<<<error
Line 34: return ds.Tables[2];
Line 35: }
>
>
Source File: d:\users\cahrp\html\Controls\MedicalNewsFeeds.ascx .cs
Line: 33
>
>
>
>
What should i be doing to solve this any help or hints would be
greatley apreciated.
>
Thanks,
Bilal
www.bilalhamdan.com
>
Tuesday, March 13, 2012
System.Security.SecurityException ??
System.Security.SecurityException
i don´t know why.
Could you please help me with this problemHello, there must be some code you're using that is generating this error, could u please post the whole error ? and some code that might be generating this error !!!
System.Security.SecurityException: Requested registry access is not allowed.
the registry
System.Security.SecurityException: Requested registry access is not allowed.
I followed the following article and I still get the error:
http://support.microsoft.com/defaul...kb;en-us;329291
Any suggestions?
ThanksWhen you say write to the registry, do you mean using the EventLog? Or do
you mean explicitly writing to the registry? The account that your ASP.NET
code is running as needs the rights to do whatever you're trying to do. Unde
r
IIS5 it's the local ASPNET account. Under IIS6 it's the local Network Servic
e
account.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> I keep getting this error when my asp.net application tries to write
> into
> the registry
> System.Security.SecurityException: Requested registry access is not
> allowed.
> I followed the following article and I still get the error:
> http://support.microsoft.com/defaul...kb;en-us;329291
> Any suggestions?
> Thanks
>
Actually the problem was that I did not creat the Installet class properly
so Gacutil was unable to create the right permissions for my ASPNET user.
Thanks for your help
"Brock Allen" <ballen@.NOSPAMdevelop.com> wrote in message
news:763197632520356933089056@.msnews.microsoft.com...
> When you say write to the registry, do you mean using the EventLog? Or do
> you mean explicitly writing to the registry? The account that your ASP.NET
> code is running as needs the rights to do whatever you're trying to do.
> Under IIS5 it's the local ASPNET account. Under IIS6 it's the local
> Network Service account.
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
>
System.Security.SecurityException: Requested registry access is not allowed.
the registry
System.Security.SecurityException: Requested registry access is not allowed.
I followed the following article and I still get the error:
http://support.microsoft.com/defaul...kb;en-us;329291
Any suggestions?
ThanksWhen you say write to the registry, do you mean using the EventLog? Or do
you mean explicitly writing to the registry? The account that your ASP.NET
code is running as needs the rights to do whatever you're trying to do. Under
IIS5 it's the local ASPNET account. Under IIS6 it's the local Network Service
account.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> I keep getting this error when my asp.net application tries to write
> into
> the registry
> System.Security.SecurityException: Requested registry access is not
> allowed.
> I followed the following article and I still get the error:
> http://support.microsoft.com/defaul...kb;en-us;329291
> Any suggestions?
> Thanks
Actually the problem was that I did not creat the Installet class properly
so Gacutil was unable to create the right permissions for my ASPNET user.
Thanks for your help
"Brock Allen" <ballen@.NOSPAMdevelop.com> wrote in message
news:763197632520356933089056@.msnews.microsoft.com ...
> When you say write to the registry, do you mean using the EventLog? Or do
> you mean explicitly writing to the registry? The account that your ASP.NET
> code is running as needs the rights to do whatever you're trying to do.
> Under IIS5 it's the local ASPNET account. Under IIS6 it's the local
> Network Service account.
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>> I keep getting this error when my asp.net application tries to write
>> into
>> the registry
>> System.Security.SecurityException: Requested registry access is not
>> allowed.
>> I followed the following article and I still get the error:
>> http://support.microsoft.com/defaul...kb;en-us;329291
>>
>> Any suggestions?
>>
>> Thanks
>>