简体   繁体   中英

DotNet display different port on same local server

I'm not really familiar with dotnet but need to make some changes to an app built with it. On the app's server, I'm running a Python application on a different port (8050). If I'm in the server and I go to http://127.0.0.1:8050 the Python app displays fine. I'm trying to show the outputs of this via the app written in dot net.

I have a file like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MyProjectDefault" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Test Layout</title>
        <style type="text/css">
            body, html
            {
                margin: 0; padding: 0; height: 100%; overflow: hidden;
            }

            #content
            {
                position:absolute; left: 0; right: 0; bottom: 0; top: 0px; 
            }
        </style>
    </head>
    <body>
        <div id="content">
            <iframe width="100%" height="100%" frameborder="0" src="127.0.0.1:8050" />
        </div>
    </body>
</html>

This does not work and the iframe isn't the right approach, but it's roughly what I would like to happen. I want the dot net page to render the content shown on port 8050. Is there any way to make this happen?

The Default.aspx.cs page seems pretty simple too:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MyProjectDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

if any changes there would help.

Thank you!

This won't work. .Net has nothing to do with it. This is because how iframe works. It does not matter where you host it, the url inside the iframe is always referred from client machine. So, anyone opening the app is actually looking for 127.0.0.1:8050 on their machine, which does not exist. You can only view this from the server itself, because at that time the target 127.0.0.1:8050 is the server itself.

You will need to host the application with a public domain or at least with a public static ip address that points to the machine hosting the python website. Then use that url inside the iframe.

Having an iframe is exactly same as opening a browser and putting that url in the address bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM