简体   繁体   English

使用 .NET Core 在浏览器中更新显示的 URL

[英]Updating the displayed URL in the browser using .NET Core

So, I have a certain webpage (view) that I have created.所以,我有一个我创建的网页(视图)。 I have a requirement where I need to update the displayed URL in the browser's to show a different path to this page and update the querystring.我有一个要求,我需要更新浏览器中显示的 URL 以显示此页面的不同路径并更新查询字符串。

Update: I don't want to actually redirect the page, this is merely a cosmetic update.更新:我不想实际重定向页面,这只是一个外观更新。 To make the URL appear differently that what it was.为了使 URL 看起来与原来不同。 It's a requirement our customer support team wanted.这是我们的客户支持团队想要的要求。 :p :p

Ex.前任。 https://www.myserver.com/error/ https://www.myserver.com/error/

I need to update the path in the URL depending on the type of error, like so: https://www.myserver.com/#/order-completed?var=someguid我需要根据错误类型更新 URL 中的路径,如下所示: https://www.myserver.com/#/order-completed?var=someguid

My error page handles various situations you see.我的错误页面处理您看到的各种情况。 I know this is easily done in JS, but I want to be able to do this from my error page Controller.我知道这在 JS 中很容易做到,但我希望能够从我的错误页面 Controller 中做到这一点。

Could someone lend a hand?有人可以帮忙吗? I'd super appreciate it!我会非常感激的!

I think "update the path" means you simply have to redirect the browser to that url.我认为“更新路径”意味着您只需将浏览器重定向到 url。 If you are using ASP.NET MVC, you can use the Redirect controller method like this:如果您使用的是 ASP.NET MVC,则可以使用重定向 controller 方法,如下所示:

return Redirect("https://www.myserver.com/#/order-completed?var=someguid");

So, I went the way of JS afterall.所以,我还是走上了 JS 的路。 I call it from window.onload in the View.我从视图中的 window.onload 调用它。

var fromController = '@ViewData["NewURL"]';
histoy.pushState(null, '', fromController);

In the Controller, in the Index() action在 Controller 中,在 Index() 操作中

ViewData["NewURL"] = @"/myURL/myview?user=2342434";
return View();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 核心图像在 Outlook 中不显示(在浏览器 src 中被阻止的imagesrc) - asp.net core image is not displayed in outlook (in browser src is blockedimagesrc) .NET Core,Angular2,NancyFX-404在浏览器中更改URL - .NET Core, Angular2, NancyFX - 404 changing URL in browser 如何使用 ASP.NET core mvc 中的下拉列表更新每页显示元素的数量? - How to updating number of displayed elements per page with a drop down list in ASP.NET core mvc? 如何从 ASP.NET Core Web API 返回 JSON,以便在浏览器中正确显示格式? - How to return JSON from a ASP.NET Core Web API, such that it's displayed properly formatted in the browser? 分页不更新目标-使用Ajax的Asp.Net Core - Pagnation not updating target - Asp.Net Core using Ajax NET Core 6 使用 DTO 更新数据库记录时遇到问题 - NET Core 6 Trouble updating a DB record using a DTO 在ASP.NET Core中使用Ajax更新下拉列表 - Updating dropdown list using Ajax in ASP.NET Core 使用 selenium 和 .NET Core 运行跨浏览器测试 - Running cross browser tests using selenium and .NET Core 使用 .NET Core Razor Pages 将文件下载到浏览器 - Download file to browser using .NET Core Razor Pages 如何使用asp.net在浏览器中更改URL名称 - How to change URL name in browser using asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM