Is it possible to call aspx page from php web site?

Last post 05-11-2008 5:48 PM by alacevic. 2 replies.

Sort Posts:

  • Is it possible to call aspx page from php web site?

    01-24-2008, 10:20 AM
    • Loading...
    • xesteban
    • Joined on 08-30-2006, 11:51 AM
    • Posts 29

    I have a web site developed in php.  I need to call an aspx page from a php page.

    1. Is it possible?

    2. If yes, how could I do it?

    3. If yes, is it necessary to have the aspx page located in the php server?

    Thanks.

  • Re: Is it possible to call aspx page from php web site?

    01-24-2008, 10:33 AM
    Answer
    • Loading...
    • Curt_C
    • Joined on 07-23-2003, 4:27 PM
    • Stevens Point, WI - USA
    • Posts 4,285
    • Moderator

    depends on what you mean by "call"...

    Yes you can navigate to them...that should be no different then navigating to ANY page.

    As for it's location.... as long as the "php server" is windows based and supports .Net then yes you can have the pages there, but you dont need to.

    Curt Christianson
  • Re: Is it possible to call aspx page from php web site?

    05-11-2008, 5:48 PM
    • Loading...
    • alacevic
    • Joined on 05-11-2008, 3:42 PM
    • Posts 1


    Yes, you can!
    Here are the steps:
    1. call the asp.net page with all headers that the browser supplied (including all cookies!)
    2. parse the response and set headers that the asp.net page returned (like cookies, you don't want to loose the cookies!)
    3. write any headers you wish to the browser.
    4. when you are satisfied with your headers, you may then write your page contents incorporating your asp.net page body into your php page. This step is done only AFTER you write out any headers you wish to send because as soon as you write any page contents the headers will be sent and you won't be able to add any headers later in the page. You can use buffering to get around this issue... read on.

    This script, the call to the asp.net page, should come first before any php page contents are written! 


    <?php
     
      //Send a request to our aspx (asp.net) page exactly as it came in to us, with all cookies and all headers intact!
      //then on the way back, set cookies and other headers returned to us from aspx page.
      //This way this php script acts as a proxy to our aspx page and nothing is lost!
      //For example, if you set a cookie in the aspx page, it won't be lost, the client (the browser in this case) will receive it!
      $options = array('headers'=>http_get_request_headers());
     
      //echo 'Sending in:<br/>';
      //print_r($options);
     
      //echo 'Response:';
      $full_response = http_get('http://localhost/pub/blog/blogheader.aspx', $options, $info);
     
      //parsing the returned http message is done with http_parse_message() function,
      //which returns an object with the headers, body, and other parameters.
      //ref: http://www.nusphere.com/kb/phpmanual/function.http-parse-message.htm
      $parsed_response = http_parse_message($full_response);


      //write headers before any content from the asp.net page.
      //------------------------------------------------------------------
      foreach ($parsed_response->headers as $key=>$value)
      {
        //DO NOT forward content-length header!
        if($key != 'Content-Length')
        {
          //forward only cookies from the aspx page to browser:
          //--------------------------------------------------------------------------------------
          if($key == 'Set-Cookie')
          {
            foreach ($value as $val)
              header('Set-Cookie' . ': ' . $val, false);
          }

          //uncomment this if you want to forward all headers:
          //else
          //header($key . ": " . $value);
        }
      
      }

    ?>


    When you are done forwarding the cookies, (or other headers) from asp.net page, only then may you write the actual page contents!
    You have to set the outgoing headers BEFORE you write any page text, if your page output is not buffered (it is not by default).
    You can use ob_start(); ob_end_flush(); to buffer your output. Then you could write the headers anywhere in your php script.

    <?php
     
      echo 'response from aspx page:';
      //print $parsed_response->responseCode;
      //print_r($parsed_response->headers);
     
      //output the html body of the asp.net page:
      print $parsed_response->body;
     
      //if you wish to see all parameters:
      //print_r($parsed_response);
    ?>


     

    Good luck,

    -Ahmed Lacevic



Page 1 of 1 (3 items)
Microsoft Communities
Page view counter