Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Monday, March 26, 2012

Performing an Operation Once a Day

I want to write a script that runs just once in a day.
Like i want to add a poll of the day or send all emails after one day or something like that then how can i do?
I thought of threading but if the web application closes and then on its start how would it know if the actions have been taken? do I have to store them in some files like last poll update time etc.
Is there a better way of doing this? Moreover can i make a class that is visible to all the sessions (just like application variables) and any script can call that class or its member functions.There are several ways to go about this. You could have the web app fire the tasks (yes, you'd have to store the status in a file or database somewhere), but because ASP.NET may restart itself, the application may shut down, etc., you won't be able to control when your daily processes run. If you are simply adding content to a database, you might choose to schedule a database job to run at a specific time. You could use the Windows scheduler to fire off an exe or to run some VBScript via WSH at a predetermined time. Or, you may choose to create a Windows service to coordinate execution of each task.
To answer your second question: yes, you can create a class that is visible to all sessions. A class built using the singleton design pattern will accomplish this, with the side-effect of also being accesible to your non-HttpContext daily tasks.

Thanks for the reply.
Yes, choosing a database schedule is suitable for database jobs. I dont have direct access to my server ( i have shared hosting), so i dont think i can write a windows scheduler. Moreover i would like to write a generic script that will work on any client machine.
I didnt quite understand the second point. What is a class built on a singleton design? The side effect that it is accessible to non httpcontext tasks mean it can be accessed without the http request also?
I did the same thing with an application I wrote, this was delivered on a shared hosting plan.
I added a little script to the homepage which checked if todaysactivity had been completed, if not, it did it and then changed theflag.
Of course, someone had to visit the homepage at least once a day - butthat wasn't a problem, since the customer visited it every hour anyway.
We had two versions - one which stored data in a database, another stored the flag in an XML file.

Ya this is a good idea. I had thought of making a page that the web team will visit each day, which will execute the scripts. This way i can perform the operations.
Is it possible to make a class that sends email. This must be visible to the entire application. How can i do that?
Yes, things will get a bit trickier in a shared hosting environment. Your only option may be to have a page check a status flag and kickoff the script as has been suggested and, as long as thight scheduling is not required, should work just fine.
A singleton class can only ever have one instance, meaning that data can be easily shared between objects, etc. The advantage to using this approach versus the ASP.NET Application object is that other, non-web pieces of your application can gain access to the object. If you'd like to learn more about singleton, referenceDesign Patterns or theMS P&P website.


Thanks. The link was of great help.

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 to write a file

Hi all
I'm coding a Web application which requires to write an XML file into a
folder. I'm wondering other than account Everyone which else I can set
permission so that my application can have the rights to write the file.You have to set permissions on the user that asp.net is working on.
By default it is ASPNET
Regards
Martin
"Hai Nguyen" <haiaggie@.neo.tamu.edu> wrote in message
news:ueILnPGVEHA.1048@.tk2msftngp13.phx.gbl...
> Hi all
> I'm coding a Web application which requires to write an XML file into a
> folder. I'm wondering other than account Everyone which else I can set
> permission so that my application can have the rights to write the file.
>
>

Permission to write a file

Hi all

I'm coding a Web application which requires to write an XML file into a
folder. I'm wondering other than account Everyone which else I can set
permission so that my application can have the rights to write the file.You have to set permissions on the user that asp.net is working on.
By default it is ASPNET

Regards
Martin

"Hai Nguyen" <haiaggie@.neo.tamu.edu> wrote in message
news:ueILnPGVEHA.1048@.tk2msftngp13.phx.gbl...
> Hi all
> I'm coding a Web application which requires to write an XML file into a
> folder. I'm wondering other than account Everyone which else I can set
> permission so that my application can have the rights to write the file.
>

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 Problem

I am trying to determine a permission problem trying to write a text file
from one web server to another.
Here is the situation:
We have two domains in place one is Active Directory and the other is an old
NT4 domain. These two domains have a trust between them.
On a 2003 server I am using the file system object to write a text file to a
NT4 web server. The folder on the NT 4 server currently is shared with open
security with control for everyone on Domain1 and Domain2. The 2003 server's
worker process is running under a domain account that has full access to the
folder.
I am able to map a drive to the share from the 2003 box to the NT4 box while
logged in with an admin account of the 2003 box. I am also able to run a
.vbs script on the 2003 box that is able to place a text file on the NT4
box. Of course, I do believe that script runs and creates the file system
object as the logged in user of the 2003 box.
Now to the non-working part. On my asp.net and classic asp page I am unable
to write a text file from the 2003 box to the NT4 box at all. The virtual
server(s) that are serving the pages have anon security turned on and use
the IUSR_MachineName account. Since I have every permission imaginable added
to the folder on the NT4 box for both domains at full control. My theory is
that possibly the IUSR account is the account that is actually creating the
object and trying to place the text file. I only theorize this because I can
not place the text file and that account seems to be the only one w/o
permissions to that folder since it is a local machine account and not a
domain account.
So my real question here is if my theory is right and/or what exactly is
going on here. After spending much too long on this problem and feeling like
a noob I am at a loss as to what to try next. Any suggestion would be
greatly appreciated.
Thank you)The crux of this is that the user under which you try to access the remote
dir must be the same user that your script is running as. This become a
real pain when you tie this in with permissions across domains. So, on your
win3k box you need to impersonate in asp.net the user with permissions and
allow asp.net to run on behlaf of that trusted user. I've not tried it
between trusted domains, but it will be a pain I expect.
Why dont you cut your losses and pass the text as a post request to your NT4
web server and have asp create the file for you on the NT 4 box.
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Brian Cooper" <cooperb@.ingrambarge.com> wrote in message
news:QtCFc.3796$XF5.2833@.bignews4.bellsouth.net...
> I am trying to determine a permission problem trying to write a text file
> from one web server to another.
> Here is the situation:
> We have two domains in place one is Active Directory and the other is an
old
> NT4 domain. These two domains have a trust between them.
> On a 2003 server I am using the file system object to write a text file to
a
> NT4 web server. The folder on the NT 4 server currently is shared with
open
> security with control for everyone on Domain1 and Domain2. The 2003
server's
> worker process is running under a domain account that has full access to
the
> folder.
> I am able to map a drive to the share from the 2003 box to the NT4 box
while
> logged in with an admin account of the 2003 box. I am also able to run a
> .vbs script on the 2003 box that is able to place a text file on the NT4
> box. Of course, I do believe that script runs and creates the file system
> object as the logged in user of the 2003 box.
> Now to the non-working part. On my asp.net and classic asp page I am
unable
> to write a text file from the 2003 box to the NT4 box at all. The virtual
> server(s) that are serving the pages have anon security turned on and use
> the IUSR_MachineName account. Since I have every permission imaginable
added
> to the folder on the NT4 box for both domains at full control. My theory
is
> that possibly the IUSR account is the account that is actually creating
the
> object and trying to place the text file. I only theorize this because I
can
> not place the text file and that account seems to be the only one w/o
> permissions to that folder since it is a local machine account and not a
> domain account.
> So my real question here is if my theory is right and/or what exactly is
> going on here. After spending much too long on this problem and feeling
like
> a noob I am at a loss as to what to try next. Any suggestion would be
> greatly appreciated.
> Thank you)
>
Hi,
ASP.NET by default does not impersonate the logged on user, but rather runs
under the local ASPNET account, which is a least privliedged account. In ord
er to have the ASP.NET application impersonate the original caller you must
set imperonsation to true,
and authorization mode to Windows in your Web.Config. You also have to set W
indows Integrated Security in IIS. After this is done, if the logged on use
has access to the shared folder, there should be no problem accessing it.
Another thing also, is that you mentioned you are using the File System Obje
ct in Classic asp to access the share. If this is the case, then this object
does not understand UNC paths within a web application, this may be your pr
oblem. Try using another ob
ject if possible.
hope this helps,
sivilian
"Brian Cooper" wrote:

> I am trying to determine a permission problem trying to write a text file
> from one web server to another.
> Here is the situation:
> We have two domains in place one is Active Directory and the other is an o
ld
> NT4 domain. These two domains have a trust between them.
> On a 2003 server I am using the file system object to write a text file to
a
> NT4 web server. The folder on the NT 4 server currently is shared with ope
n
> security with control for everyone on Domain1 and Domain2. The 2003 server
's
> worker process is running under a domain account that has full access to t
he
> folder.
> I am able to map a drive to the share from the 2003 box to the NT4 box whi
le
> logged in with an admin account of the 2003 box. I am also able to run a
> ..vbs script on the 2003 box that is able to place a text file on the NT4
> box. Of course, I do believe that script runs and creates the file system
> object as the logged in user of the 2003 box.
> Now to the non-working part. On my asp.net and classic asp page I am unabl
e
> to write a text file from the 2003 box to the NT4 box at all. The virtual
> server(s) that are serving the pages have anon security turned on and use
> the IUSR_MachineName account. Since I have every permission imaginable add
ed
> to the folder on the NT4 box for both domains at full control. My theory i
s
> that possibly the IUSR account is the account that is actually creating th
e
> object and trying to place the text file. I only theorize this because I c
an
> not place the text file and that account seems to be the only one w/o
> permissions to that folder since it is a local machine account and not a
> domain account.
> So my real question here is if my theory is right and/or what exactly is
> going on here. After spending much too long on this problem and feeling li
ke
> a noob I am at a loss as to what to try next. Any suggestion would be
> greatly appreciated.
> Thank you)
>
>

Permissions Problem

I am trying to determine a permission problem trying to write a text file
from one web server to another.

Here is the situation:

We have two domains in place one is Active Directory and the other is an old
NT4 domain. These two domains have a trust between them.

On a 2003 server I am using the file system object to write a text file to a
NT4 web server. The folder on the NT 4 server currently is shared with open
security with control for everyone on Domain1 and Domain2. The 2003 server's
worker process is running under a domain account that has full access to the
folder.

I am able to map a drive to the share from the 2003 box to the NT4 box while
logged in with an admin account of the 2003 box. I am also able to run a
..vbs script on the 2003 box that is able to place a text file on the NT4
box. Of course, I do believe that script runs and creates the file system
object as the logged in user of the 2003 box.

Now to the non-working part. On my asp.net and classic asp page I am unable
to write a text file from the 2003 box to the NT4 box at all. The virtual
server(s) that are serving the pages have anon security turned on and use
the IUSR_MachineName account. Since I have every permission imaginable added
to the folder on the NT4 box for both domains at full control. My theory is
that possibly the IUSR account is the account that is actually creating the
object and trying to place the text file. I only theorize this because I can
not place the text file and that account seems to be the only one w/o
permissions to that folder since it is a local machine account and not a
domain account.

So my real question here is if my theory is right and/or what exactly is
going on here. After spending much too long on this problem and feeling like
a noob I am at a loss as to what to try next. Any suggestion would be
greatly appreciated.

Thank you)The crux of this is that the user under which you try to access the remote
dir must be the same user that your script is running as. This become a
real pain when you tie this in with permissions across domains. So, on your
win3k box you need to impersonate in asp.net the user with permissions and
allow asp.net to run on behlaf of that trusted user. I've not tried it
between trusted domains, but it will be a pain I expect.

Why dont you cut your losses and pass the text as a post request to your NT4
web server and have asp create the file for you on the NT 4 box.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Brian Cooper" <cooperb@.ingrambarge.com> wrote in message
news:QtCFc.3796$XF5.2833@.bignews4.bellsouth.net...
> I am trying to determine a permission problem trying to write a text file
> from one web server to another.
> Here is the situation:
> We have two domains in place one is Active Directory and the other is an
old
> NT4 domain. These two domains have a trust between them.
> On a 2003 server I am using the file system object to write a text file to
a
> NT4 web server. The folder on the NT 4 server currently is shared with
open
> security with control for everyone on Domain1 and Domain2. The 2003
server's
> worker process is running under a domain account that has full access to
the
> folder.
> I am able to map a drive to the share from the 2003 box to the NT4 box
while
> logged in with an admin account of the 2003 box. I am also able to run a
> .vbs script on the 2003 box that is able to place a text file on the NT4
> box. Of course, I do believe that script runs and creates the file system
> object as the logged in user of the 2003 box.
> Now to the non-working part. On my asp.net and classic asp page I am
unable
> to write a text file from the 2003 box to the NT4 box at all. The virtual
> server(s) that are serving the pages have anon security turned on and use
> the IUSR_MachineName account. Since I have every permission imaginable
added
> to the folder on the NT4 box for both domains at full control. My theory
is
> that possibly the IUSR account is the account that is actually creating
the
> object and trying to place the text file. I only theorize this because I
can
> not place the text file and that account seems to be the only one w/o
> permissions to that folder since it is a local machine account and not a
> domain account.
> So my real question here is if my theory is right and/or what exactly is
> going on here. After spending much too long on this problem and feeling
like
> a noob I am at a loss as to what to try next. Any suggestion would be
> greatly appreciated.
> Thank you)
Hi,

ASP.NET by default does not impersonate the logged on user, but rather runs under the local ASPNET account, which is a least privliedged account. In order to have the ASP.NET application impersonate the original caller you must set imperonsation to true, and authorization mode to Windows in your Web.Config. You also have to set Windows Integrated Security in IIS. After this is done, if the logged on use has access to the shared folder, there should be no problem accessing it.

Another thing also, is that you mentioned you are using the File System Object in Classic asp to access the share. If this is the case, then this object does not understand UNC paths within a web application, this may be your problem. Try using another object if possible.

hope this helps,

sivilian

"Brian Cooper" wrote:

> I am trying to determine a permission problem trying to write a text file
> from one web server to another.
> Here is the situation:
> We have two domains in place one is Active Directory and the other is an old
> NT4 domain. These two domains have a trust between them.
> On a 2003 server I am using the file system object to write a text file to a
> NT4 web server. The folder on the NT 4 server currently is shared with open
> security with control for everyone on Domain1 and Domain2. The 2003 server's
> worker process is running under a domain account that has full access to the
> folder.
> I am able to map a drive to the share from the 2003 box to the NT4 box while
> logged in with an admin account of the 2003 box. I am also able to run a
> ..vbs script on the 2003 box that is able to place a text file on the NT4
> box. Of course, I do believe that script runs and creates the file system
> object as the logged in user of the 2003 box.
> Now to the non-working part. On my asp.net and classic asp page I am unable
> to write a text file from the 2003 box to the NT4 box at all. The virtual
> server(s) that are serving the pages have anon security turned on and use
> the IUSR_MachineName account. Since I have every permission imaginable added
> to the folder on the NT4 box for both domains at full control. My theory is
> that possibly the IUSR account is the account that is actually creating the
> object and trying to place the text file. I only theorize this because I can
> not place the text file and that account seems to be the only one w/o
> permissions to that folder since it is a local machine account and not a
> domain account.
> So my real question here is if my theory is right and/or what exactly is
> going on here. After spending much too long on this problem and feeling like
> a noob I am at a loss as to what to try next. Any suggestion would be
> greatly appreciated.
> Thank you)
>