简体   繁体   English

Abp从WinForm浏览

[英]Abp browse from WinForm

I try to open a new winForm with abp page. 我尝试用abp页面打开一个新的winForm。 My user has already do login on application via ABP LogInManger and I store my login result. 我的用户已经通过ABP LogInManger在应用程序上登录,我存储了登录结果。

So when I open the new form with webBrowser component the login that I try to pass doesn't work. 因此,当我使用webBrowser组件打开新表单时,尝试传递的登录名无效。

To do login I try: 要登录,我尝试:

  • OAuthBearerAuthenticationOptions OAuthBearerOptions { get; OAuthBearerAuthenticationOptions OAuthBearerOptions {get; set; 组; } but the object it still null. },但该对象仍然为null。 I need to initialize some Owin or is not the correct way? 我需要初始化一些Owin还是不正确的方法?
  • I try to reauthenticate with user and password and put header with Bearer but not work 我尝试使用用户名和密码重新进行身份验证,并在Bearer中放置标头,但不起作用

Any idea to solve this issue? 有解决这个问题的主意吗?

I write a simple case and more details about my solution: - WinForm .Net 4.6.1 - Web Application 4.6.1 based on AbpBolierplate 我写了一个简单的案例以及有关解决方案的更多详细信息:-WinForm .Net 4.6.1-基于AbpBolierplate的Web应用程序4.6.1

We'll create a porting from an old .Net solution and add some new functions. 我们将从旧的.Net解决方案创建移植,并添加一些新功能。 About the new functions the UI is on Abp web and not on WinForm, so to allow user to use this new function we open webBrowser embedded (or not) and we try to authenticate via token. 关于新功能,UI在Abp Web上而不在WinForm上,因此,为了允许用户使用此新功能,我们打开(或不打开)嵌入的webBrowser,并尝试通过令牌进行身份验证。 Right today we talk we other collegue and the solution can be do in this way: 今天,我们谈论其他同事,并且可以通过以下方式解决问题:

  • Create a custom controller on Web to allow post token on it 在Web上创建自定义控制器以允许在其上发布令牌
  • Auth user inside the controller and redirect to requested page 在控制器内对用户进行身份验证并重定向到请求的页面

this question has not a short and correct answer . 这个问题没有一个简短正确的答案 I'll try to guide you with outlines of solution; 我将尝试为您提供解决方案的概述;

You didn't mention whether you are using MVC or Angular! 您没有提到使用的是MVC还是Angular! But if you are using angular it's easier. 但是,如果您使用的是角度,它会更容易。 Just create a RestApi client in your WinForm. 只需在WinForm中创建一个RestApi客户端。 Authenticate to website using Http Post to "api/TokenAuth/Authenticate". 使用Http Post到“ api / TokenAuth / Authenticate”对网站进行身份验证。 Store the token and refresh it before it expires. 存储令牌并在令牌过期之前刷新它。

Use Application services as WebApi endpoints. 将应用程序服务用作WebApi端点。 Add authentication header to every request you make (eg: bearer xxxxxxx_token_xxxxx). 将身份验证标头添加到您提出的每个请求中(例如:bearer xxxxxxx_token_xxxxx)。

If you are using MVC then you can create your own WebApi to authenticate and use required services. 如果使用的是MVC,则可以创建自己的WebApi进行身份验证和使用所需的服务。

Long story short; 长话短说; using WebBrowser to authenticate and consume aspnetboiler website is not a convenient way as you'll have to deal with cookies. 使用WebBrowser认证和使用aspnetboiler网站不是一种便捷的方法,因为您必须处理Cookie。 best practise is using a WebApi for your use cases. 最佳做法是将WebApi用于您的用例。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM