【发布时间】:2020-06-19 14:47:07
【问题描述】:
在这里感谢任何帮助,
我刚刚开始使用 Blazor,创建了一个针对 Web 程序集的基本客户端/服务器项目。 在服务器端添加了一个新的控制器,它是
public async Task<IActionResult> GetEncryptedDataAsync()
返回
return await Task.FromResult(new JsonResult(model));
下面是我从 razor 页面调用的控制器方法
[HttpGet]
public async Task<IActionResult> GetEncryptedDataAsync()
{
var model = new DecryptViewModel
{
ApiKey = _appsettings.Value.Checkout.InboundApikey,
Sharedsecretkey = _appsettings.Value.Checkout.InboundSharedsecret,
EncKey = "XoSVc/2E717Ivf56JUEMn2",
EncPaymentData = "S7e9mZy9GrZtaEC/s0f2/4hj1lq" };
return await Task.FromResult(new JsonResult(model));
}
在客户端,在 index.razor 中
@page "/"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Zapy.Shared.ViewModels;
@using System.Net.Http
@inject HttpClient Http
@attribute [Authorize]
<br />
<div class="card card-nav-tabs navbar-dark text-left">
<div class="card-header card-header-primary"><strong>Decryption</strong></div>
<div class="card-body">
<h4 class="card-title">Enter encrypted payload below</h4>
<EditForm Model=@decryptViewModel OnSubmit=@SubmitData>
<DataAnnotationsValidator />
<ValidationSummary />
<div class="form-group">
<label for="apikey">Apikey</label>
<InputText Id="apikey" class="form-control" @bind-Value="decryptViewModel.ApiKey" />
</div>
<div class="form-group">
<label for="Sharedsecretkey">Sharedsecret</label>
<InputText Id="Sharedsecretkey" type="password" class="form-control" @bind-Value="decryptViewModel.Sharedsecretkey" />
</div>
<div class="form-group">
<label for="encKey">Enckey</label>
<InputText Id="encKey" class="form-control" @bind-Value="decryptViewModel.EncKey" />
</div>
<div class="form-group">
<label for="encPaymentData">encPaymentData</label>
<textarea Id="encPaymentData" class="form-control" @bind="decryptViewModel.EncPaymentData" rows="15"/>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</EditForm>
</div>
<div class="card-footer text-muted">
2 days ago
</div>
</div>
<br />
<div id="DisplayResults" class="card card-nav-tabs text-left">
<div class="card-header card-header-primary"><strong>Results</strong></div>
<div class="card-body ">
<pre id="jsonResults"></pre>
</div>
</div>
code {
private DecryptViewModel decryptViewModel = new DecryptViewModel();
protected override async Task OnInitializedAsync()
{
try
{
decryptViewModel = await Http.GetFromJsonAsync<DecryptViewModel>("api/CheckoutService/GetEncryptedDataAsync");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}
async Task SubmitData()
{
try
{
decryptViewModel.Result = await Http.GetFromJsonAsync<string>("GetResult");
}
catch (AccessTokenNotAvailableException exception)
{
exception.Redirect();
}
}
}
【问题讨论】: