我应该从服务层返回什么? DotNetOpenAuth
我想知道在这种情况下我应该返回什么。我的用户界面和服务层位于不同的项目中。
这就是发生的事情
->用户来到网站 ->用户选择 openId 提供商并点击登录 ->发回控制器
[HttpPost]
public ActionResult Login(LoginViewModel loginViewModel)
{
var test = accountService.SendOpenIdRequest(loginViewModel.OpenId);
}
public class LoginViewModel
{
public OpenId OpenId { get; set; }
}
所以我接受一个包含我的域类的 ViewModel。
public class OpenId
{
public string Url { get; set; }
}
到目前为止,在我的 SendOpenIdRequest
public ? SendOpenIdRequest(OpenId openId)
{
var openIdRelyingParty = new OpenIdRelyingParty();
var response = openIdRelyingParty.GetResponse();
Identifier id;
if (Identifier.TryParse(openId.Url, out id))
{
try
{
var req = openIdRelyingParty.CreateRequest(openId.Url);
return req.RedirectingResponse
}
catch (ProtocolException ex)
{
}
}
return null;
}
Now 中,这是我迷失的地方,因为它们是我可以返回的很多东西。
我可以返回
return req.RedirectingResponse.AsActionResult()
但是我认为这会很糟糕,因为现在我依赖于 asp.net mvc ActionResult 并且如果我说将此服务层用于其他一些项目(也许我有一个连接到移动应用程序的 Web 服务)。它不会运作得很好。
我可以返回 OutgoingWebResponse
,但我不太确定在取回它后该如何处理它。
我还可以返回从 CreateRequest() 生成的 IAuthenticationRequest
最后,我可以返回我的域对象(OpenId)以及上面列出的对象之一。
I am wondering what should I return in this case. My Ui and service layer are in different projects.
This is what happens
-> User Comes to Site -> User chooses openId provider and hits login -> Post back to controller
[HttpPost]
public ActionResult Login(LoginViewModel loginViewModel)
{
var test = accountService.SendOpenIdRequest(loginViewModel.OpenId);
}
public class LoginViewModel
{
public OpenId OpenId { get; set; }
}
So I take in a ViewModel that contains my domain class.
public class OpenId
{
public string Url { get; set; }
}
So far in my SendOpenIdRequest
public ? SendOpenIdRequest(OpenId openId)
{
var openIdRelyingParty = new OpenIdRelyingParty();
var response = openIdRelyingParty.GetResponse();
Identifier id;
if (Identifier.TryParse(openId.Url, out id))
{
try
{
var req = openIdRelyingParty.CreateRequest(openId.Url);
return req.RedirectingResponse
}
catch (ProtocolException ex)
{
}
}
return null;
}
Now this is where I get lost since their are so many things I could return.
I could return
return req.RedirectingResponse.AsActionResult()
However I think this would be bad as now I am depending on asp.net mvc ActionResult and if I say use this service layer for some other project(maybe I have a webservice that connects to a mobile application). It won't won't work to well.
I could return OutgoingWebResponse
but I am not really sure what to do with it once I get it back.
I could also return the IAuthenticationRequest what is generated from CreateRequest()
Finally I could return my Domain Object(OpenId) with one of the ones I listed above in it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以返回一个
OutgoingWebResponse
:然后在您的控制器中:
You could return an
OutgoingWebResponse
:and then in your controller: