简体   繁体   English

如何在OData asp.net Web API中创建注册用户操作

[英]How to create a Register User action in OData asp.net Web API

I am trying to implement a method for registering a user in my OData based asp.net Web API. 我正在尝试实现一种在基于OData的asp.net Web API中注册用户的方法。 The ploblem is i would like to have it on the root url followed by /Register. 问题是我想将其放在根目录上,然后是/ Register。

The register action itself makes use of a RegisterModel which contains the right information to create the user. register动作本身利用RegisterModel,其中包含创建用户的正确信息。

I have tried to add a custom action in the WebApiConfig. 我试图在WebApiConfig中添加自定义操作。 Problem with this is that OData then expects a simple parameter and sending whole models over won't succeed. 问题在于,OData然后需要一个简单的参数,并且无法成功发送整个模型。

Simple action specification like below won't work for me. 像下面这样的简单动作说明对我不起作用。 The endpoint can be found but the model is always 'null'. 可以找到端点,但是模型始终为“空”。

var actionRegister = builder.Action("Register");
actionRegister.Parameter<RegisterModel>("model");
actionRegister.Returns<IdentityResult>();

The API method is started as follows: API方法如下启动:

[AllowAnonymous]
[HttpPost]
[ODataRoute("Register")]
public async Task<IHttpActionResult> Register(RegisterModel model)
{

Any help is welcome. 欢迎任何帮助。 My ultimate goal would be to have a controller call in my user controller that can register users via the route /Register. 我的最终目标是在我的用户控制器中进行一个控制器调用,该调用可以通过路由/ Register注册用户。

请在此处查看http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/ODataActionsSample/ODataActionsSample/示例代码,未绑定函数应满足您的需求。

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

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