asp.net-web-api2

ASP.NET allow anonymous access to OData $metadata when site has global AuthorizeAttribute

眉间皱痕 提交于 2019-12-11 10:05:47
问题 I have an ASP.NET OData site that has the following in the WebApiConfig file: config.Filters.Add(new AuthorizeAttribute()) This forces all callers to authenticate before calling any of the controllers. Unfortunately, this also forces user authentication to access the "$metadata" url. I need to globally force authentication for all controller access while also allowing anonymous access the the "$metadata" url. 回答1: Create a custom filter that derives from AuthorizeAttribute and override the

InvalidCastException when using Entity Framework

我怕爱的太早我们不能终老 提交于 2019-12-11 10:03:45
问题 I am trying to save a List of Users in a Conversation class but I am getting an InvalidCastException when performing a POST. This is my User class: public class User { [Key] [DataMember] public String Email { get; set; } [DataMember] public String Password { get; set; } [DataMember] public Boolean Admin { get; set; } public User(String email, String password, Boolean admin) { Email = email; Password = password; Admin = admin; } } And this is my Conversation class: [DataContract] public class

Role based tokens ASP.net Identity

早过忘川 提交于 2019-12-11 09:57:16
问题 I am using the standard ASP.net OWIN OAuth middleware system to authenticate local users with Bearer tokens. What I would like to do is is hand out role-based tokens for the same user account. eg. OAuth TokenA => General User Privileges UserA -> OAuth TokenB => Admin User Privileges Is this supported in any way? 回答1: I was able to solve this using the following method - //ensure the token is a User role token only identity.AddClaim(new Claim(ClaimTypes.Role, "User")); Where 'identity' is an

Preventing Cross-Site Request Forgery Attacks With a Windows Client Application

徘徊边缘 提交于 2019-12-11 09:55:45
问题 I develop an web application by web api2 . My client application is a windows application that developed by C# , .net 4.0. The client application sends some Json data to the web api application and the application stores data in database. Now the issue is sending the request with another method except my application and sending dump data to the server.I have authentication on the server but it isn't enough,I need some tokens for handling this issue. After some searches i find this article and

Fallback controller route in ASP.NET Web API v2

早过忘川 提交于 2019-12-11 09:47:03
问题 I'm building an offline web app that uses the path string for client-side URLs. There are several (attribute-based) routes that map to dedicated controllers for resources, API calls, etc.. For example: /myapp/api/... /myapp/resources/... I then want all requests that do not match one of these patterns to be routed to my bootstrap HTML page, which I currently serve via a dedicated controller. So, for example, the following requests need to end up at the bootstrap HTML page: /myapp/customers/..

How to add migration in .NET Core Library project in web API core 1.1

≯℡__Kan透↙ 提交于 2019-12-11 08:48:54
问题 I am new in .net core. I am adding migration in .net core Liabrary project in web API core 1.1. using below code. Add-Migration example1 But it's showing below error: 回答1: If you are using VS Code or other editor: In dotnet command cli type: dotnet ef migrations add InitialCreate obs:InitialCreate is the name of migration, you can give any name. If you are using Visual Studio: Create your database Once you have a model, you can use migrations to create a database. Open the PMC: Tools –> NuGet

Entity Framework working with SQL Server views for ASP. NET web api

a 夏天 提交于 2019-12-11 08:48:14
问题 I am researching my first RESTful API project to interact with the automation side of our ERP system. I am planning a SPA like here The simple web page is to provide users with a list of purchase requisitions they must approve or decline. The app will retrieve the data from a SQL Server view into a collection. As the user approves or declines the requisition this is recorded in the object and when the User presses 'Update ERP' the app will build a XML list of the collection and using a SQL

Upgraded to WebAPI2 and DotNetNuke 7.2.1 and all services returning 404.0

非 Y 不嫁゛ 提交于 2019-12-11 08:22:20
问题 I wrote some WebAPI controllers using WebAPI for DotNetNuke 7.0 using this method Everything worked great. Today I upgraded DNN to 7.2.1 and upgraded my projects to ASP.NET Web API2 and my services on my local machine are now not working - they return "HTTP Error 404.0 - Not Found". I think it is something to do with IIS and extensionless URLs - I checked IIS and DesktopModules is not an application as suggested here. I tried Fiddler and F12 Debugging tools and the message is giving no clues

Configuring Route to allow dot as extension?

不想你离开。 提交于 2019-12-11 07:28:55
问题 Imagine the following: client app, which no one has control over, calls Web API methods but each of these methods ends in extensions such as : /api/{controller}/{method}.ab How is it possible to configure the ASP.NET web API, for a specific controller, to allow extensions for the method being called but also allow the existing default controllers to continue working? For instance if we have a method call GetCustomer , the client app will call GetCustomer.ab but want that call to be routed to

How to lock a long async call in a WebApi action?

 ̄綄美尐妖づ 提交于 2019-12-11 06:08:13
问题 I have this scenario where I have a WebApi and an endpoint that when triggered does a lot of work (around 2-5min). It is a POST endpoint with side effects and I would like to limit the execution so that if 2 requests are sent to this endpoint (should not happen, but better safe than sorry), one of them will have to wait in order to avoid race conditions. I first tried to use a simple static lock inside the controller like this: lock (_lockObj) { var results = await _service