我在Blazor Server应用程序剃须刀页面中有一个iframe,该页面定义了外部URL。如何使用按钮强制刷新此URL(重新加载)?

发布于 2025-02-13 15:48:23 字数 1644 浏览 0 评论 0原文

我有一个Blazor Server应用程序。在其中一个剃须刀页面中,在iframe中显示了一个外部URL(... index.php)。我有一些按钮将一些信息写入Exchange TXT文件。 按下每个按钮后,URL不会更改。我只需要回忆起URL,以便称为index.php应读取Exchange文件中的新数据。我如何强制刷新或重新加载我的iframe中的URL?我的代码是:

@page "/explorer"
@using System.Diagnostics
@using System.IO;
@inject AuthenticationStateProvider _authenticationStateProvider
@using Microsoft.AspNetCore.Http
@inject IHttpContextAccessor httpContextAccessor
<html>
<body>

<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="C"; File_Explorer();})">C:\</button>
<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="D"; File_Explorer();})">D:\</button>
<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="E"; File_Explorer();})">E:\</button>
<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="F"; File_Explorer();})">F:\</button>


<iframe name="web" src=@URL_Explorer width="1500px"
        height="800px" frameBorder="0">
</iframe>


@code{
    
    public static string CurrentUserName { get; set; }
    public static string CurrentUserName_trimmed { get; set; }
    public string user_path_total;
    public static string Drive_Letter;
    public string URL_Explorer { get; set; }="";

    public void File_Explorer()
    {
        
        using (StreamWriter writer = new StreamWriter(exchange_file, append: false))
        {
            writer.Write("\\\\" + Connect2.MAE_IP_Win + "\\" + Drive_Letter + "$");
            writer.Close();
        }
        
        URL_Explorer = "https://server:8092/index.php" ;
    }


}

I have a Blazor server app. In one of the razor pages there is shown an external URL (...index.php) in an iframe. I have some buttons that are writing some information into a exchange txt file.
After pressing each button the URL is not changing. I just have to recall the URL, so that the called index.php shall read the new data in the exchange file. How can I force to refresh or reload the URL in my iframe? My Code is:

@page "/explorer"
@using System.Diagnostics
@using System.IO;
@inject AuthenticationStateProvider _authenticationStateProvider
@using Microsoft.AspNetCore.Http
@inject IHttpContextAccessor httpContextAccessor
<html>
<body>

<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="C"; File_Explorer();})">C:\</button>
<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="D"; File_Explorer();})">D:\</button>
<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="E"; File_Explorer();})">E:\</button>
<button class="btn btn-primary" @onclick="@(() => { @Drive_Letter="F"; File_Explorer();})">F:\</button>


<iframe name="web" src=@URL_Explorer width="1500px"
        height="800px" frameBorder="0">
</iframe>


@code{
    
    public static string CurrentUserName { get; set; }
    public static string CurrentUserName_trimmed { get; set; }
    public string user_path_total;
    public static string Drive_Letter;
    public string URL_Explorer { get; set; }="";

    public void File_Explorer()
    {
        
        using (StreamWriter writer = new StreamWriter(exchange_file, append: false))
        {
            writer.Write("\\\\" + Connect2.MAE_IP_Win + "\\" + Drive_Letter + "
quot;);
            writer.Close();
        }
        
        URL_Explorer = "https://server:8092/index.php" ;
    }


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

变身佩奇 2025-02-20 15:48:23

更改URL后,您尝试使用stateHaschanged()?

You try with StateHasChanged() after change the url?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文