Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2010, 04:25 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default ASP.NET permissions

I have written some code using the XMLTextWriter to write some stuff into an XML file. However It keeps throwing an exception saying that Access to the file is denied.

I have gone and changed the security settings for this file so that "Everyone" has full control over the file however I still incur this error when attempting to write to this file.

What else would cause this? I am building and running the application using the built in server within visual web developer.

Any ideas?

Cheers
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old August 8th, 2010, 03:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you provide more information such as the relevant code and the exact error message? Maybe there are other things (temp folder for example) involved, or maybe the error message is sneding you in the wrong direction.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 8th, 2010, 05:07 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Sure,

The exception message that I get is:

Access to the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\ErrorLog.xml' is denied.

It seems to be occurring when this fires:

XmlTextWriter textWriter = new XmlTextWriter("ErrorLog.xml", Encoding.UTF8);


However when googling for solutions I was advised that I would need to set the permissions on the actual file itself.

The code I am attemtping to use is to record each time an exception occurs:

Code:
public static void CreateXMLErrorLog(Exception error)
{
    //Create xml log entry
    XmlTextWriter textWriter = new XmlTextWriter("ErrorLog.xml", Encoding.UTF8);

    //Construct xml
    textWriter.WriteStartDocument();
    textWriter.WriteStartElement("error");
    textWriter.WriteStartElement("date", DateTime.Now.ToShortDateString());
    textWriter.WriteEndElement();
    textWriter.WriteStartElement("time", DateTime.Now.ToShortTimeString());
    textWriter.WriteEndElement();
    textWriter.WriteStartElement("errorDetails", error.ToString());
    textWriter.WriteEndElement();
    textWriter.WriteEndElement();
    textWriter.WriteEndDocument();
    textWriter.Close();
  }
First time i've used that so I was hoping to test the results from it.
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old August 8th, 2010, 05:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you running this on Windows 7? I think access is blocked to the Program Files folder if you're not running this as an Administrator. Setting permissions then doesn't make a difference.

Try specifying a path like this:

Code:
 
XmlTextWriter textWriter = new XmlTextWriter(@"C:\Test\ErrorLog.xml"), Encoding.UTF8);
And assign the permissions to the C:\Test folder. Does it work then?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 8th, 2010, 05:56 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Yes it works when I make those changes and use the test file as suggested.

I closed VS down and ran it as an administrator and tried it again using the original code and I got no exception this time but it doesn't seem to have written anything into the XML file.

Thanks for your help!
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old August 8th, 2010, 06:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hui Will,

It's generally a bad idea to write to Program Files from your application. You're better off storing data in the user's folder or in a folder outside Windows folders.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 8th, 2010, 06:17 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Ok, I wanted to have the file as an xml file that logs any errors that occur.

When I put this onto a server will this work? I had just intended to include an XML file in the application and have the errors written to that file path but this is a bad idea?
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old August 8th, 2010, 06:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
When I put this onto a server will this work?
That will depend on the server and its configuration.
Quote:
I had just intended to include an XML file in the application and have the errors written to that file path but this is a bad idea?
Probably. Again, it depends. For a web application, you could write to App_Data instead. For other types of applications, I prefer to create a separate folder like d:\LogFiles and create a sub folder for each application that needs to log. Easier to configure and manage.....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 8th, 2010, 08:01 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Thanks for the help, will look into the App_Data.

Cheers
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old August 8th, 2010, 12:57 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Alright I don't seem to have the permissions issue I was having when attempting to write to the App_Data folder? Is this because ASP.NET is automatically configured to have access to this folder?

I don't know too much about the App_Data folder, is this a protected folder by default? Would it be a good place to store .pdf or other types of files that I don't want made available to the public and then just read them from the folder?

I am now using this code to create an error log but I am overwriting previous entries each time...

Code:
public static void CreateXMLErrorLog(Exception error)
  {
    //Create xml log entry
    XmlTextWriter textWriter = new XmlTextWriter(HttpContext.Current.Server.MapPath("~/App_Data/ErrorLog.xml"), Encoding.UTF8);

    //Construct xml
    textWriter.WriteStartDocument();
    textWriter.WriteStartElement("error");
    textWriter.WriteElementString("date", DateTime.Now.ToShortDateString());
    textWriter.WriteElementString("time", DateTime.Now.ToShortTimeString());
    textWriter.WriteElementString("errorDetails", error.ToString());
    textWriter.WriteEndElement();
    textWriter.WriteEndDocument();
    textWriter.Close();
  }
This is just because of the XmlTextWriter I suppose what would be a better option so that I can just add in new entries instead of overwriting each time?
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
assign report permissions thru vb .net code polofson Reporting Services 0 April 15th, 2008 05:31 PM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
Restrict ASP.NET app DB permissions using Integrat wirerider ASP.NET 2.0 Professional 0 March 6th, 2007 08:23 PM
Permissions error when executing DTS from ASP pjmair SQL Server DTS 9 February 6th, 2004 02:47 PM
IIS 6.0 and ASP.NET Permissions dikkjo ASP.NET 1.0 and 1.1 Basics 4 July 29th, 2003 03:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.