asp.net-web-api

Authorize Attribute Not working in Web API 2.2 using OAuth2

好久不见. 提交于 2020-01-17 05:08:10
问题 I'm placing an [Authorize(Users = "user@sample.com")] attribute at the top of my Controller: [Authorize(Users = @"user@sample.com")] public class PostsController : ApiController { ... methods... } The user's usernames are the email address. When I sign in with user@sample.com I still get a 401 Unauthorized this controller's methods. I've also notice that, even after the user signs in both System.Web.HttpContext.Current.User.Identity.Name and System.Security.Claims.ClaimsPrincipal.Current

Authentication in webAPI

无人久伴 提交于 2020-01-17 04:51:47
问题 I want to set Individual authentication for the web API application i have created in Visual studio 2013 using Asp.net . please tell me how can i do that . VS 2013 by default provide several types of authentication while designing . i choose individual Authentication . But don't know how it works . 回答1: Create authentication token on server-side and store it in your database or even in cache. Then send this token with requests from your win forms application. WebApi should check this token

Xamarin.Forms.Portable : How to display data that comes from 2 different Entities?

≡放荡痞女 提交于 2020-01-17 04:44:29
问题 Good Day everyone. I'm currently creating a simple Xamarin.Forms Portable mobile application that allows me to input record of an Employee Name and Employee Department. I was able to retrieve the employee records created from the ASP.NET Web application Database, and display it on a ListView in the UWP part of my program. However, the data being retrieved is just coming from a single Entity namely 'Employee'. How will I display records that comes from 2 different Entities? I have tried it

How to resolve Dependency within Dependency

…衆ロ難τιáo~ 提交于 2020-01-17 04:11:10
问题 I have 4 Projects in a solution DAL_Project BLL_Project Interface_Project WebApi_Project Interface_Project has two interfaces ICar_DAL and ICar_BLL DAL_Project has a class Car_DAL that implements ICar_DAL BLL_Project has a class Car_BLL that implements ICar_BLL and its constructor takes in ICar_DAL WebApi_Project has an api controller CarApiController and its constructor takes in ICar_BLL the dependency resolution of WebApi Controller's constructor is done by Unity.WebApi using this in

How to handle Http Status code when making use of ReadAsStringAsync()

删除回忆录丶 提交于 2020-01-17 01:45:12
问题 I have a JavaScript client which makes Ajax call to a .net service (Lets call it First service). First service then makes call to another .net Controller (Call it Second Service). In this controller, I am throwing some exception. On the first line I am saying: //Code from Second Service [HttpPost] public HttpResponseMessage Results(ParamsModel data) { throw new Exception("Exception for testing purpose"); } //Code from First Service [HttpPost] public ActionResult Results(ParamsModel data) {

Return Task<T> as plain Task breaks WebAPI

限于喜欢 提交于 2020-01-16 20:06:15
问题 This is actually a different angel on this question Task with result unknown type Consider this code public interface IQueryHandler<in TQuery, TResult> where TQuery : Query<TResult> { Task<TResult> Handle(TQuery query); } Above interface is invoked like where Task<T> will be exposed as Task public Task Invoke(Query query) { var queryHandlerType = typeof(IQueryHandler<,>); var queryType = query.GetType(); var queryResultType = queryType.BaseType.GetGenericArguments().First(); var handler =

Return Task<T> as plain Task breaks WebAPI

爷,独闯天下 提交于 2020-01-16 20:06:05
问题 This is actually a different angel on this question Task with result unknown type Consider this code public interface IQueryHandler<in TQuery, TResult> where TQuery : Query<TResult> { Task<TResult> Handle(TQuery query); } Above interface is invoked like where Task<T> will be exposed as Task public Task Invoke(Query query) { var queryHandlerType = typeof(IQueryHandler<,>); var queryType = query.GetType(); var queryResultType = queryType.BaseType.GetGenericArguments().First(); var handler =

Calling WebApi from jQuery

心不动则不痛 提交于 2020-01-16 19:11:27
问题 Just started with WebApi and have multiple problems. Read tons of info, but probably missing some concepts. In my controller: public IEnumerable<Product> GetProducts() { return db.Products.AsEnumerable(); } public Product GetProduct(string name) { Product product = db.Products.FirstOrDefault(p => p.Name == name); if (product == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return product; } Javascript : $('#Search').click(function () { jQuery

How to know when a response has finished being sent to the client?

女生的网名这么多〃 提交于 2020-01-16 19:05:34
问题 I have a Web API web method which returns a list of Events in xml: public IList<Event> GetAllEvents() { ... } public class Event { public string Name { get; set; } public int Id { get; set; } } The client may send a GET request and receive 100 events which will be serialized so what happens is that: Request is received by GetAllEvents methods Data is provided by the method Web API engine serializes the object to xml Web API engine sends the serialized data (it might be e.g. 5MB) to the client

How to know when a response has finished being sent to the client?

我与影子孤独终老i 提交于 2020-01-16 19:05:14
问题 I have a Web API web method which returns a list of Events in xml: public IList<Event> GetAllEvents() { ... } public class Event { public string Name { get; set; } public int Id { get; set; } } The client may send a GET request and receive 100 events which will be serialized so what happens is that: Request is received by GetAllEvents methods Data is provided by the method Web API engine serializes the object to xml Web API engine sends the serialized data (it might be e.g. 5MB) to the client