4

I have a problem when I try to access a file from a shared folder in a local network.
When I run the application in Visual Studio it works fine and I can download the file, but when I deploy the application to IIS, it simply doesn´t work.
I don´t understand why, cause I give full permissions to all users, including NETWORK SERVICE and IIS_USR.
I'm currently using my computer to test this. It has Windows 7 and running IIS 7.5. The shared folder I'm trying to access is on a Windows Vista installation which doesn´t have IIS installed.

The code to download file is this:

protected void button_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=S10.png");
    Response.WriteFile(@"\\192.168.1.82\Machine\file.png");
    Response.End();
}

and it gives me the following error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Acesso negado ao caminho '\192.168.1.82\Machine\file.png'.

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 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET 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.

Please someone could help me. Thanks in advance.

3 Answers 3

1

You have given access rights on the file system (full control is overkill for this, read or modify should be fine), but you will likely find the share permissions are still at the default of read only. You need to change the share permissions.

Read this for more info.

EDIT: The reason it works ok when debugging is because it's using the account you are logged on with, not the aspnet account in VS.

Create a new app pool, running under a service account which is a member of the IIS_WPG group on the IIS server and has permissions on the share you want to write back to (remember to set the service account to password never expire). Give the IIS_WPG group Read & Execute, List Folder Contents, and Read permissions to the Web site directories. Change the web app to run in this new web pool.

Sign up to request clarification or add additional context in comments.

2 Comments

Thaks for your reply, but it´s not that, I checked the share permissions and it´s fine, also this works well running in visual studio, it only gives me the problem when I running the application in IIS.
Thanks for your help. I´ve tried that and it doesn´t work, always keep getting the same error, can´t find out what is wrong.
0

solution 1:

You can define a domain user. Let IIS server run with this user ( through Pool identity or 'connect as'). give this user access rights on Shared folder.

Solution 2:

Add IIS server account into user group of the server that contain shared folder, Give this user access right on shared folder.

Comments

0

If the file and the Machine folder is in C Drive, then you also need to give permissions to the root folder containing this file path because C Drive is usually read/write protected as it has System Files in it.

So for example if the file is in the path C:\Machine\file.png. Then you need to add and give relevant permissions to IIS users group to Machine Folder and not just to the file i.e., file.png.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.