Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating an web application. I have to show one attachment in a button click.The attachment file resides on another server which is in the same network. when i make the coding its works well in my development machine, but when i deploy it does not work.

i am deploying the application in 192.168.a.xyz server and the mapped folder is in 192.168.a.ijk.

i have used the below code which works well in the development machine which is also in the same network.

I am creating an web application. I have to show one attachment in a button click.The attachment file resides on another server which is in the same network. when i make the coding its works well in my development machine, but when i deploy it does not work.

i am deploying the application in 192.168.a.xyz server and the mapped folder is in 192.168.a.ijk.

i have used the below code which works well in the development machine which is also in the same network.


Appreciate if anybody can help!

What I have tried:

C#
public ActionResult GetCorporateInvoiceCopy(string attachId)
        {
            if (attachId.Length > 0)
            {
                try
                {
                    string FileExtension = ".pdf";
                    string csvPath = "";
                    string inv = attachId;
                    csvPath = @"\\192.168.a.ijk\\Attached_Files\" + Path.GetFileName(inv.ToString() + FileExtension );
                    return File(csvPath, FileExtension);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return null;
            }
        }
Posted
Updated 7-Mar-17 7:59am
v2
Comments
[no name] 7-Mar-17 9:50am    
Accounts normally running IIS do not have access to network resources.

1 solution

It works on your machine because when you write the code and tested it on your machine it was running under YOUR ACCOUNT. Since you have access to the other network resource, the code works.

Now, when running the code on the web server, it's running under a default ASP.NET account. By default, and for very good security reasons, has no access to the network resource you're trying to get to.

You have to create a user stripped down user account to run your site under. This account would also have to be given appropriate Share and NTFS permissions to the network resource the code is trying to get to. You then change the Application Pool running your site to use this account.

Hopefully, you've got these machines running in Active Directory to make this a bit easier to manage? If not, good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900