简体   繁体   中英

Access to the path “*****” is denied

I have a folder in my same network as "\\lo1dc\\abcd\\Admin\\Images" I set full permission for everyone. I created a new web application in another machine within the same network and created a virtual directory called "_images" and set this folder path. I have set the path credential as a specified user while creating account and set the name as administrator. Which is administrator user for entire network.

Now while trying to save image as shown below

string strSaveLocationCode128 = Server.MapPath("~/_images") + "//abc.Jpg";
barcodeCode128Mobile.drawBarcode(strSaveLocationCode128);

This is showing me the error message as "Access to the path '\\lo1dc\\abcd\\Admin\\Images\\abc.Jpg' is denied".

Please help me I am using Win 7 as my development platform.

Finally i found out the answer, The network path cannot be accessed by an anonymous user. So

SPSecurity.RunWithElevatedPrivileges

has done the trick for me. Thank you all for your valuable help at right time.

You can Login as local user using LogOnUser function:

        [DllImport("advapi32.dll", SetLastError = true)]
        private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

        // types 
        const int LOGON32_LOGON_INTERACTIVE = 2;
        const int LOGON32_LOGON_NETWORK = 3;
        const int LOGON32_LOGON_NEW_CREDENTIALS = 9;

        // providers 
        const int LOGON32_PROVIDER_DEFAULT = 0;
        const int LOGON32_PROVIDER_WINNT35 = 1;
        const int LOGON32_PROVIDER_WINNT40 = 2;
        const int LOGON32_PROVIDER_WINNT50 = 3;

Usage:

IntPtr token = IntPtr.Zero;
LogonUser("User Name", "Domain Name", "Password", LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);

using (WindowsImpersonationContext user = new WindowsIdentity(token).Impersonate())
{
    // Do file operations here...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM