. NET access GeoServer published WMS cross-domain problem solution

Source: Internet
Author: User

Environment: Server geoserver2.4.1


There are cross-domain issues with WMS published by the development Machine Access server, and the research has finally found a solution for two days.

The main idea is to use jquery's Ajax instead of the Groserver request, then forward the WMS's requested address to a. NET handler, using. NET handlers for cross-domain processing.

 function mouseclick (e)  {             var layer = new array ();             layer = map.getlayersbyname ("Simple_geometry");             if  (layer != null)                  for  (var i = 0; i  < layer.length; i++)  {                     map.removelayer (Layer[i]);                 }                              var wms_url =  "Http://10.72.4.219:8089/geoserver/xj/wms?";             var params =                       {                          REQUEST:  "Getfeatureinfo",                           bbox: map.getextent (). Tobbox (),                          WIDTH:  map.size.w,                          height: map.size.h,                          X: e.xy.x,                          y: e.xy.y ,                          SERVICE:  "WMS",                          query_ Layers: map.layers[0].params. layers,                          INFO_FORMAT:  ' text/html ',                          feature_count: 50,                          Layers:  ' Xj:cswl_ Group ',                          Styles:  "",                           format:  "APPLICATION/VND.OGC.GML",                          EXCEPTIONS:  " Application/vnd.ogc.se_xml ",                     // Exception  type                           srs:  ' EPSG:4326 '                       };                       var domainUrl =  "Crossdomain.ashx? Url= ";                      var request = parpreurl (Wms_url, params);                      request  = encodeuricomponent (encodeURIComponent (request));                      $.post (domainUrl +  request,  "", function  (e)  {                          document.getelementbyid (' nodelist ') .innerhtml = e;                      });                                  openlayers.event.stop (e);         }        function  parpreurl (url, paramsobj)  {             for  (var k in paramsobj)  {                 url +=  (k +  "="  + paramsobj[k]  +  "&"); &NBSP;&NBSP;&Nbsp;                          }             return url;        }

If you use Groserver.proxyhost, you will encounter triggerevent undefined problem, so use Jqueyr Ajax instead of Geoserver.request, plus

 public void processrequest (Httpcontext context)          {            context. response.contenttype =  "Text/html";             string url =  "";             url = context. request.querystring["URL"]. ToString ();             url = context. Server.urldecode (URL);             httpwebrequest  loHttp =  (HttpWebRequest) webrequest.create (URL);             loHttp.Timeout = 10000;     // 10  Secs            lohttp.useragent =&nbSP; " Web client ";            httpwebresponse  lowebresponse =  (HttpWebResponse) lohttp.getresponse ();             encoding enc = encoding.getencoding (65001);             StreamReader loResponseStream = new  StreamReader (Lowebresponse.getresponsestream (),  enc);             string lchtml = loresponsestream.readtoend ();             context. Response.Write (lchtml);             Lowebresponse.close ();             Loresponsestream.close ();         }


This will solve the cross-domain problem

This article is from the "hb407033" blog, make sure to keep this source http://hb407033.blog.51cto.com/7387236/1433902

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.