我必须在web表单中添加一个iframe。我必须得到的网址从API调用到第三方服务,这是一个支付服务,并显示iframe。我使用的是ASP.NET 4.5和C# 6.0版本。
这是webform代码。iframe代码是从asp.net mvc代码复制而来的,其中也实现了iframe。我正在尝试在webforms中实现类似的东西。我知道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方法。
你知道我该如何做到这一点吗?我需要使用用户控件吗?
发布于 2021-04-20 02:40:45
我们可以这样做-
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;
}https://stackoverflow.com/questions/67069090
复制相似问题