Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SignalR to send page jump notifications

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use SignalR to send page jump notice, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

When Wechat uses Alipay, there needs to be an excessive page that prompts the user to open the page to pay with the browser, and then opens Wechat after the browser has paid (Wechat still displays the transition page at this time). The transition page needs to be redirected to the order details page. So how does this transition page know it needs to be redirected?

All I can think of is to use SigbalR to send a notice telling the excessive page to jump.

The first step is to add SigbalR-related dll.

Step 2, customize the hub

Public class myHub:Hub {public override Task OnConnected () {return base.OnConnected ();}}

The third step is to customize the UserIdProvider, because we need to send a jump notification to the specified user

Public class CustomerUserIdProvider: IUserIdProvider {public string GetUserId (IRequest request) {/ / get the current login user var customer= EngineContext.Current.Resolve () .CurrentCustomer; if (customer==null) {return ";} else {/ / return the current login user id return customer.Id.ToString ();}

Step 4: register our custom UserIdProvider in startup

/ / SignlR var idProvider = new CustomerUserIdProvider (); GlobalHost.DependencyResolver.Register (typeof (IUserIdProvider), () = > idProvider); app.MapSignalR ()

The fifth step is to send the notification in the Alipay payment asynchronous notification plus this line of code, and pass in the parameters of the order number. Here, send a notification to the user of order customerid. The order customerid is the same as the id of the current login. So you can get the message.

Var myHub = GlobalHost.ConnectionManager.GetHubContext (); myHub.Clients.User (order.OrderCustomerId.ToString ()) .redirctOrderDetails (order.OrderNumber)

The sixth step is to accept execution on the transition page

/ / declare that a proxy references the hub, remember $.connection. The first letter of the latter method must be lowercase, which is why I use the alias var chat = $.connection.chinookHub; / / here is the method called by the registration hub, unlike 1.0, which requires registration after chat.client, which does not require chat.client.redirctOrderDetails = function (oerderNumber) {_ window.location.href = "/ Customer/MyOrderDetails?page=4&orderNumber=" + oerderNumber;}. Chat.client.redirctMoneyAccountDetail = function () {_ window.location.href = "/ Customer/AccountDetail/Money";}; / / start connection $.connection.hub.start ()

In this way, you can perfectly jump to the page after the payment is completed. I can't think of a better way so far.

Thank you for reading this article carefully. I hope the article "how to use SignalR to send Page Jump Notification" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report