asp.net-web-api

How can I limit the serving of a javascript file to only authenticated users?

為{幸葍}努か 提交于 2020-01-29 04:56:06
问题 I have a WebAPI 2 / AngularJS SPA application that uses Identity 2 for authentication. Locally my code stores a token for authentication. I would like to implement functionality that allows my application to request additional javascript for authenticated users after my initial index.html page has been downloaded. Is there a way I can make my server code give out the javascript files to only authenticated and authorized users? Something similar to the way a controller action method returns

Make sure that the controller has a parameterless public constructor error

北战南征 提交于 2020-01-26 07:57:10
问题 I have followed this tutorial which has worked great, until I modified my DbContext to have an additional constructor. I am now having issues with the resolution and not sure what to do to fix this. Is there an easy way to force it to grab the parameterless constructor or I am approaching this incorrectly? DbContext with two constructors: public class DashboardDbContext : DbContext { public DashboardDbContext() : base("DefaultConnection") { } public DashboardDbContext(DbConnection

Make sure that the controller has a parameterless public constructor error

ⅰ亾dé卋堺 提交于 2020-01-26 07:56:13
问题 I have followed this tutorial which has worked great, until I modified my DbContext to have an additional constructor. I am now having issues with the resolution and not sure what to do to fix this. Is there an easy way to force it to grab the parameterless constructor or I am approaching this incorrectly? DbContext with two constructors: public class DashboardDbContext : DbContext { public DashboardDbContext() : base("DefaultConnection") { } public DashboardDbContext(DbConnection

Make sure that the controller has a parameterless public constructor error

旧城冷巷雨未停 提交于 2020-01-26 07:56:05
问题 I have followed this tutorial which has worked great, until I modified my DbContext to have an additional constructor. I am now having issues with the resolution and not sure what to do to fix this. Is there an easy way to force it to grab the parameterless constructor or I am approaching this incorrectly? DbContext with two constructors: public class DashboardDbContext : DbContext { public DashboardDbContext() : base("DefaultConnection") { } public DashboardDbContext(DbConnection

How to pass/verify Open ID token between .net core web app and web api?

霸气de小男生 提交于 2020-01-26 03:57:08
问题 We have the following architecture: .NET core 3.1 web application using razor pages, jQuery, etc as the UI (not an angular application) .NET core 3.1 web api application serving as our api layer Okta as our identity provider I have implemented the Okta widget and middleware in the web application. Users can login, and after that happens I’m able to get a ClaimsPrincipal, access all of their scopes, and get to any custom profile data I’ve stored via open id. I'm able to secure views through

asp.net mvc web api help page not populating for given route

柔情痞子 提交于 2020-01-26 01:41:37
问题 I am having difficulties having the help page populate for a web api controller. The only method in the controller is the following: public HttpResponseMessage Get(string p1,string p2= "blend", string p3 = "blend") The method appears reflected in the help page with the signature: GET api/mycontroller?p1={p1}&p2={p2}&p3={p3} However none of my comments flow to the help page. For other simple controller Get(string id) the help page works ok. I tried adding the following on the WebApiConfig.cs

Doesn't ASP.NET Web Api Model Binding Use Newtonsoft (JSON.NET)

本小妞迷上赌 提交于 2020-01-26 00:59:46
问题 As far as I understand, Web Api uses Newtonsoft (JSON.NET) serializer/deserializer when model binding. But when I use [JsonProperty(Required = Required.AllowNull)] attribute for a model property, it does not work. I omit the property in JSON but model binder does not throw exception or make the ModelState.IsValid false. My questions are: Why does it not work if Web Api is using Json.Net? Is there a simple solution like a configuration change? If I have to use a custom model binder in order to

Dependency injection not working in web api call

笑着哭i 提交于 2020-01-25 21:42:12
问题 Hi I am trying to build angular 2 web application using WebAPI, Entityframework that is loosely coupled using dependency injection. I am using unity for dependency injection. I have created multiple projects in one solution to address the separation concerns. I have configured the dependency in unity.config however when i execute the webapi application and type the following url http://localhost:8702/api/allcustomers , I get message saying the customer controller doesn't have parameter-less

Hiding menu element by permission using AngularJS and Web API

别等时光非礼了梦想. 提交于 2020-01-25 20:08:09
问题 I have implemented roles based authorization in my Web API RESTfull service using OWIN. What would be the best way to hide menu items or buttons based on the role that the user has? I want to hide the items that the user has no access to. UPDATED I want to know what the best practice is for my controller. This is an example of what I want, but I don't think it is the right way to do it. Second, the routing fails because it cannot distinguish between the two actions. [Authorize(Roles =

Protecting webapi with IdentityServer and Autofac - can't get claims

蹲街弑〆低调 提交于 2020-01-25 16:34:22
问题 I'm trying to protect my webapi with IdentityServer and OpenID Connect using Autofac. I'm using OWIN. But for some reason I can't get claims of the user. It seems that AccessTokenValidation is not triggered at all. That makes me think there is something wrong in the order of my declarations at my startup. Here is my startup. public class Startup { public void Configuration(IAppBuilder appBuilder) { // Add authentication this.AddAuthentication(appBuilder); HttpConfiguration config = new