UnauthorizedAccessException

Discussion in 'ASP .Net Web Services' started by DearManasi@gmail.com, Jan 31, 2006.

  1. Guest

    Hi,

    I have written a ASP.NET web service . It contains a method called
    WriteMessage(). This method creates a .txt file on c drive and writes
    some message to it.

    Now I have created a ASP.NET web application. I am calling the
    WriteMessage() method from this web application. But it is throwing
    UnauthorizedAccessException.

    The exception is as follows
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    System.UnauthorizedAccessException: Access to the path
    'c:\NSWebService.txt' is denied.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
    access, Int32 rights, Boolean useRights, FileShare share, Int32
    bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
    msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    access, FileShare share, Int32 bufferSize, FileOptions options)
    at Service.WriteMessage()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    What should I do to obtain the nexessary permissions?
    Please help.

    Mana
    , Jan 31, 2006
    #1
    1. Advertising

  2. Josh Twist Guest

    The problem here is that the ASPNET user account does not have
    permissions to write to the C:\.

    If you've managed to make your web service work when 'playing' with it
    I'll wager that you are using the ASP.NET development server provided
    with Visual Studio 2005 (.NET 2.0) - this operates under YOUR user
    account permissions (probably Administrator). Don't use it, it's
    dangerous for this very reason!

    The quickest solution here is to give your ASPNET user account write
    permissions to the files/folders necessary. I would strongly recommend
    you create a custom folder and not give the ASPNET account full
    permissions over your whole C:\ though! You could also consider
    impersonation etc.

    Josh
    http://www.thejoyofcode.com/
    Josh Twist, Jan 31, 2006
    #2
    1. Advertising

  3. Mana Guest

    Hi Josh,

    I created one custom folder and gave ASPNET user necessary permissions.
    It worked.
    Thanks a lot.

    Mana
    Mana, Feb 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    846
    S. Justin Gengo
    Jul 14, 2003
  2. Salim Afþar
    Replies:
    0
    Views:
    423
    Salim Afþar
    Aug 11, 2003
  3. R Warford
    Replies:
    3
    Views:
    485
    Guest
    Dec 1, 2003
  4. GM
    Replies:
    2
    Views:
    2,210
  5. Hal 9000
    Replies:
    1
    Views:
    2,014
    avnrao
    May 4, 2004
Loading...

Share This Page