[英]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.