Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Azure网站时访问第三方网络驱动器_C#_.net_Azure - Fatal编程技术网

C# 使用Azure网站时访问第三方网络驱动器

C# 使用Azure网站时访问第三方网络驱动器,c#,.net,azure,C#,.net,Azure,在azure网站上托管我的网站/请求时,我在尝试读取存储在网络驱动器上的文件时遇到问题 该代码在本地机器上进行测试,也在专用服务器上工作,我们与另一个客户机一起使用该服务器,并完全控制该服务器,但当我们尝试读取该文件时,它会出现以下错误 对路径“\xxx.xxx.xxx.xxx\abc\abc.xml”的访问被拒绝 我想知道Azure是否被锁定以防止这种我不知道的行为。可能是港口关闭了什么的 我正在使用的代码 if (impersonate.impersonateValidUser("usern

在azure网站上托管我的网站/请求时,我在尝试读取存储在网络驱动器上的文件时遇到问题

该代码在本地机器上进行测试,也在专用服务器上工作,我们与另一个客户机一起使用该服务器,并完全控制该服务器,但当我们尝试读取该文件时,它会出现以下错误

对路径“\xxx.xxx.xxx.xxx\abc\abc.xml”的访问被拒绝

我想知道Azure是否被锁定以防止这种我不知道的行为。可能是港口关闭了什么的

我正在使用的代码

if (impersonate.impersonateValidUser("username", "domain.com", "password"))
                    {
                        message = "impersonate ok";
                        if (!System.IO.File.Exists(file))
                        {
                            message = "no file";
                            impersonate.undoImpersonation();
                        }

                        using (StreamReader reader = File.OpenText(file))
                        {
                            message = "";
                            XmlSerializer deserializer = new XmlSerializer(typeof(TextModeSchema));
                            schema = (TextModeSchema)deserializer.Deserialize(reader);
                            reader.Close();
                        }
                    }
这是一个基本的模拟类,我们在很多地方都使用它

public class Impersonate : IDisposable
    {
        public const int LOGON32_LOGON_INTERACTIVE = 2;
        public const int LOGON32_LOGON_NETWORK = 3;
        public const int LOGON32_LOGON_BATCH = 4;
        public const int LOGON32_LOGON_SERVICE = 5;
        public const int LOGON32_LOGON_UNLOCK = 7;
        public const int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
        public const int LOGON32_LOGON_NEW_CREDENTIALS = 9;


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

       WindowsImpersonationContext impersonationContext;

        [DllImport("advapi32.dll")]
        public static extern int LogonUserA(String lpszUserName,
            String lpszDomain,
            String lpszPassword,
            int dwLogonType,
            int dwLogonProvider,
            ref IntPtr phToken);
        [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int DuplicateToken(IntPtr hToken,
            int impersonationLevel,
            ref IntPtr hNewToken);

        [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool RevertToSelf();

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern bool CloseHandle(IntPtr handle);

        public bool impersonateValidUser(String userName, String domain, String password)
        {
            WindowsIdentity tempWindowsIdentity;
            IntPtr token = IntPtr.Zero;
            IntPtr tokenDuplicate = IntPtr.Zero;

            if (RevertToSelf())
            {
                if (LogonUserA(userName, domain, password, LOGON32_LOGON_NEW_CREDENTIALS,
                    LOGON32_PROVIDER_DEFAULT, ref token) != 0)
                {
                    if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
                    {
                        tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
                        impersonationContext = tempWindowsIdentity.Impersonate();
                        if (impersonationContext != null)
                        {
                            CloseHandle(token);
                            CloseHandle(tokenDuplicate);
                            return true;
                        }
                    }
                }
            }
            if (token != IntPtr.Zero)
                CloseHandle(token);
            if (tokenDuplicate != IntPtr.Zero)
                CloseHandle(tokenDuplicate);
            return false;
        }

        public void undoImpersonation()
        {
            impersonationContext.Undo();
        }


        public void Dispose()
        {
            impersonationContext.Undo();
            GC.Collect();
        }
    }

如果azure上不允许这样做,是否有人知道我们可以绕过它而不必设置完整的虚拟机?理想情况下,我希望使用azure网站/webapp。

这是在web角色、工作者角色还是web应用程序上?我知道,对于角色,场景中的远程主机必须与角色位于同一个专用网络上(对于web应用程序也可能如此)。另外,我们有一个类似的场景,我们决定使用Azure文件,它允许在您可能想要尝试的角色上装载共享