in Education by
I have shared location on Azure VM and web job in the same Vnet on Azure. I have C# script deployed on webjob to access the shared location. When I execute web job to access it, I am getting bewlo error: [03/22/2019 15:02:19 > eb8046: SYS INFO] Status changed to Initializing [03/22/2019 15:02:29 > eb8046: SYS INFO] Run script 'AccessSharedLocation.exe' with script host - 'WindowsScriptHost' [03/22/2019 15:02:29 > eb8046: SYS INFO] Status changed to Running [03/22/2019 15:02:32 > eb8046: ERR ] [03/22/2019 15:02:32 > eb8046: ERR ] Unhandled Exception: System.Net.WebException: Access to the path '\192.168.1.4\shared\nilo.txt' is denied. ---> System.Net.WebException: Access to the path '\192.168.1.4\shared\nilo.txt' is denied. ---> System.UnauthorizedAccessException: Access to the path '\192.168.1.4\shared\nilo.txt' is denied. [03/22/2019 15:02:32 > eb8046: ERR ] at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) [03/22/2019 15:02:32 > eb8046: ERR ] at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) [03/22/2019 15:02:32 > eb8046: ERR ] at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean useAsync) [03/22/2019 15:02:32 > eb8046: ERR ] --- End of inner exception stack trace --- [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean useAsync) [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebRequest.CreateResponse() [03/22/2019 15:02:32 > eb8046: ERR ] --- End of inner exception stack trace --- [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebRequest.CreateResponse() [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebRequest.<>c.b__59_0(Object s) [03/22/2019 15:02:32 > eb8046: ERR ] at System.Threading.Tasks.Task`1.InnerInvoke() [03/22/2019 15:02:32 > eb8046: ERR ] at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) [03/22/2019 15:02:32 > eb8046: ERR ] --- End of stack trace from previous location where exception was thrown --- [03/22/2019 15:02:32 > eb8046: ERR ] at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) [03/22/2019 15:02:32 > eb8046: ERR ] --- End of stack trace from previous location where exception was thrown --- [03/22/2019 15:02:32 > eb8046: ERR ] at System.Threading.Tasks.TaskToApm.End[TResult](IAsyncResult asyncResult) [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult) [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.FileWebRequest.GetResponse() [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.WebClient.GetWebResponse(WebRequest request) [03/22/2019 15:02:32 > eb8046: ERR ] at System.Net.WebClient.OpenRead(Uri address) [03/22/2019 15:02:32 > eb8046: ERR ] at AccessSharedLocation.Program.buttonDownloadFile_Click() in C:\Users\dharti.sutariya\source\repos\AccessSharedLocation\AccessSharedLocation\Program.cs:line 63 [03/22/2019 15:02:32 > eb8046: ERR ] at AccessSharedLocation.Program.Main(String[] args) in C:\Users\dharti.sutariya\source\repos\AccessSharedLocation\AccessSharedLocation\Program.cs:line 48 [03/22/2019 15:02:32 > eb8046: INFO] Hello World! [03/22/2019 15:02:32 > eb8046: SYS INFO] Status changed to Failed [03/22/2019 15:02:32 > eb8046: SYS ERR ] Job failed due to exit code -532462766 Below is my C# code using System; using System.ComponentModel; using System.Net; using System.Runtime.InteropServices; namespace AccessSharedLocation { public class NetworkConnection : IDisposable { readonly string _networkName; public NetworkConnection(string networkName, NetworkCredential credentials) { _networkName = networkName; var netResource = new NetResource { Scope = ResourceScope.GlobalNetwork, ResourceType = ResourceType.Disk, DisplayType = ResourceDisplaytype.Share, RemoteName = networkName }; var userName = string.IsNullOrEmpty(credentials.Domain) ? credentials.UserName : string.Format(@"{0}\{1}", credentials.Domain, credentials.UserName); var result = WNetAddConnection2( netResource, credentials.Password, userName, 0); if (result != 0) { throw new Win32Exception(result); } } ~NetworkConnection() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { WNetCancelConnection2(_networkName, 0, true); } [DllImport("mpr.dll")] private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags); [DllImport("mpr.dll")] private static extern int WNetCancelConnection2(string name, int flags, bool force); [StructLayout(LayoutKind.Sequential)] public class NetResource { public ResourceScope Scope; public ResourceType ResourceType; public ResourceDisplaytype DisplayType; public int Usage; public string LocalName; public string RemoteName; public string Comment; public string Provider; } public enum ResourceScope : int { Connected = 1, GlobalNetwork, Remembered, Recent, Context }; public enum ResourceType : int { Any = 0, Disk = 1, Print = 2, Reserved = 8, } public enum ResourceDisplaytype : int { Generic = 0x0, Domain = 0x01, Server = 0x02, Share = 0x03, File = 0x04, Group = 0x05, Network = 0x06, Root = 0x07, Shareadmin = 0x08, Directory = 0x09, Tree = 0x0a, Ndscontainer = 0x0b } } } Can anyone please help me out with this. Any help would be great. if this is achievable thorugh Powershell as well, it would work. I have tried several powershell but Azure does not allow to install/execute several module with admin access. The same powershell works with my local system but not through Azure web job. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The App Service sandbox explicitly does not allow access to the ports necessary for SMB protocol (137/138/139/445). This article mentions it under Restricted Outgoing Ports: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox.

Related questions

0 votes
    I have a HDInsight Hadoop cluster (Linux, deployed separately) on Azure VNet (restricting client IPs using NSG). ... Data Factory? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Can someone tell me the differences between the Azure Web Site and the Azure Web Roles for an ASP.NET MVC ... Cache service locally? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    Azure Traffic manager receives a query from _____________. A. Endpoint B. Client C. Routing Method D. All the options...
asked Nov 21, 2022 in Education by JackTerrance
0 votes
    Which endpoint is used for Non-Azure services? A. External Endpoint B. Nested Endpoint C. Azure Endpoints D. All the options...
asked Nov 21, 2022 in Education by JackTerrance
0 votes
    How many endpoints are there in Azure Traffic Manager? A. 1 B. 2 C. 3 D. 4...
asked Nov 21, 2022 in Education by JackTerrance
0 votes
    Azure DNS is the same as Domain Registrar. A. True B. False...
asked Nov 21, 2022 in Education by JackTerrance
0 votes
    Azure Virtual Networks can be created using _________. A. Azure CLI B. Azure Portal C. Azure Powershell D. All the options...
asked Nov 21, 2022 in Education by JackTerrance
0 votes
    A company is planning on hosting an application on an Azure Virtual Machine. It needs to be ensured that the application ... plan. Would this satisfy the requirement A. Yes B. No...
asked Nov 20, 2022 in Education by JackTerrance
0 votes
    In Azure, a public address can be assigned to _____________. A. VPN Gateway B. Application Gateway C. VM D. All the options...
asked Nov 20, 2022 in Education by JackTerrance
0 votes
    You need to ensure that Azure DNS can resolve names for your registered domain. What should you implement? A. An MX Record B. A Secondary Zone C. A CNAME Record D. Zone Delegation...
asked Nov 20, 2022 in Education by JackTerrance
0 votes
    Azure takes care of ___________. A. Subnet allocation B. VM IP range allocation C. DNS resolution D. Underlying routing...
asked Nov 20, 2022 in Technology by JackTerrance
0 votes
    I was doing an arm template deployment of Azure data factory from dev-ops pipelines. Mistakenly I have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I was doing an arm template deployment of Azure data factory from dev-ops pipelines. Mistakenly I have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Can't ping smtp.gmail.com. I've been using google smtp for email notification and it was working ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    If you want to build enterprise ASP.NET MVC applications that use MSSQL databases is it better to use Windows ... integration, etc)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...