asp.net-web-api

Owin Authentication In MVC and Web Api

谁都会走 提交于 2020-01-23 02:05:28
问题 I'm trying to use the same authentication between the MVC controllers and the Web Api controllers. The Web api is in the same project, just in an /Controllers/API/ folder. I can't seem to figure out how to authenticate using OWIN, when I logged in through MVC and created a claim and a cookie like the example below. var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name,"Admin"), new Claim(ClaimTypes.Role,"Administrator") , "ApplicationCookie"); var ctx = Request.GetOwinContext();

Owin Authentication In MVC and Web Api

血红的双手。 提交于 2020-01-23 02:05:27
问题 I'm trying to use the same authentication between the MVC controllers and the Web Api controllers. The Web api is in the same project, just in an /Controllers/API/ folder. I can't seem to figure out how to authenticate using OWIN, when I logged in through MVC and created a claim and a cookie like the example below. var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name,"Admin"), new Claim(ClaimTypes.Role,"Administrator") , "ApplicationCookie"); var ctx = Request.GetOwinContext();

Handle Oracle Database Connection in Dapper

会有一股神秘感。 提交于 2020-01-23 01:49:07
问题 I am trying to connect to the Oracle Database and trying to execute a query. So below is my Model Class using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; namespace TestAPI.Models { public class TestAPIModel { [Key] public int PRIO_CATEGORY_ID { get; set; } public int LANG_ID { get; set; } public System.DateTime REC_DATE { get; set; } public int REC_USER { get;

Run node.js & WebAPI on same server for same site with IIS

£可爱£侵袭症+ 提交于 2020-01-23 01:11:06
问题 I'm looking to slowly convert a Node.js application over to ASP.NET WebAPI 2.0 . I'm currently using IIS and will stick with IIS . So, I would like to host them on the same server but direct some URIs over to the new platform. How would I do this in the web.config ? The current web.config for node.js looks like so: <configuration> <system.webServer> <handlers> <!-- indicates that the app.js file is a node.js application to be handled by the iisnode module --> <add name="iisnode" path="beta

Web api authentication and MVC 4

≡放荡痞女 提交于 2020-01-22 23:09:08
问题 I have the following solution: Web api project. MVC 4 project. I need to authenticate user by sending its credentials using a JSON request (https is a must). is it a good approach ? and how can i authenticate the user on both web api and MVC . 回答1: is it a good approach ? Yeah, why not. and how can i authenticate the user on both web api and MVC . If the Web API requires authentication you could use the same Forms Authentication as the MVC application. So you could configure Forms

Web api authentication and MVC 4

被刻印的时光 ゝ 提交于 2020-01-22 23:09:05
问题 I have the following solution: Web api project. MVC 4 project. I need to authenticate user by sending its credentials using a JSON request (https is a must). is it a good approach ? and how can i authenticate the user on both web api and MVC . 回答1: is it a good approach ? Yeah, why not. and how can i authenticate the user on both web api and MVC . If the Web API requires authentication you could use the same Forms Authentication as the MVC application. So you could configure Forms

Treat empty query string parameters as empty strings, without using a class for parameters

白昼怎懂夜的黑 提交于 2020-01-22 20:00:33
问题 I am trying to pass multiple parameters to a httpget web api function. The key problem I am having is that empty query string parameters are being converted to null. I can solve this by creating a class like something below: public class CuttingParams { [DisplayFormat(ConvertEmptyStringToNull = false)] public string batch_number { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string filter { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string

How do I map an OData query against a DTO to an EF entity?

纵然是瞬间 提交于 2020-01-22 19:02:05
问题 I have an ODataController in an Asp.Net Web Api application that allows OData queries. I'm only allowing reads, not updates. Instead of exposing the data model directly, I've created a set of DTOs. The property names on the DTOs do not necessarily match the properties on the EF model. This causes a problem when I try to use the OData query against the EF model. I've looked at other posts on StackOverflow around this subject but none of them seemed to resolve this issue. Here is what I have

Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'

大城市里の小女人 提交于 2020-01-22 17:30:12
问题 I am testing my Web API. Mocking the data I have this: var objs = ((JArray)JsonConvert.DeserializeObject("{ \"PrintId\":10,\"Header\":\"header\",\"TC\":\"tc\",\"CompanyRef\":\"00000000-0000-0000-0000-000000000000\"}")).Values<JObject>(); Which gives me the error: Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray' The thing is it was working. I must have changed something, but I don't know what. My intent is to convert this JSON object to a list

Cleanest way to start a WebAPI project in Visual Studio (NO VIEWS)

馋奶兔 提交于 2020-01-22 17:10:25
问题 What's the cleanest way to remove all extras that normally come with Visual Studio API Template, things like Views and other stuff that are not needed if you just want to have a WebAPI service?? I'm assuming that the folder VIEWS is for MVC Views ...maybe I'm wrong and it's all needed to have a running APIs. 回答1: Launch Visual Studio go to File -> New Project -> ASP.NET MVC 4 Web Application . Click OK then select "Empty" instead of "Web API" That will not have any extras such as Views. 回答2: