Questions tagged [asp.net-web-api]

13699 questions
2

votes
1

answer
55

Views

Service fabric hosted Asp.net WebApi Container application : 403 - Forbidden : Access is denied. on local cluster

I'm trying to do a lift and shift of a Asp.net MVC application . I've containarized my Asp.Net WebApi application and deployed it AzureContainerRegistry and i'm referencing the container in a service fabric application. My ServiceManifest looks like this bookingacr.azurecr.io/bookingapi And the App...
Arshad Badar Khan
0

votes
1

answer
11

Views

IIS Rewrite based on query string value

I am new to IIS Rewrite, Need someone to assist me, I am in a scenario to redirect to another domain based on querystring value. Ex: Request: http://localhost:50743/api/Values?stdId=1000&stdName='Test' http://localhost:50752/api/Values?stdId=1001&stdName='Test1' http://localhost:50753/api/Values?std...
Vicky S
1

votes
0

answer
130

Views

ASP.NET Web API and IdentityServer issue with CORS

I had an MVC controller which was doing logout and it was working fine. We decided to migrate from MVC to Web API and translated all the code. Now, on logout action I'm getting response error like CORS request made for path: path-to-my-identity-server/login from origin: localhost:port but rejecte...
anatol
1

votes
0

answer
88

Views

SignalR setup when separating out data access layer

Current setup has a single webapi with controllers, services, SignalR Hubs/server, data entity models and view models (say Project.Main). The thought is to create a separate project (Project.Data - webapi) for Data entity model, view models and services. Project.Main would reference Project.Data to...
Shyamal Parikh
1

votes
1

answer
259

Views

What's the best way to implement roles in a multi-tenant .net project?

My application is .NET 4.7 Web Api with Entity Framework 6. This is for a software as a service tool I am building. In my application there is a many to many relationship between AspNetUser and Company. A user can have many companies, and a company can have many users. A user needs to have a diffe...
Suren
1

votes
0

answer
787

Views

How to use dependency injection in ActionFilter Web API?

I am trying to get work with dependency injection into the action filter, but it seems not working I've registered the type in UnityConfig public static void RegisterComponents(IUnityContainer container) { GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container)...
M005
1

votes
1

answer
507

Views

Combine ASP.NET MVC and Web API projects using identity

I am new to ASP.NET and I have to create an ASP.NET MVC project using the identity framework for authentication and authorization, but the access to the database (SQL Server) must be done in an independent web service project so I created a Web API project with also identity containing all services...
sam
1

votes
0

answer
129

Views

How to perform a LINQ join on IQueryable<T> in odata controller

I have a WebAPI method which uses the OData Query Options to return data to the client. The entity has cityid and I want cityname from another entity using joins. I have tried using below Api method, which is incomplete. Entity1:- public partial class UU_DeliveryCharges { public int DeliveryChargeId...
Sunil Chaudhary
1

votes
0

answer
328

Views

Excel download from Asp.Net Web API using Axios post method

I have an action which returns excel file. [HttpPost] public async Task Export([FromBody] QueryParameters qp) { var stream = _service.GetExcel(qp); var exportFileName = 'MyExcel'; return File(stream, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', exportFileName)...
Parashuram
1

votes
1

answer
37

Views

SignalR methods in WebApi controller not called in specific setup

Well, I have a signalR hub: public class ReportHub : Hub { private static IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext(); public void SendMessage(string text) { Clients.All.sendMessage(text); } public static void ServerSendMessage(string text) { hubContext.Clients.All.sendMess...
udovichenko
1

votes
0

answer
16

Views

WebAPI, no Post

WebAPI, I'm getting a HTTP 500 error. The alerts that I put in are firing correctly. But I put a breakpoint in the Post method in ProductsController.cs. It didn't stop at the breakpoint which seems to indicate that the routing wasn't right. My intention is to have the Post method add the new row to...
DRL
1

votes
1

answer
749

Views

How to return a file using byte [] with web Api?

I trying export file with web Api. this is my client code : exportLicense(licenseIds) { return this.$http({ method: 'POST', contentType: 'application/zip', url: this.application.resolveWebApiService('Licenses', 'ExportLicenses'), data: licenseIds }); } ExportLicenses method from my backend side(my...
eagle
1

votes
1

answer
169

Views

Interrupted downloads when downloading a file from Web Api (remote host closed error 0x800704CD)

I have read near 20 other posts about this particular error, but most seem to be issues with the code calling Response.Close or similar, which is not our case. I understand that this particular error means that typically a user browsed away from the web page or cancelled the request midway, but in o...
David Anderson
1

votes
0

answer
445

Views

Unable to capture Access token from Azure using this.adalService.acquireToken

I am using ng2-adal for Azure AD authentication. I have created 2 projects, one is Angular 2 and WebAPI. Using ng2-adal, I am able authenticate user and got the Web App access token, but to get access token of Web API, I am using below code public getToken(): any { debugger; return this.adalServic...
Raj4MS
1

votes
2

answer
3.5k

Views

Angular SignalR HubConnection gives 'Protocol error: Unknown transport.'

I have an Owin-selfhosted API running on http://localhost:8090/. I created a signalR hub with the following code: app.UseCors(CorsOptions.AllowAll); //Inside Startup.cs app.MapSignalR(); //Inside Startup.cs //Inside own class file public class SensorHub: Hub { public void Send(string message) { Cons...
G Versluis
1

votes
2

answer
124

Views

EF Code First - How to Deploy to Azure

I've been struggling with this all day. I can't make my WebApi to access my database. I'm using the Code First approach with Entity Framework. When I'm deploying, a new connection string is added to web.config. And this raises an exception: This is what I've got in my web.config (locally): And thi...
RottenCheese
1

votes
1

answer
128

Views

Restrict Asp.Net Web API numeric value bindings to base 10

In an Asp.Net Web API controller I have, there is a PostAsync method that bind the request JSON body to a model class. E.g.: public class EmployeesController : ApiController { ... public async Task PostAsync([FromBody] Employee employee) { ... } ... } The Employee model class contains a numeric prop...
Liroy Alima
1

votes
1

answer
233

Views

Structuremap - dependency injection - EF Core DBContext lifetime per request

Has anyone had any luck setting up an EF Core DBContext with Structuremap 'correctly' (what is correctly?) DBContext needs to be a singleton across the lifetime of the request. I understand that the default lifecycle is Transient. I understand that that will get a nested container, which effectively...
jenson-button-event
1

votes
0

answer
96

Views

Arduino POST long JSON data

I want to send dynamically sized (long) JSON data to a web API over an Ethernet module. Before sending the data, I have to send HTTP headers. My JSON data size is very big and I don't want to store this data in memory only to calculate the length of the data to send the Content-Length HTTP header. B...
Onur Tekir
1

votes
0

answer
195

Views

multipart/form-data ASP.NET Web API 2 - cannot bind data with BindModel (ViewModel) in action

I added this line to my WebApiConfig config.Formatters.XmlFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue('multipart/form-data')); (From my research I found that this is the only way to receive data and file at the same time, PS: Can I send JSON data and file data...
john
1

votes
1

answer
669

Views

How to upload image to server using web api?

I am at learning phase of web api and I want to upload image to server using web api in mvc dot net. I have tried much but not getting solution. In controller I have done this. string img = username + '_' + labTestId + fb; var element2 = image; MemoryStream ms = new MemoryStream(Convert.FromBase64St...
SoftwareStudent
1

votes
1

answer
213

Views

Security - pass password /secrets to Webapi

What is the best practice to pass sensitive information like password/secret from angular to Webapi? Should we need to hash/encrypt them at the client before sending to webapi? Having https:// protocol would be enough to pass the sensitive information over the wire without encrypting? Let me know yo...
Balaji
1

votes
0

answer
535

Views

FromQuery Nested Model Binding

How can we bind nested properties from query? Example model: public class X { public string PropA { get;set; } public string PropB { get;set: } public Y ClassY { get;set; } } public class Y { [FromQuery(Name = 'prop1')] public string Prop1 { get;set; } public string Prop2 { get;set; } } Class x gets...
user2963570
1

votes
0

answer
273

Views

Web API w/ SSL allows non-secure GET requests

The scenario: I have a .NET Core 2.0 Web API app configure to use only secure connections. I'm using Postman to test the requests. If I try to POST, PUT or DELETE using non-secure URL (HTTP), it returns status 403 (as it should be). However, it accepts GET requests via HTTP. I'm really an amateur re...
thiagoprzy
1

votes
1

answer
279

Views

How to configure web api's json serializer to convert date time into ISO 8601 format?

I am working on web api project and inside my WebApiConfig class I have added this configuration to convert datetime parameters into ISO 8601 format: IsoDateTimeConverter converter = new IsoDateTimeConverter { //DateTimeStyles = DateTimeStyles.AdjustToUniversal, DateTimeFormat = 'yyyy'-'MM'-'dd'T'HH...
Simple Code
1

votes
1

answer
70

Views

how to validate list in web api

I am writing a web api which accepts list of customers in from file upload. Each row in file represents single customers. There can be 'n' customers in a single file. For each row, validation check is required. The error messages needs to be displayed in respective row. POST /api/customers List if...
Vijay Balkawade
1

votes
0

answer
140

Views

Work with DI in Asp .NET Core Web API

During the controller design I had the following question: For example I have Controller that inject via constructor few services that work for more endpoints in that controller, further I want to add new functionality and add new endpoint to that controller as the result I need to add new Service i...
3axap
1

votes
0

answer
626

Views

Owin Context returns null

This is my DbContext class: public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base('name=ApplicationDbContext') { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new ShopConfiguration()); base.OnModelCreat...
RottenCheese
1

votes
1

answer
27

Views

How to use attribute routing in for get method with same parameter in web api 2

following is code for calling web API call public async System.Threading.Tasks.Task RequisitionNameByQuantityThisDraw() { //Guid applicationRequisitionOid string userName = string.Empty; SessionObject sessionData = new SessionObject().GetSessionData(); if (sessionData == null) { return RedirectToAct...
1

votes
0

answer
805

Views

Asp.Net Web Api Request logging in action filter

i need user request logging in action filter. I had some refactoring to our companys web api project.It has custom authentication and authorization,i dont want to change this part. Before the refactoring,every method find the requested user with header value. [CustomAuthorization] public class Conte...
engcmreng
1

votes
0

answer
27

Views

Calling itunes web api to fetch the data

I am very much new to the web API concept. I want to populate a div in my web page with the logo images of all the games of particular developer in itunes using the itunes web API. Can anyone please help me out. Thanks in advance.
1

votes
0

answer
223

Views

Streaming large Files using Web Api

I got a little question: I would like to stream an large array from my web API to my client. But I got a System.OutOfMemory Exception or an AggregateException. My Api looks like this: public List Get() { return GetLittlePonys();} And my Client looks like: public string GetRequest(string URL) { usin...
Homer Tw
1

votes
1

answer
95

Views

'System.Data.Entity.Database' does not contain a definition for 'ExecuteStoredProcedure'

I am using Entity Framework extras EF6 in Visual Studio 2013 for calling a stored procedure that takes table valued parameter. But on this line of code: context.Database.ExecuteStoredProcedure(procedure); I get this error: 'System.Data.Entity.Database' does not contain a definition for 'ExecuteStor...
Seema A
1

votes
1

answer
964

Views

SyntaxError: Illegal return statement in Angular application

I'm getting SyntaxError: Illegal return statement while running beow code in last line of code(return statement). And after executing last line, I'm getting TypeError: Cannot read property 'post' of undefined error. constructor(private _http:Http); createCategory(vm: Category): Observable{ vm.Id =...
Shailesh Bhat
1

votes
0

answer
74

Views

Route attribute with wildcard on the left

I want to be able to automatically match routes that may or may not have a prefix on the left of the incoming request's route. For example, for this controller [MyRoutePrefix('api/hello-world')] public class MyController { [Route('')] public IHttpActionResult Get(){ return OK(); } } I'd like the fol...
lanierhall
1

votes
1

answer
37

Views

How to retrieve stored proc data without the word “table” in the return value using c# web api

I'm trying to pull some database rows to be consumed through an api using the code below: DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection('data source=.; database=GiveTradeApp; integrated security=true;')) { SqlCommand cmd = new SqlCommand('sp_get_products_by_user', con); c...
Mr.Google
1

votes
1

answer
51

Views

Writing a WebAPI that scales to large volume conurrency scenario

I know it is a broad topic, but I am looking for the 101 here. What considerations should I put in mind while writing a simple web api service with a database involved, in order for it to scale up in the future handling high volume of concurrent users with no problems?
Sisyphus
1

votes
1

answer
267

Views

ExceptionFilterAttribute in Azure Functions

I'm trying to migrate a WebAPI application to Azure Functions. I have searched on the net and haven't found anything equivalent to ExceptionFilterAttribute supported in Azure Functions. Does this mean that to migrate this feature, we should wrap the code of every function in try catch blocks and the...
stormtrooper
1

votes
1

answer
374

Views

How to access Model object in ActionFilterAttribute.OnResultExecuted?

I am working with a WEB API application in ASP .NET Core 2.0 where I have a custom filter attribute that inherits from ActionFilterAttribute. How can I access the Model object passed to a controller action in POST call, in ActionFilterAttribute.OnResultExecuted() The mentioned method is passed a Res...
Farooq Hanif
1

votes
0

answer
140

Views

Handle Azure web app timeout error to send ApplicationInsights traces

We have a webapi wep app deployed in Azure. We receive a POST request that takes longer that 230 seconds to finish. Azure is then killing the request and sending a 500 error response. My problem is that all Application Insights telemetry and error traces for that POST request are lost when the requ...
Diana

View additional questions