asp.net-web-api2

Global variable in Web API

和自甴很熟 提交于 2019-12-11 12:57:54
问题 I have a Web API application that is authenticated using a combination of userid and an APIKey as part of the RequestMessage. In my authorization filter I check if the combination is valid before proceeding. I then need to use the userid to log some actions in my controllers. The UserID and key are encoded together. Something like: .../api/v1/Transaction?api_key=YmFyZGFnYWR2ZXJndXI The problem I am having is how to expose the userid to the controller. 回答1: Using the comment from Chips_100 I

Method name conventions in Web API 2 [closed]

試著忘記壹切 提交于 2019-12-11 12:56:01
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Is there a list of what conventions are used in Web API 2? Take these two methods for example. Both work, neither are decorated with attributes. IHttpActionResult GetMyModel(int id) IEnumerable<MyModel> GetAllMyModels() Get responds to the route "{controller}/{action}/{id}", so I

Make local web api call from local web forms app

柔情痞子 提交于 2019-12-11 12:43:25
问题 I want to know if its possible to make this call: jQuery.ajax({ type: "POST", url: "http://localhost:5832/api/Login", data: "{username: user1, password:'123456'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { alert(data.d); } }); Which is basically call to this web api controller: public class LoginController : ApiController { [System.Web.Http.AcceptVerbs("POST")] public HttpResponseMessage Post(string username, string password) { string

ActionContext.ActionArguments Is Empty In IAuthenticationFilter

☆樱花仙子☆ 提交于 2019-12-11 12:19:44
问题 Background: I want to authenticate a POST request to my web API using an implementation of IAuthenticationFilter injected using Ninject. To authenticate a request I need access to request body. Problem: ActionContext.ActionArguments , which I usually use to access request payload, is empty when I try to access it inside the filter. Question: How to access POST request payload inside an IAuthenticationFilter implementation? Why ActionContext.ActionArguments is empty inside an

How to return bearer token from HttpresponseMessage Asp.net Web Api

只愿长相守 提交于 2019-12-11 12:07:52
问题 How can I return token from web api so that I can set cookie of that token in javascript? In this way I am generating token [Route("api/agency/login")] [HttpPost] public HttpResponseMessage loginApi([FromBody] Users UserObj) { var tokanObj = method.AccessToken(UserObj.username, UserObj.Password, "password"); //How to return this token ?? } 回答1: Did you try StringContent ? return new HttpResponseMessage( HttpStatusCode.OK ) { Content = new StringContent( "Your token here" ) }; 回答2: You can

Web API 2 cannot register user

给你一囗甜甜゛ 提交于 2019-12-11 11:05:45
问题 I have a Web API 2 project using MVC. It uses entity framework. This entity framework uses a database first approach with a .edmx file. The project is based on VS 2013 Express Web API 2 template. I just used my own database. I didn't modify any account related code. But when I try to register a new user, the following statement in AccountController.cs throw exception: public async Task<IHttpActionResult> Register(RegisterBindingModel model) { ... IdentityResult result = await UserManager

How to construct ISecureDataFormat<AuthenticationTicket> with unity

情到浓时终转凉″ 提交于 2019-12-11 10:49:22
问题 I have consturctor on my webapi account controller looking like that: public AccountController(ApplicationUserManager userManager, ISecureDataFormat<AuthenticationTicket> accessTokenFormat) { _userManager = userManager; AccessTokenFormat = accessTokenFormat; } But Unity is not able to consruct the ISecureDataFormat<AuthenticationTicket> because the constructor is not working untill I taking off the second param. public AccountController(ApplicationUserManager userManager) { _userManager =

c#, web api, swashbuckler/swagger

两盒软妹~` 提交于 2019-12-11 10:46:29
问题 This is my first web api, first web app, and first time Ive used swagger via swashbuckler. I'm using TPH for my equipment db table. For example, I have base class called equipment with several child classes inherited from equipment. (This isnt real code so Ive not put in all the publics etc) As I sorta expect, the model description when I run swagger in my browser, just returns the model for the equipment class I've googled how to show all possible models but can't understand the replies as

How to store token in mvc cookie and send it to api

老子叫甜甜 提交于 2019-12-11 10:42:30
问题 I am sending credentials to API which creates user then through MVC Login method i create token in Web API and return token in response to MVC now I want to store Token in MVC Cookie and again send it Web API when hitting API Controller authorized action. Please suggest me these two things 回答1: There's not a whole lot to work with here, but generally speaking, Web API diverges from MVC mostly in that it's fully REST-compliant, whereas MVC is not. REST-compliant applications are stateless (in

Generate Access Token In Web Api action method using OWIN and IIS host

痴心易碎 提交于 2019-12-11 10:26:43
问题 I'm trying to generate a token inside Web Api action method based on the code below: private JObject GeneratePaymentTokenResponse(string email, bool rememberMe) { //var tokenExpiration = rememberMe ? TimeSpan.FromDays(14) : TimeSpan.FromMinutes(30); var tokenExpiration = rememberMe ? TimeSpan.FromMinutes(30) : TimeSpan.FromMinutes(5); ClaimsIdentity identity = new ClaimsIdentity("CustomType", ClaimTypes.Email, ClaimTypes.Role); identity.AddClaim(new Claim(ClaimTypes.Email, email)); var props