The software solves the routing backflow problem.

Source: Internet
Author: User

Recently I encountered a backflow problem when using CAS for SSO.

(Brief description of reflux:

The application and service are in the same Intranet IP address, and the service and application are mapped to the Internet IP address. When the application uses the Internet IP address to access the service, the access is denied. Because the ingress detects that the accessed service is on the same Intranet IP address, it can only be accessed through the Intranet IP address, or the routing configuration is changed .)

Here we will introduce the software solution:

Because you cannot directly change the IP Address Configuration to the Intranet IP address for CAS verification, you can only dynamically determine that the address in the URL is automatically replaced with the local address when a webexception occurs, to solve the backflow problem.


The judgment code is as follows (replacelocalip is used to replace the local address)

                try                {                    serverResponse = RetrieveResponseFromServer(validationUrl, ticket);                }                catch (WebException)                {                    validationUrl = ReplaceLocalIP(validationUrl);                    serverResponse = RetrieveResponseFromServer(validationUrl, ticket);                }

Replacelocalip method:

/// <Summary> /// replace it with the local address to address the backflow problem // </Summary> /// <Param name = "validationurl"> </param> // /<returns> </returns> private string replacelocalip (string validationurl) {int iindex = validationurl. indexof ("//"); int iindex1 = validationurl. indexof ("/", iindex + 2); string shostold = validationurl. substring (iindex + 2, iindex1-iindex + 2); string [] arrayadd = shostold. split (':'); arrayadd [0] = "127.0.0.1"; string shostnew = string. empty; foreach (VAR item in arrayadd) shostnew + = item + ":"; shostnew = shostnew. remove (shostnew. length-1); string sresult = validationurl. replace (shostold, shostnew); Return sresult ;}

Related Article

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.