Portal development proxy settings and certificates

Source: Internet
Author: User
Tags chrome developer chrome developer tools

I encountered some problems when I first used the portalrest API for development. After a few days, I finally sorted out some issues that need attention before development. Now I have recorded the issues and solutions, for future use.

Development Goal: To obtain user tokens

Development Environment: VM portal forarcgis (glassfish), Local Web Server IIS, JavaScript, html

 

The main problems encountered are:

1. Javascript cross-origin access

2. HTTPS + SSL verification problems

 

I. Javascript cross-origin access

Because the developed web application is deployed on the local IIS, cross-origin access may occur when accessing the Porta in the Virtual Machine. For security reasons, JavaScript does not allow cross-origin access. There are many ways to solve this problem. I am using the Web server to deploy the proxy page. ESRI provides three languages of proxy Page code: ASP. NET, Java/JSP, and PHP. We can download it from the reference link below. Because IIS is used, ASP. NET version proxy is used in this development.

The proxy configuration is divided into four steps:

1. Download and configure the proxy page

Put the proxy file in the Web application directory

Open the proxy. config file in the text editor, add a <serverurl> entry, enter the portal address in the URL, and set matchall to true (requests starting with a URL will all use this proxy)

2. Add code on the Web application page to enable proxy

Add the following code to the initialization function of the Web application page:

3. Set the webapplication Security Mechanism (this step has not been studied in depth. For details, refer to the link)

4. test whether the agent works normally.

For testing, you can use network development and debugging tools, such as firebug or chrome Developer Tools. When our request address is changed to the following example, the request indicates that we have set it successfully.

If 404 error occurs, the program cannot find the proxy. ashx page.

If the 500 error occurs, you can view the response information.

Ii. HTTPS + SSL verification problems

The HTTP request described above returns the 500 error. Based on the response information, it is determined that the remote server certificate is invalid during the HTTPS request, because the Portal Server in the virtual machine does not have a certificate, ESRI proxy access does not support access without signature certificates.

There are two solutions to this problem:

1. Apply for a trusted certificate from the certificate authority, such as Verisign.

2. bypass certificate verification

The first method is too troublesome, and we only use it for testing and development. So here we choose to modify the porxy. ashx file to bypass the certificate verification process so that the verification result will always pass.

Add the following code to proxy. ashx:

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); 

And create a method

private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)    {        return true;    } 

Program running effect:

Page code (the Code was modified from the demo of ESRI Beijing colleague. Thank you ):

<! Doctype HTML> <HTML lang = "en"> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.