Proxy problems

5261
29
Jump to solution
10-23-2018 08:49 AM
MKF62
by
Occasional Contributor III

I'm quite confused on how to get this proxy working. 

I've secured one geoprocessing service called Habitat Management. It is located in the HabitatManagement folder, the service is titled HabitatManagement, and it contains a geoprocessing task called HabitatManagement. Essentially, the url for the secured service looks like this:

https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat...

The actual web mapping application resides inside of a .NET application. The URL of the .NET application is this:

https://www.mydomain.com/appName

The actual web map url is this:

https://www.mydomain.com/appName/HabitatMap/HabitatJSMap

I have my proxy config file set up like so:

<ProxyConfig allowedReferers="https://www.mydomain.com/appName/*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/"
                  username="username"
                  password="password"
                  matchAll="true"/>
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I have the proxy JS code like this:

urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com",
                proxyUrl: "https://www.mydomain.com/appName/proxy/proxy.ashx"
            });‍‍‍‍

If I go to the proxy page following this URL:

https://www.mydomain.com/appName/proxy/proxy.ashx

It works as expected, it says "Config File: "OK" Log File: "OK""

When I test this URL, it takes me to the HabitatManagement folder but does not show the services within it, even though the token should be passing the username and password so I can see the services, right? That's issue #1 that I don't understand.

https://www.mydomain.com/appName/proxy/proxy.ashx?https://www.mydomain.com/myServer/rest/services/Ha...

Additionally, when I go the web map and try to access the service, it still makes me login with this message:

Please sign in to access the item on https://www.mydomain.com/myServer (HabitatManagement/HabitatManagement)

If I login, things work fine - it appears the token is generated and appended to the URL as it should be.

If I change the config file serverURL to this (note the extra "HabitatManagement" on the end of the URL):

<serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement"
                  username="username"
                  password="password"
                  matchAll="true"/>‍‍‍‍‍‍‍‍

and try this URL, the request fails with "Bad Request" error:

https://www.mydomain.com/appName/proxy/proxy.ashx?https://www.mydomain.com/myServer/rest/services/Ha...

and if I test it in the application it still prompts me to login with the same message as before.

I have also tried to change my serverURL to something very general with no luck. Ideally, the serverURL would be more specific than this as there are some services we have that don't require authentication thus do not need to run through a proxy.

<serverUrl url="https://www.mydomain.com"
                  username="username"
                  password="password"
                  matchAll="true"/>‍‍‍‍

I'm not sure if my proxy is located in the wrong spot, or if my referrer URL is messed up, or if my serverURLs are messed up. How do I access my secured services using the proxy?

0 Kudos
29 Replies
MKF62
by
Occasional Contributor III

Have added it. Now prompting me to log in to view the data on the map, so it's still not generating a token for some reason.

<ProxyConfig allowedReferers="https://www.mydomain.com/*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat..."
                 username="username"
                 password="password"
                 matchAll="true"/>
      <serverUrl url="https://www.mydomain.com/appName/HabitatMap/HabitatJSMap"
                 password="username"
                 password="password"
                 matchAll="true" />
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Getting a 404 Resource Not Found error. I wonder if it's because I have a relative path as my proxy path?

It says this, so that might be it:

<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
<br><br>

<b> Requested URL: </b>/proxy/proxy.ashx<br><br>

The URLs it's trying to place a request with also are off:

https://www.mydomain.com/proxy/proxy.ashx?https://www.mydomain.com/myServer/rest/services/… 

I wonder if I change the JS to this if it would work? Or may make the proxyUrl property an absolute path instead of relative. I will play around with it.

//Set up the proxy to forward requests for data/geoprocessing tools
            urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com/appName/HabitatMap/HabitatJSMap",
                proxyUrl: "/proxy/proxy.ashx"
            });
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

  Are there secured service in the map? Are you using an WebMap from AGOL or Portal?

0 Kudos
MKF62
by
Occasional Contributor III

Just edited my answer above, but yeah, the MapServer data is secured as well as one other GP service than the one already mentioned, so that's why I'm getting a login page for the whole map now. I could turn security off for those services and just leave the one aformentioned GP service secured and see what happens.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

No need for that just add serverUrls for each secured service to the proxy config.

0 Kudos
MKF62
by
Occasional Contributor III

Alright. I have all the services in the config file. Now, no login prompts, however no data on the map either. I am getting a lot of "resource not found" in the console. 

Network tab snippet:

When I go look in the header and response for details, this is in the response:

<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

<h2> <i>The resource cannot be found.</i> </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
<br><br>

<b> Requested URL: </b>/proxy/proxy.ashx<br><br>

So it seems like it can't find the proxy URL which suggests that my JS code needs to be altered in some way, right? I changed my proxyUrl to be an absolute path but that has not changed anything. 

//Set up the proxy to forward requests for data/geoprocessing tools
            urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com/",
                proxyUrl: "https://www.mydomain.com/appName/proxy/proxy.ashx"
            });‍‍‍‍‍‍‍‍‍‍

I have also tried this because I'm not entirely sure what the urlPrefix does:

//Set up the proxy to forward requests for data/geoprocessing tools
            urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com/appName",
                proxyUrl: "/proxy/proxy.ashx"
            });
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Given where the proxy sits in the application, I think the proxy would be located at https://www.mydomain.com/appName/proxy/proxy.ashx. The proxy folder sits under the root folder "appName" in my visual studio solution explorer which creates all the URLs and what not.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

  Can you show me the serverUrl url that you added for your secure service (replacing sensitive info, but not over doing it)? It sounds like it is not the proxy url that it can't find but the map service url.

0 Kudos
MKF62
by
Occasional Contributor III

My bad, I didn't publish my app quite right after changing the JS, so I redid it and now I get the log in prompt again (no "resource not found" errors). Just to clarify everything...

Current JS:

//Set up the proxy to forward requests for data/geoprocessing tools
            urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com/appName",
                proxyUrl: "/proxy/proxy.ashx"
            });
‍‍‍‍‍

Current config:

<ProxyConfig allowedReferers="https://www.mydomain.com/*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/appName/HabitatMap/HabitatJSMap"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat..."
                 username="username"
                 password="password"
                 matchAll="true"/>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/0"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/1"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/2"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/3"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/4"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/5"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatClassification/GPServer/Hab..."
                 username="username"
                 password="password"
                 matchAll="true" />
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

  OK you only have to have a serverUrl for each unique map service not each layer in the map service:

<serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer"
  username="username"
  password="password"
  matchAll="true"/>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

and reset your proxy rule to:

            //Set up the proxy to forward requests for data/geoprocessing tools
            urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com",
                proxyUrl: "/proxy/proxy.ashx"
            });
0 Kudos
MKF62
by
Occasional Contributor III

Back to "resources not found" errors when trying to load the map services. No log in window.

GET https://www.mydomain.org/proxy/proxy.ashx?https://www.mydomain.org/myServer/rest/services/HabitatMon... 404 (Not Found)

Config:

<ProxyConfig allowedReferers="https://www.mydomain.com/*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/appName/HabitatMap/HabitatJSMap"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat..."
                 username="username"
                 password="password"
                 matchAll="true"/>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatClassification/GPServer/Hab..."
                 username="username"
                 password="password"
                 matchAll="true" />
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

JS:

//Set up the proxy to forward requests for data/geoprocessing tools
            urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com",
                proxyUrl: "/proxy/proxy.ashx"
            });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Would the way the feature layers are defined possibly pose a problem? I swear I've seen people having trouble with definition expressions and proxies for some reason. Granted I don't know why that would produce 404 errors. Seems unlikely.

 //Add the habitat patches feature layer
            var patchesFL = new FeatureLayer("https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer/2", {
                mode: FeatureLayer.MODE_ONDEMAND,
                autoGeneralize: false,
                refreshInterval: 10,
                visible: false,
                infoTemplate: patchesPopupBox,
                outFields: ["*"]
            });
            patchesFL.setMinScale(500000);
            patchesFL.setSelectionSymbol(selectionSym);
            patchesFL.setDefinitionExpression('ReportingYear = ' + currentYear);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Molly,

  It appears that the proxy url is not defined correctly based on the error:

 https://www.mydomain.org/proxy/proxy.ashx? It seems to be missing the appName portion of the url.

0 Kudos