Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Saturday, March 24, 2012

Permission Denied Writing to a file

I'm getting a 'permission denied' error when I try to write to a file. I'm running Windows XP Professions, FAT32, and I've set the aspnet user to be an administrator. And I still get this error. I know it's not that the folder doesn't exist, because if I change the path to one that doesn't exist I get the appropriate error that it doesn't exist.

Help.

buzzWow! I hope this server is not exposed to the Internet in any way.
First, you should use NTFS and not FAT32 (there are no permissions on FAT32 disks).
And making ASPNET an administrator is something you should never do. You could edit the machine.config file instead and make the process use SYSTEM instead of ASPNET. I don't even recommend doing this, and you should really just give enough rights on the directories to ASPNET so that you can write to your file.
Does this help?
I'm just in development on my desktop for now, which is why it's FAT32, and the only reason why I made the ASPNET account an admin was to troubleshoot my permission denied error. That's why I mentioned it, because even with it being an admin I'm still getting this error.
You should use NTFS on your dev machines too. I doubt that you will be able to sort this one out except if you use NTFS. I haven't checked this, but I wouldn't be surprised if we used low permissions by default if the file system is Fat, as there are no permissions on this file system.
And 'low permissions' means no write permission, ever, anywhere? That would be remarkably restrictive, wouldn't it? Aren't there some IIS settings I can look at? I also went into my app in IIS and gave write permission in there and that didn't work either.

Thanks for your input.

buzz
Once again, I'm not sure about that at all.
But usually, a web site has no need to write files.
And it would be incredibly dangerous to allow writing to an unprotected file system by default.
I strongly recommend you use NTFS in all circumstances. Fat32 is only there for Win9x compatibility.
I see, well I'll look into converting to NTFS.

>> But usually, a web site has no need to write files.

Is this true? I'm not an expert, but what about uploading files, etc? Also, I want to write to a file for logging purposes, for when my database goes down.

Thanks for all your help!

buzz
Yes, that's why I said "usually".
Most sites don't need to upload files. And if you upload, you should do so in a directory that's not acessible from the web, for obvious security reasons, whenever possible. And you should always require reliable authentication when you allow for it.
Logging can be done using the System.Diagnostics namespace, using the standard Windows event logs.

Permission Problem writing to Disk in Asp.NET application

Here's what I need to do:
Due to a bug in Crystal Reports ExportToStream() method I can't stream a
Crystal Reports directly to the client as PDF and I must must use the
Export() and put the the PDF on disk first and stream to the client. That's
just how it is.

Question:
So I need to let the aspx user have write permissions to disk.. NOT GOOD.
How do I solve this? Can I somehow write the PDF to disk in another thread
with other writes? OR are ther other ways around this?

best regards
/Lars NetzelLars

Note : The code below is stripped from a asp.net project using a web
service. This project would relay a binary file from an internal web server
where Crystal reports is installed to an external web server. You will still
need write permissions for the directory you want to save to

You could try this, I hope It helps

Stream fs =
rep.ExportToStream(CrystalDecisions.Shared.ExportF ormatType.PortableDocFormat);
byte[] binaryfile = StreamToBinary(fs);
string docLocation = Server.MapPath(null) + @."\Docs\";
SaveFileToServer(binaryfile,docLocation,"my.pdf",DateTime.Now);
Response.Redirect("Docs/"+"my.pdf");

public void SaveFileToServer(byte[] binaryFile, string docPath, string
docName, DateTime fileModifiedDate)
{
Directory.CreateDirectory(docPath);
MemoryStream m = new MemoryStream(binaryFile);
FileStream f = new FileStream(docPath+docName,FileMode.Create);
m.WriteTo(f);
f.Close();
m.Close();
File.SetLastWriteTime(docPath+docName,fileModified Date);
}

public byte[] StreamToBinary(Stream fs)
{
Int32 i = Convert.ToInt32(fs.Length);
byte[] b = new byte[fs.Length];
fs.Read(b,0,i);
fs.Close();
}

"Lars Netzel" <lars.netzel@.NO-SPAM.qlogic.se> wrote in message
news:%23wlKhu8HFHA.3244@.TK2MSFTNGP09.phx.gbl...
> Here's what I need to do:
> Due to a bug in Crystal Reports ExportToStream() method I can't stream a
> Crystal Reports directly to the client as PDF and I must must use the
> Export() and put the the PDF on disk first and stream to the client.
> That's just how it is.
> Question:
> So I need to let the aspx user have write permissions to disk.. NOT GOOD.
> How do I solve this? Can I somehow write the PDF to disk in another thread
> with other writes? OR are ther other ways around this?
> best regards
> /Lars Netzel
Thanks but I can't ExportToStream due to a bug with record and
groupselections in the Crystal Reports Engine. so I can't use that code.

I need to write to disk with other permisisons than the ASPNET user

/Lars

"Kamal Vaghjiani" <kamal@.mortgageuk.com> wrote in message
news:Ok7aI59HFHA.2784@.TK2MSFTNGP09.phx.gbl...
> Lars
> Note : The code below is stripped from a asp.net project using a web
> service. This project would relay a binary file from an internal web
> server where Crystal reports is installed to an external web server. You
> will still need write permissions for the directory you want to save to
> You could try this, I hope It helps
> Stream fs =
> rep.ExportToStream(CrystalDecisions.Shared.ExportF ormatType.PortableDocFormat);
> byte[] binaryfile = StreamToBinary(fs);
> string docLocation = Server.MapPath(null) + @."\Docs\";
> SaveFileToServer(binaryfile,docLocation,"my.pdf",DateTime.Now);
> Response.Redirect("Docs/"+"my.pdf");
> public void SaveFileToServer(byte[] binaryFile, string docPath, string
> docName, DateTime fileModifiedDate)
> {
> Directory.CreateDirectory(docPath);
> MemoryStream m = new MemoryStream(binaryFile);
> FileStream f = new FileStream(docPath+docName,FileMode.Create);
> m.WriteTo(f);
> f.Close();
> m.Close();
> File.SetLastWriteTime(docPath+docName,fileModified Date);
> }
> public byte[] StreamToBinary(Stream fs)
> {
> Int32 i = Convert.ToInt32(fs.Length);
> byte[] b = new byte[fs.Length];
> fs.Read(b,0,i);
> fs.Close();
> }
>
> "Lars Netzel" <lars.netzel@.NO-SPAM.qlogic.se> wrote in message
> news:%23wlKhu8HFHA.3244@.TK2MSFTNGP09.phx.gbl...
>> Here's what I need to do:
>> Due to a bug in Crystal Reports ExportToStream() method I can't stream a
>> Crystal Reports directly to the client as PDF and I must must use the
>> Export() and put the the PDF on disk first and stream to the client.
>> That's just how it is.
>>
>> Question:
>> So I need to let the aspx user have write permissions to disk.. NOT GOOD.
>> How do I solve this? Can I somehow write the PDF to disk in another
>> thread with other writes? OR are ther other ways around this?
>>
>> best regards
>> /Lars Netzel
>>

Permission Problem writing to Disk in Asp.NET application

Here's what I need to do:
Due to a bug in Crystal Reports ExportToStream() method I can't stream a
Crystal Reports directly to the client as PDF and I must must use the
Export() and put the the PDF on disk first and stream to the client. That's
just how it is.
Question:
So I need to let the aspx user have write permissions to disk.. NOT GOOD.
How do I solve this? Can I somehow write the PDF to disk in another thread
with other writes? OR are ther other ways around this?
best regards
/Lars NetzelLars
Note : The code below is stripped from a asp.net project using a web
service. This project would relay a binary file from an internal web server
where Crystal reports is installed to an external web server. You will still
need write permissions for the directory you want to save to
You could try this, I hope It helps
Stream fs =
rep.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocForma
t);
byte[] binaryfile = StreamToBinary(fs);
string docLocation = Server.MapPath(null) + @."\Docs\";
SaveFileToServer(binaryfile,docLocation,
"my.pdf",DateTime.Now);
Response.Redirect("Docs/"+"my.pdf");
public void SaveFileToServer(byte[] binaryFile, string docPath, string
docName, DateTime fileModifiedDate)
{
Directory.CreateDirectory(docPath);
MemoryStream m = new MemoryStream(binaryFile);
FileStream f = new FileStream(docPath+docName,FileMode.Create);
m.WriteTo(f);
f.Close();
m.Close();
File. SetLastWriteTime(docPath+docName,fileMod
ifiedDate);
}
public byte[] StreamToBinary(Stream fs)
{
Int32 i = Convert.ToInt32(fs.Length);
byte[] b = new byte[fs.Length];
fs.Read(b,0,i);
fs.Close();
}
"Lars Netzel" <lars.netzel@.NO-SPAM.qlogic.se> wrote in message
news:%23wlKhu8HFHA.3244@.TK2MSFTNGP09.phx.gbl...
> Here's what I need to do:
> Due to a bug in Crystal Reports ExportToStream() method I can't stream a
> Crystal Reports directly to the client as PDF and I must must use the
> Export() and put the the PDF on disk first and stream to the client.
> That's just how it is.
> Question:
> So I need to let the aspx user have write permissions to disk.. NOT GOOD.
> How do I solve this? Can I somehow write the PDF to disk in another thread
> with other writes? OR are ther other ways around this?
> best regards
> /Lars Netzel
>
Thanks but I can't ExportToStream due to a bug with record and
groupselections in the Crystal Reports Engine. so I can't use that code.
I need to write to disk with other permisisons than the ASPNET user
/Lars
"Kamal Vaghjiani" <kamal@.mortgageuk.com> wrote in message
news:Ok7aI59HFHA.2784@.TK2MSFTNGP09.phx.gbl...
> Lars
> Note : The code below is stripped from a asp.net project using a web
> service. This project would relay a binary file from an internal web
> server where Crystal reports is installed to an external web server. You
> will still need write permissions for the directory you want to save to
> You could try this, I hope It helps
> Stream fs =
> rep.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFor
mat);
> byte[] binaryfile = StreamToBinary(fs);
> string docLocation = Server.MapPath(null) + @."\Docs\";
> SaveFileToServer(binaryfile,docLocation,
"my.pdf",DateTime.Now);
> Response.Redirect("Docs/"+"my.pdf");
> public void SaveFileToServer(byte[] binaryFile, string docPath, string
> docName, DateTime fileModifiedDate)
> {
> Directory.CreateDirectory(docPath);
> MemoryStream m = new MemoryStream(binaryFile);
> FileStream f = new FileStream(docPath+docName,FileMode.Create);
> m.WriteTo(f);
> f.Close();
> m.Close();
> File. SetLastWriteTime(docPath+docName,fileMod
ifiedDate);
> }
> public byte[] StreamToBinary(Stream fs)
> {
> Int32 i = Convert.ToInt32(fs.Length);
> byte[] b = new byte[fs.Length];
> fs.Read(b,0,i);
> fs.Close();
> }
>
> "Lars Netzel" <lars.netzel@.NO-SPAM.qlogic.se> wrote in message
> news:%23wlKhu8HFHA.3244@.TK2MSFTNGP09.phx.gbl...
>

Permissions

By default, IIS denies ASP.NET scripts to write files on the disc and create
folders. What should i do to permit ASP.NET scripts writing, for example, i
n C:\test.txt ?You need to give write (and possibly Change) permissions to the ASPNET
account.
The best way is to do it securely as outline here:
How To Create a Custom Account to Run ASP.NET
http://msdn.microsoft.com/library/e...asp?frame=true
"michael" <michael.1jbh5v@.mail.codecomments.com> wrote in message
news:michael.1jbh5v@.mail.codecomments.com...
> By default, IIS denies ASP.NET scripts to write files on the disc and
> create folders. What should i do to permit ASP.NET scripts writing, for
> example, in C:\test.txt ?
>
> --
> michael
> ---
> Posted via http://www.codecomments.com
> ---
>

Permissions

By default, IIS denies ASP.NET scripts to write files on the disc and
create folders. What should i do to permit ASP.NET scripts writing, for
example, in C:\test.txt ?

--
michael
----------------------
Posted via http://www.codecomments.com
----------------------You need to give write (and possibly Change) permissions to the ASPNET
account.

The best way is to do it securely as outline here:

How To Create a Custom Account to Run ASP.NET

http://msdn.microsoft.com/library/e...asp?frame=true

"michael" <michael.1jbh5v@.mail.codecomments.com> wrote in message
news:michael.1jbh5v@.mail.codecomments.com...
> By default, IIS denies ASP.NET scripts to write files on the disc and
> create folders. What should i do to permit ASP.NET scripts writing, for
> example, in C:\test.txt ?
>
> --
> michael
> ----------------------
> Posted via http://www.codecomments.com
> ----------------------

Wednesday, March 21, 2012

Permissions to call LogonUser

I have been troubleshooting writing a log file to a fileshare on
another machine... and I can't seem to find my way past the "Double
Hop" issue. I seem have narrowed it down to a failure of the
LogonUser call. On Windows 2000 with IIS 5 and ASP.NET 2.0 the
LogonUser call returns 0. From a Windows Forms client I can get the
LogonUser call to work fine (returns 1).
So what allows me to call LogonUser? Is there something I need to do
in the web.config or machine.config? I already tried the change where
you give ASPNET account the right to "Act as part of the OS".
Any other ideas? Articles? I'd like to get this working under IIS 5 if
possible.
Kelly Greer
kellygreer1@dotnet.itags.org.nospam.com
change nospam to yahooyou may need to revert to the process token, to allow impersonation.
RevertToSelf();
before calling logon
-- bruce (sqlwork.com)
"kellygreer1" wrote:

> I have been troubleshooting writing a log file to a fileshare on
> another machine... and I can't seem to find my way past the "Double
> Hop" issue. I seem have narrowed it down to a failure of the
> LogonUser call. On Windows 2000 with IIS 5 and ASP.NET 2.0 the
> LogonUser call returns 0. From a Windows Forms client I can get the
> LogonUser call to work fine (returns 1).
> So what allows me to call LogonUser? Is there something I need to do
> in the web.config or machine.config? I already tried the change where
> you give ASPNET account the right to "Act as part of the OS".
> Any other ideas? Articles? I'd like to get this working under IIS 5 if
> possible.
> Kelly Greer
> kellygreer1@.nospam.com
> change nospam to yahoo
>

Permissions to call LogonUser

I have been troubleshooting writing a log file to a fileshare on
another machine... and I can't seem to find my way past the "Double
Hop" issue. I seem have narrowed it down to a failure of the
LogonUser call. On Windows 2000 with IIS 5 and ASP.NET 2.0 the
LogonUser call returns 0. From a Windows Forms client I can get the
LogonUser call to work fine (returns 1).

So what allows me to call LogonUser? Is there something I need to do
in the web.config or machine.config? I already tried the change where
you give ASPNET account the right to "Act as part of the OS".

Any other ideas? Articles? I'd like to get this working under IIS 5 if
possible.

Kelly Greer
kellygreer1@dotnet.itags.org.nospam.com
change nospam to yahooyou may need to revert to the process token, to allow impersonation.

RevertToSelf();

before calling logon

-- bruce (sqlwork.com)

"kellygreer1" wrote:

Quote:

Originally Posted by

I have been troubleshooting writing a log file to a fileshare on
another machine... and I can't seem to find my way past the "Double
Hop" issue. I seem have narrowed it down to a failure of the
LogonUser call. On Windows 2000 with IIS 5 and ASP.NET 2.0 the
LogonUser call returns 0. From a Windows Forms client I can get the
LogonUser call to work fine (returns 1).
>
So what allows me to call LogonUser? Is there something I need to do
in the web.config or machine.config? I already tried the change where
you give ASPNET account the right to "Act as part of the OS".
>
Any other ideas? Articles? I'd like to get this working under IIS 5 if
possible.
>
Kelly Greer
kellygreer1@.nospam.com
change nospam to yahoo
>