Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What about calling aspx in php?

Tags:

php

asp.net

Here is my code

<html>
<body>

<?php
include("Default.aspx");
?>

</body>
</html>

but it keeps giving me the output of

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <% Response.Write("Hello world!"); %>

I just need to run the Hello World on the site.

like image 523
user197252 Avatar asked Apr 14 '26 11:04

user197252


2 Answers

If you want the output of the aspx file, you will need to request it via a web server which can understand aspx files rather than the file system, e.g.

include("http://example.com/Default.aspx");

Your PHP installation must have URL fopen wrappers enabled for this to work.

As Magnus Nordlander notes in another answer, you should only use include if you expect to find php code in the file. If you don't, you could simply use readfile to output the data verbatim:

readfile("http://example.com/Default.aspx");
like image 120
Paul Dixon Avatar answered Apr 17 '26 02:04

Paul Dixon


You seem to be going about this in a very wrong way.

What include() (and require(), for that matter) does is that it parses the specified file with the PHP interpreter. If your aspx-code for some reason generates PHP-code, which is supposed to be parsed by the PHP interpreter, then the way Paul Dixon suggests would be the right way of going about this. However, I would strongly advice against doing this.

For one thing, it's a huge security disaster waiting to happen. It's also incredibly bad architecturally speaking.

If you want to include HTML markup etc. generated using aspx, what you should do is to use

echo file_get_contents("http://www.example.com/Default.aspx");

This way, any PHP code in the output remains unparsed, thus avoiding the aforementioned security disaster. However, if you're able to do without mixing languages like this, that's probably going to be a much better solution.

like image 37
Magnus Nordlander Avatar answered Apr 17 '26 01:04

Magnus Nordlander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!