asp.net-web-api2

CORS: credentials mode is 'include'

孤者浪人 提交于 2019-11-27 17:23:08
Yes, I know what you are thinking - yet another CORS question, but this time I'm stumped. So to start off, the actual error message: XMLHttpRequest cannot load http://localhost/Foo.API/token . The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include' . Origin ' http://localhost:5000 ' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. I'm not sure what is meant by credentials mode is 'include' ? So when I

Return more info to the client using OAuth Bearer Tokens Generation and Owin in WebApi

孤者浪人 提交于 2019-11-27 17:01:15
I have created a WebApi and a Cordova application. I am using HTTP requests to communicate between the Cordova application and the WebAPI. In the WebAPI, I've implemented OAuth Bearer Token Generation. public void ConfigureOAuth(IAppBuilder app) { var oAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), Provider = new SimpleAuthorizationServerProvider(new UserService(new Repository<User>(new RabbitApiObjectContext()), new EncryptionService())) }; // Token Generation

Include property but exclude one of that property's properties

别说谁变了你拦得住时间么 提交于 2019-11-27 16:35:49
问题 Let's say I have a method like this in one of my controllers: [Route("api/Products")] public IQueryable<Product> GetProducts() { return db.Products .Include(p => p.Category); } Using this I can get a product from the database and include its Category property. In my CategoryControllerI have this method: [Route("api/Categories")] public IQueryable<Category> GetCategories() { return db.Categories .Include(c => c.Parent) .Include(c => c.Products) .Include(c => c.SubCategories); } When I send a

Newtonsoft Json serialize a class where one of the properties is JSON [duplicate]

别来无恙 提交于 2019-11-27 16:18:17
This question already has an answer here: Serialize object to JSON that already contains one JSON property 2 answers I'm using Newtonsoft Json serialization (with Web API 2). One of the public properties on my class is a String that holds JSON data. I'd like to serialize my class, and include this public property, but I don't want the serializer to process/modify the contents of this string. Is there any way I can include this property, but not mess with its contents? You could make a JsonConverter to write the raw value of the string property to the output without changing it. You take

Using Simple Injector in Web API and OWIN

心不动则不痛 提交于 2019-11-27 16:09:34
问题 I'm experiencing the same problem as described here and my set up is almost identical to this that is actually based on this guide. When I access a method in my controller I get this An error occurred when trying to create a controller of type 'TestController'. Make sure that the controller has a parameterless public constructor. Here's the stack trace at System.Web.Http.Dispatcher.DefaultHttpControllerActivator .Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor

ASP.NET Web API Authorization tokens expiring early

旧时模样 提交于 2019-11-27 14:26:42
I have implemented security for my web api (individual accounts) as discussed here . I have hosted the website on godaddy (shared hosting) and its working fine. When I ask for token by using url "domain.com/token", I get the token with expiration date of within 15 days. I have set this in "StartupAuth.cs" using AccessTokenExpireTimeSpan = TimeSpan.FromDays(15) e.g.: { "access_token":"qwertyuiop.....", "token_type":"bearer", "expires_in":1209599, "userName":"user@example.com", ".issued":"Wed, 11 Feb 2015 01:00:00 GMT", ".expires":"Thu, 26 Feb 2015 01:00:00 GMT" } (I put values in above code,

How do I get StructureMap working with an AngularJs / MVC5 and WebApi2 web project

南楼画角 提交于 2019-11-27 14:19:22
问题 So I have an AngularJs/MVC project with normal Controllers and decided to move more to an SPA app and add WebApi2 to pass data back to my UI instead of using MVC. In my Global.asax I had the following for my MVC project: DependencyResolver.SetResolver(new StructureMapDependencyResolver(container)); My WebApiController has a constructor with an IRepository to talk to the database and get some entities back. When my AngularJS web app makes a call to the controller the break points never hit and

Dependency injection not working with Owin self-hosted Web Api 2 and Autofac

半世苍凉 提交于 2019-11-27 13:35:06
问题 I'm finding my feet with Web Api 2, Owin and Autofac and need some guidance, please. Overview I have an Owin self-hosted Web Api that uses Autofac for IoC and dependency injection. The project is a console app acting like a service, meaning it can be stopped and started. I have an Authentication controller with two constructors: one parameter-less and the other injects a repository. Problem When I run the service and call the api, my parameter-less constructor is called and my repository

OData V4 modify $filter on server side

给你一囗甜甜゛ 提交于 2019-11-27 13:17:00
I would like to be able to modify the filter inside the controller and then return the data based on the altered filter. So for I have an ODataQueryOptions parameter on the server side that I can use to look at the FilterQueryOption. Let's assume the filter is something like this "$filter=ID eq -1" but on the server side if I see "-1" for an ID this tells me that the user wants to select all records. I tried to change the "$filter=ID eq -1" to "$filter=ID ne -1" which would give me all by setting the Filter.RawValue but this is read only. I tried to create a new FilterQueryOption but this

Web API 2, OWIN Authentication, SignOut doesn't logout

旧巷老猫 提交于 2019-11-27 12:22:00
I'm doing some research for work with a view to using Bearer tokens as an authentication mechanism (i.e. AngularJS UI, authenticates via OWIN in a Web API [2] project). I have the login working fine, role information and all that is fine, but I cannot get the token to logout. My startup configuration is this: OAuthOptions = new OAuthAuthorizationServerOptions() { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId), AccessTokenExpireTimeSpan = SESSION_TIMEOUT, AllowInsecureHttp = true }; And my logout action is simply this: public