asp.net-web-api2

MVC 5, Identity 2.0 Android Rest/Json Api

人盡茶涼 提交于 2019-12-03 19:29:45
I have an ASP.NET MVC 5 Application which uses Identity 2.0 for authentication/authorisation. Now I want to provide access to the data in my web application to my Android Application via Web Api 2.0. My question is: How to control authorize/authenticate the access of my android application? On Android side I use "org.springframework.web.client.RestTemplate" and add this HTTP header to my request: HttpAuthentication authHeader = new HttpBasicAuthentication("username", "password"); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); HttpEntity<?>

Want to understand async

左心房为你撑大大i 提交于 2019-12-03 17:35:08
问题 I've used async coding a little bit but I don't really fully understand how to use it -- though I understand the concept and why I need it. Here's my set up: I have a Web API that I will call from my ASP.NET MVC app and my Web API will call DocumentDB. In code samples, I see a lot of await keywords while sending queries to DocumentDB. I'm confused if I need to make my Index action method in my MVC app async? I'm also confused if my CreateEmployee() method in my Web API should be async? What

MVC Routes within WebAPI controller

百般思念 提交于 2019-12-03 15:59:39
Quick question regarding routes within MVC and WebAPI. I have added a route to route config.cs: routes.MapRoute( name: "ConfirmEmail", url: "ConfirmEmail/{userid}", defaults: new { controller = "Email", action = "ConfirmEmail" } ); This is registered in the global.asax as per normal: RouteConfig.RegisterRoutes(RouteTable.Routes); I am trying to generate a URL for use within an email which is sent as part of a function call within a WebAPI controller function. I am using the UrlHelper.Link function to attempt to generate a URL, however I receive an error saying the route cannot be found by name

How to remove schema node in web api if return format is xml?

断了今生、忘了曾经 提交于 2019-12-03 15:50:36
I have a web api method that takes format as a parameter that provides returning both xml and json.The data type that method return is DataTable.In json format everything looks fine but in xml format the schema of datatable and some other attributes in xml nodes also returning.How to return simple xml that includes only data of datatable?Also, I am using QueryStringMapping in WebApiConfig. This is WebApiConfig Code public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/

Always receiving 'invalid_client' error when POSTing to /Token endpoint with ASP Identity 2

扶醉桌前 提交于 2019-12-03 15:12:09
问题 About a month ago I had a project working perfectly with ASP Identity OAuth. I'd send a POST request to the /Token endpoint with grant_type, username, and password, and all was dandy. I recently started a new project based off of Visual Studio 2013 RC2's SPA template. It's a bit different than the old template. Authentication is set up to pretty basic defaults, OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), //AuthorizeEndpointPath = new

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

旧巷老猫 提交于 2019-12-03 15:08:53
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 (still trying to understand how to do this by the way). It does not even add it to my bearer token

Relation to users when these are stored in an external Identity provider service

时光总嘲笑我的痴心妄想 提交于 2019-12-03 14:58:56
I'm trying to create an API and a website client for it. Lately I've been reading a lot about OAuth2 as a security mechanism and companies that offers authentication as a service such as auth0.com or even Azure active Directory and I can see the advantages in using them Because I'm used to always having the users in the same database and tables with relationships to the Users table in the form of One to Many such as below public class User { public string subjectId { get; set; } public virtual List<Invoice> Invoices { get; set; } /* More properties in here */ } public class Invoice { public

Why Authentication type - individual user accounts for Web API in .NET Core is not available when we creating new Web APi service

这一生的挚爱 提交于 2019-12-03 14:41:18
问题 Why it`s not possible to create Web API project with Individual User Accounts Authorization type? 回答1: UPDATE: All version numbers are updated from v1.2 to v2.0. Please find the ASP.NET Core Schedule and Roadmap: Identity Application Services A service layer will be added ASP.NET Core Identity and included in the project templates using Individual Authentication. This will allow authentication of users by way of JWT tokens such that Web APIs can be secured out of the box, and make it simpler

The route template separator character '/' cannot appear consecutively - Attribute routing issue

只谈情不闲聊 提交于 2019-12-03 14:25:29
问题 The configuration has nothing to do with the error This is my configuration for the Web API in App_Start/WebApiConfig.cs: public static void Register(HttpConfiguration config) { // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );..... And this is my global.asax class: GlobalConfiguration.Configure(WebApiConfig.Register); This is the error But whenever the

Multiple controllers with same URL routes but different HTTP methods

旧街凉风 提交于 2019-12-03 14:11:58
I've got a following two controllers: [RoutePrefix("/some-resources") class CreationController : ApiController { [HttpPost, Route] public ... CreateResource(CreateData input) { // ... } } [RoutePrefix("/some-resources") class DisplayController : ApiController { [HttpGet, Route] public ... ListAllResources() { // ... } [HttpGet, Route("{publicKey:guid}"] public ... ShowSingleResource(Guid publicKey) { // ... } } All three actions got in fact three different routes: GET /some-resources POST /some-resources GET /some-resources/aaaaa-bbb-ccc-dddd If I put them into single controller everything