Saturday, April 12, 2008

Writing on a file in asp.net application

I have written an application in asp.net where I have to write an Xml file through IIS server but I was getting this error:

Access to the path "C:\.... \viewRss.xml" is denied.

Exception Details:
System.UnauthorizedAccessException: Access to the
path " C:\.... \viewRss.xml " is denied.

And the solution given by the MS on the error page was:

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or
Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.

I have tried all this but was unable to write on the file.

The solution I got was with the help of my friend (Ravi) was :

  • Right click on the virtual directory
  • Click on properties
  • Click on Directory Security, onthis tab click on Edit button
  • Check mark on Anonymous User and give the name of the computer like this IUSR_ComputerName
  • Check mark on Integrated Windows authentication and click Ok.
  • And in the Web config file of Asp.Net Application Add this lines between system.web tags
    • <identity impersonate="true" />

After this I was able to write on the xml file.

1 comment:

Anonymous said...

What are the security concern when you give access anonymously?