将 iframe 添加到网络表单 asp.net

Adding an iframe to a webform asp.net

我必须在 Web 表单中添加 iframe。我必须从 API 调用第三方服务获取 url,该第三方服务是支付服务并显示 iframe。我正在使用 ASP.NET 4.5 和 C# 6.0 版本。

这是网络表单代码。 iframe 代码是从 asp.net mvc 代码中复制的,其中也实现了 iframe。我正在尝试在网络表单中实现类似的东西。我知道webfroms里没有模型。

MyWebform.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
   
<div class="row ">
         <div class="col-md-12">
            <div class="panel panel-primary panel-title">
            <div class="panel-heading text-bold">My Component Iframe</div>
            <div class="panel-body">
                <iframe id="thirdPartyiframe" name="client" style="width: 100%; height: 600px; position: center; left: 0; top: 0; border: thick"></iframe>
                <form action="@MyModel.IframeUrl" id="initForm" target="client" method="POST" style="display:none">
                    <input name="BEARER-TOKEN" value="@MyModel.AgentAccessToken"/>
                    <input name="REFRESH-TOKEN" value="@MyModel.AgentRefreshToken"/>
                </form>
            </div>
        </div>

    </div>
</div>
 
    
    <script>
        document.getElementById("initForm").submit();
    </script>
</body>
</html>

页面隐藏代码的代码。 MyWebform.aspx.cs

public partial class MyWebform : System.Web.UI.Page
{
   
    private MyClient _apiClient;

    public MyWebform()
    {
    }


    protected async Task Page_Load(object sender, EventArgs e)
    {
        var model = new PaymentRequestModel
        {
            FirstName = "John",
            Surname = "Smith",
            Email = "smith.john@gmail.com",
            Street1 = "",
            City = "Indianapolis",
            State = "IN",
            Country = "USA",
            Zip = "",
            Currency = "USD",
            Amount = 100.00,
            AgentId = "5551",
            AccountConfigurationId = 1,
                    
        };
        CreateSessionResponse paymentSessionResponse  = await _apiClient.MakePaymentSession(model);

        //assign iframe url - TO DO
        string url = paymentSessionResponse.IframeUrl;  
  
        //assign tokens
        string accToken =  paymentSessionResponse.accToken;
        string refToken = paymentSessionResponse.refToken;
    }
   
   
}

paymentSessionResponse 对象将具有生成的 iframe url,我需要 assign.When 我调试,控件永远不会进入页面加载方法。

关于如何实现此目标的任何想法?我需要使用用户控件吗?

我们可以这样做 -

MyWebform.aspx

<asp:Content ID="content" ContentPlaceHolderID="ContentPlaceHoldeMyForm"  runat="server">
<div class="row ">
         <div class="col-md-12">
            <div class="panel panel-primary panel-title">
            <div class="panel-heading text-bold">My Component Iframe</div>
            <div class="panel-body">
                <iframe id="thirdPartyiframe" name="client" style="width: 100%; height: 600px; position: center; left: 0; top: 0; border: thick"></iframe>
                <form action="<%= Session["IframeUrl"].ToString() %>" id="initForm" target="client" method="POST" style="display:none">
                    <input name="BEARER-TOKEN" value="<%= Session["AgentAccessToken"].ToString() %>"/>
                    <input name="REFRESH-TOKEN" value="<%= Session["AgentRefreshToken"].ToString() %>"/>
                </form>
            </div>
        </div>

    </div>
</div>

对于隐藏代码,我们可以像这样设置会话和调用

MyWebform.aspx.cs

 public async void MainMethod()
 {
    var res = await GetDetails();
    SetSessions(res);
 }

 public void SetSessions(CreateSessionResponse obj)
 {
        Session["AgentAccessToken"] = obj.agentAccessToken;
        Session["AgentRefreshToken"] = obj.AgentRefreshToken;
        Session["IframeUrl"] = obj.IframeUrl;
 }


 protected async Task<paymentSessionResponse> GetDetails()
    {
        var model = new PaymentRequestModel
        {
            FirstName = "John",
            Surname = "Smith",
            Email = "smith.john@gmail.com",
            Street1 = "",
            City = "Indianapolis",
            State = "IN",
            Country = "USA",
            Zip = "",
            Currency = "USD",
            Amount = 100.00,
            AgentId = "5551"                                
        };
        CreateSessionResponse paymentSessionResponse  = await 
       _apiClient.MakePaymentSession(model);
       
        return paymentSessionResponse;
      
    }