Access Denied - Windows service web API controller class

6

As a continuation on from https://stackoverflow.com/questions/48107646/how-to-test-apicontroller...in short....

Im working on an existing Windows Service project in VS 2013.

I've added a web API Controller class...I've called it SynchroniseFromAwsServiceController

Im trying to call it from a AWS lambda call but it is telling me I dont have access. So I need to test it locally to see if it is working to try and diagnose the issue.

     namespace Workflow
    {

        public class SynchroniseFromAwsServiceController: ApiController
        {
            //// POST api/<controller>
            [HttpPost]
            public string SapCall([FromBody]string xmlFile)
            {
                string responseMsg = "Failed Import User";

                if (!IsNewestVersionOfXMLFile(xmlFile))
                {
                    responseMsg = "Not latest version of file, update not performed";
                }
                else
                {
                    Business.PersonnelReplicate personnelReplicate = BusinessLogic.SynchronisePersonnel.BuildFromDataContractXml<Business.PersonnelReplicate>(xmlFile);
                    bool result = Service.Personnel.SynchroniseCache(personnelReplicate);

                    if (result)
                    {
                        responseMsg = "Success Import Sap Cache User";
                    }
                }

                return "{\"response\" : \" " + responseMsg + " \" , \"isNewActiveDirectoryUser\" : \" false \"}";
            }
    }
    }

Im using PostMan to test this. Im running the application in VS and entering http://127.0.0.1/SynchronisePersonnelXmlFromAwsServiceController/SapEaiCall in the POST field in the POSTMAN ui...it returns the following:

Server Error in '/' Application.

Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' because access is denied. Exception Details: System.Web.HttpException: Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' because access is denied.

Stack Trace:

[HttpException (0x80070005): Failed to start monitoring changes to &#39;D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax&#39;

because access is denied.] System.Web.DirectoryMonitor.AddFileMonitor(String file) +9929663 System.Web.DirectoryMonitor.StartMonitoringFileWithAssert(String file, FileChangeEventHandler callback, String alias) +89 System.Web.FileChangesMonitor.StartMonitoringFile(String alias, FileChangeEventHandler callback) +331 System.Web.HttpApplicationFactory.SetupChangesMonitor() +122 System.Web.HttpApplicationFactory.Init() +161 System.Web.HttpApplicationFactory.EnsureInited() +80 System.Web.HttpApplicationFactory.SetupFileChangeNotifications() +71 System.Web.Compilation.BuildManager.CompileGlobalAsax() +57 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +260

[HttpException (0x80004005): Failed to start monitoring changes to &#39;D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax&#39;

because access is denied.] System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +62 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +435 System.Web.Compilation.BuildManager.CallAppInitializeMethod() +33 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +563

[HttpException (0x80004005): Failed to start monitoring changes to &#39;D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax&#39;

because access is denied.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10085904 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

[HttpException]: Failed to start monitoring changes to &#39;D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax&#39;

because access is denied. at System.Web.DirectoryMonitor.AddFileMonitor(String file) at System.Web.DirectoryMonitor.StartMonitoringFileWithAssert(String file, FileChangeEventHandler callback, String alias) at System.Web.FileChangesMonitor.StartMonitoringFile(String alias, FileChangeEventHandler callback) at System.Web.HttpApplicationFactory.SetupChangesMonitor() at System.Web.HttpApplicationFactory.Init() at System.Web.HttpApplicationFactory.EnsureInited() at System.Web.HttpApplicationFactory.SetupFileChangeNotifications() at System.Web.Compilation.BuildManager.CompileGlobalAsax() at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() [HttpException]: Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' because access is denied. at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() at System.Web.Compilation.BuildManager.CallAppInitializeMethod() at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) [HttpException]: Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' because access is denied. at System.Web.HttpRuntime.FirstRequestInit(HttpContext context) at System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)

does anyone have any idea or can point me in the right direction as to why I am getting returned <title>Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' because access is denied.</title>

UPDATE

Thanks to https://stackoverflow.com/questions/4889297/failed-to-start-monitoring-changes-on-global-asax-net-3-5-web-service-using-imp

Ive removed read only from the folder and added Authenticated Users. Now when I run, it gives me a different error but still says access denied....Am I using the correct URL? http://127.0.0.1/SynchronisePersonnelXmlFromAwsServiceController/SapEaiCall

anyway the new error is:

Server Error in '/' Application. Access is denied. Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2 Unauthorized: Logon failed due to server configuration.

Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.  Contact the Web server's administrator for additional assistance.

any help would be much appreciated thank you

UPDATE Thanks to George Vovos for the reply I have moved http to above the method and changed the signature to include controller.

In postman I have also included the basic value tag for authorization.

Now when I run the VS application locally and try to connect through post man with http://localhost/WebServices.Workflow/SynchroniseFromAwsServiceController/SapCall

(WebServices.Workflow being the application name)

I get the following message:

Could not get any response
There was an error connecting to http://localhost/WebServices.Workflow/SynchroniseFromAwsServiceController/SapEaiCall
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General

I have tried turning off SSL...any other ideas?

NEW UPDATE Following on from a post I found I restarted PostMan and ran the POST again, and now the message is returning a There is a duplicate 'exceptionless' section defined which is what I get the I try to run the application from visual studio. So atleast its a step in the right direction (I think)...I have wrote a new Q regarding this...

config file flagging as duplicate Exceptionless package

NOTE if someone is able to help me answer this continuation Q, I will award them the bounty from this Q. NOTE

Thank You for any replies

c#
asp.net-web-api
postman
asked on Stack Overflow Jan 5, 2018 by John • edited Jan 8, 2018 by John

2 Answers

4

I also had the same error when deploying my ASP.Net Web API recently on my machine. What I did wrong was that I had not enabled Application Development Features required for it. You also need to check if you have the following features enabled on your local machine: enter image description here

You can navigate to ControlPanel -> Programs -> Programs And Features -> Turn Windows Features on or off, to check if these features are enabled or not.

Hope this helps :)

answered on Stack Overflow Jan 11, 2018 by Tayyab • edited Nov 6, 2019 by Tayyab
1

You need to add Windows Integrated Authentication to IIS. Check if it is installed:

Start > Run > inetmgr Click Authentication

enter image description here

If Windows Integrated is missing you will need to install it following these steps:

On Client OS:
Start > Run >appwiz.cpl
Click 'Turn Windows features on or off'
Scroll down to Internet Information Services and expand it
Expand World Wide Web Services
Expand Security
Check off the Authentication methods you need (Windows Integrated)

On Server OS:
Go to your server manager (start->Administrative tools-> Server Manager)
Expand Roles and Web Server (IIS)
Scroll down to Role Services, and click Add Role Services on the right
Enable all the types you need under the security section

answered on Stack Overflow Jan 8, 2018 by Jeremy Thompson

User contributions licensed under CC BY-SA 3.0