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:
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.
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:
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?
Solved! Go to Solution.
Right, which is why I thought I needed to change the urlPrefix in the JS to include the appName on the end of it. However, when I do that I just get a log in prompt on my web page. I will investigate more tomorrow, burnt out on this today. Thank you for all your help!! You got me a heck of a lot closer to how it needs to work.
I am so so close to having this figured out but wonder if you have any ideas on the last issue I am facing. I have gotten past the issues I was having before, I can now load my map services and successfully upload a file through my geoprocessing service with the app authenticating on behalf of itself using the proxy. The last issue I am facing is that my geoprocessing service takes in parameters, these parameters change with every submission, which means the "submitJob" URL will change every time the geoprocessing service is called upon. I have no idea how to make a server URL to handle that in proxy.config... I was looking at the "matchAll" setting for serverUrls and have tried both true and false to see if it really would forward anything that begins with the specified URL (apparently when it's set to "true" it's supposed to do this) but it doesn't. I can't specify the exact URL as it changes every time and if I just specify "www.mydomain.com" it becomes too general...
Current proxy.config
<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/uploads..."
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/upl..."
username="username"
password="password"
matchAll="true" />
</serverUrls>
</ProxyConfig>
I have tried adding something like this to proxy config which didn't work (no matter if matchAll is true or false):
<serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat..."
username="username"
password="password"
matchAll="true" />
I've also tried editing the GPServer URLs to be more general like the MapServer one with no luck:
<serverUrl
url="https://www.mydomain.com/myServer/HabitatManagement/HabitatManagement/GPServer"
username="username"
password="password"
matchAll="true" />
This is the kind of error I receive in the console:
{"error": {"code": 403,"message":"Proxy has not been set up for this URL. Make sure there is a serverUrl in the configuration file that matches: https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat...
This is how the JS code ended up, turns out I needed to add the appName to the relative path of the proxy:
urlUtils.addProxyRule({
urlPrefix: "https://www.mydomain.com",
proxyUrl: "/appName/proxy/proxy.ashx"
});
Molly,
The generalized url is the best one but you forgot a prat of the url.
<serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer"
username="username"
password="password"
matchAll="true" />
You were missing "/rest/services"
Sorry, that was just an oversight on my part when I was typing it in. I do have the /rest/services in my code. Alright, I'll probably just have to use that generalized URL as a workaround for the time being.
Molly,
What matchAll means is that anything (string) after the url specified will be routed through the proxy. So that mean any url parameters will be matched or in the case of the url in my previous reply it means that all methods in the GPServer service will be matched (i.e. uploads or submitJob).
Then I must have something else wrong since it is not matching even when set to true with a url like the one you just posted. I'm going to make a post on the GitHub page and if I'm lucky maybe the person managing it will actually respond.
Molly,
I have been down this road several times and it is has sometimes been some small CaSe issue in my url (the url is CaSe sensitive). Be sure to tripple check the urls case in the proxy.config
Went to my rest services page and checked them against the URLs. Case is correct as well as spelling. I can't take down my server right now so I'm going to try debugging proxy.ashx file tonight when no one should be using it. Need to see what the incoming URI looks like. The 403 error message above I edited because I thought it was just the way the error message was structured in the proxy.ashx file and it was repeating that big long URL twice, but I checked how the error message should look and it should only be there once I think, so I think my URI is coming in weird.
The full error message was actually this:
{"error": {"code": 403,"message":"Proxy has not been set up for this URL. Make sure there is a serverUrl in the configuration file that matches: https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat...https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/Habitat... } }
I checked my JS code and there's no way it can submit a job twice (and even if it did, the "Input_Zip_File" parameter would be different since the itemID changes on every submit), so something really funky is happening.
Edit: Nevermind, the error message is structured correctly with the repeated URL.
Alright... I have no idea what happened or what I did differently but on the 500th try it started working. If you're searching for proxy answers, read this entire thread because my code changed A LOT between beginning post and this one. The only things I can think of for final changes was that I changed the path to my log file to be accurate in the Web.config file (probably has no bearing on this working). I also changed the other GP service to the have the correct, more general URL (I hadn't earlier because I wasn't testing that service). The last "change" was just republishing my application. Again, no clue what made it start working but something did! Thanks for your help with all of this. Final code:
JS
urlUtils.addProxyRule({
urlPrefix: "https://www.mydomain.com",
proxyUrl: "/appName/proxy/proxy.ashx"
});
proxy.config
<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/"
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/"
username="username"
password="password"
matchAll="true" />
</serverUrls>
</ProxyConfig>
This solution helped me since I was adding my GPServer link with the whole URL, as seen below,
https://<domain>:6443/arcgis/rest/services/<Folder>/<service>/GPServer/Export%20Web%20Map
But then I saw your post and just added until GPServer with a forward slash at the end,
https://<domain>:6443/arcgis/rest/services/<Folder>/<service>/GPServer/
Now it doesn't show the sign-in page and continue directly to the geoprocessing service.
Thanks