asp.net-web-api2

What does exactly is the Microsoft.Owin.Cors middleware when used with ASP.NET Web Api 2.0?

大憨熊 提交于 2019-12-21 04:39:24
问题 I have an ASP.NET Web Api 2.0 project with token authentication and everything done mainly following this article: Token Based Authentication using ASP.NET Web API 2, Owin, and Identity, Bit Of Technology But I am struggling to understand what exactly this line of code in my Startup.cs does: app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); This does not make the Web Api add the Access-Control-Allow-Origin header to my API responses, in other words it does not enable Cors in my Web Api

How to correctly unit test OData v6.0 controller?

耗尽温柔 提交于 2019-12-21 04:28:18
问题 I'm attempting to unit test out OData controllers, however the APIs changed and previously recommended methods I tried do not work - currently I'm getting No non-OData HTTP route registered. when trying to instantiate ODataQueryOptions to be passed into the Get method of the controller My current code (based on answers like this one): [TestMethod()] public void RankingTest() { var serviceMock = new Mock<IVendorService>(); serviceMock.SetReturnsDefault<IEnumerable<Vendor>>(new List<Vendor>() {

OWIN token authentication 400 Bad Request on OPTIONS from browser

爷,独闯天下 提交于 2019-12-20 18:42:37
问题 I am using token authentication for small project based on this article: http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/ Everything seems to work fine except one thing: OWIN based token authentication doesn't allow OPTIONS request on /token endpoint. Web API returns 400 Bad Request and whole browser app stops sending POST request to obtain token. I have all CORS enabled in application as in sample project. Below some code that

WEB API JSON Serializing Circular References

早过忘川 提交于 2019-12-20 18:36:30
问题 I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr

WEB API JSON Serializing Circular References

时光总嘲笑我的痴心妄想 提交于 2019-12-20 18:36:22
问题 I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr

WEB API JSON Serializing Circular References

和自甴很熟 提交于 2019-12-20 18:36:00
问题 I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr

How to get Access Token from ASP.Net Web API 2 via AngularJS $http?

青春壹個敷衍的年華 提交于 2019-12-20 10:39:17
问题 I try like this: $http({ method: 'POST', url: '/token', data: { username: $scope.username, password: $scope.password, grant_type: 'password' } }).success(function (data, status, headers, config) { $scope.output = data; }).error(function (data, status, headers, config) { $scope.output = data; }); then tried changing the grant_type to a param: $http({ method: 'POST', url: '/token', data: { username: $scope.username, password: $scope.password }, params: { grant_type: 'password' } }).success

ASP.net Identity, IoC and sharing DbContext

让人想犯罪 __ 提交于 2019-12-20 10:27:57
问题 Have anyone been successful in attaching an IoC with OWIN ASP.NET Identity to share the same DbContext as the WebApi (or MVC) application? I would like that if ASP.Net identity loads the user, it loads in the same dbcontext as used in the rest of the application. (using AutoFac as IoC - but wouldn't mind an example with other container) Edit : 06/Jan/2014: Just to be a bit more specific, when the ASP.Net identity attempts to use a DbContext it needs to be the same DbContext instance as the

Web Api 2 Session

大兔子大兔子 提交于 2019-12-20 09:55:36
问题 I cannot get session data from while in web api 2. I have verified that the cookie is sending in fiddler. I know that web api 2 best practice is to be stateless, but due to requirements on a project it is now necessary to be state-full. I have tried this link. WebAPI 2 attribute routing enable session state var session = SessionStateUtility.GetHttpSessionStateFromContext(HttpContext.Current) With the above solution I am getting a null exception on that function. I also tried replicating the

405 Method Not Allowed on WebAPI2 (OWIN)

﹥>﹥吖頭↗ 提交于 2019-12-20 09:48:43
问题 I am setting up a WebAPI endpoint for my API, but am having trouble getting my AngularJS calls to my PostRegister method to work. The webAPI and Angular are on separate sites. On the Startup.cs I have: public void Configuration(IAppBuilder app) { ConfigureOAuth(app); var config = new HttpConfiguration(); WebApiConfig.Register(config); app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); app.UseWebApi(config); } private void ConfigureOAuth(IAppBuilder app) { var oAuthServerOptions = new