asp.net-web-api

how to enable cors options in asp.net web apis.?

我们两清 提交于 2020-12-06 15:42:04
问题 How do I enable the CORS option in asp.net WebApi? I installed the package Microsoft.AspNet.WebApi.Cors from nuget for CORS support. However, I am getting an error stating that IAppBuilder does not contain definition for app.useCors ? 回答1: Make sure you have installed the Microsoft.AspNet.WebApi.OwinSelfHost and Microsoft.Owin.Cors NuGet packages. 来源: https://stackoverflow.com/questions/41986332/how-to-enable-cors-options-in-asp-net-web-apis

how to enable cors options in asp.net web apis.?

笑着哭i 提交于 2020-12-06 15:38:22
问题 How do I enable the CORS option in asp.net WebApi? I installed the package Microsoft.AspNet.WebApi.Cors from nuget for CORS support. However, I am getting an error stating that IAppBuilder does not contain definition for app.useCors ? 回答1: Make sure you have installed the Microsoft.AspNet.WebApi.OwinSelfHost and Microsoft.Owin.Cors NuGet packages. 来源: https://stackoverflow.com/questions/41986332/how-to-enable-cors-options-in-asp-net-web-apis

How to fix No connection could be made because the target machine actively refused it 127.0.0.1:64527

坚强是说给别人听的谎言 提交于 2020-12-05 07:19:33
问题 I have an MVC application which depends on a web API application, I hosted the two on a shared hosting environment. API on the subdomain and MVC on the main domain the API is api.mydomain.com and the MVC is mydomain.com, the API works fine anytime I try it on postman or browser but the MVC cannot connect to it with the following error. No connection could be made because the target machine actively refused it 127.0.0.1:64527 Description: An unhandled exception occurred during the execution of

Is it best practice to test my Web API controllers directly or through an HTTP client?

陌路散爱 提交于 2020-11-30 09:48:33
问题 I'm adding some unit tests for my ASP.NET Core Web API, and I'm wondering whether to unit test the controllers directly or through an HTTP client. Directly would look roughly like this: [TestMethod] public async Task GetGroups_Succeeds() { var controller = new GroupsController( _groupsLoggerMock.Object, _uowRunnerMock.Object, _repoFactoryMock.Object ); var groups = await controller.GetGroups(); Assert.IsNotNull(groups); } ... whereas through an HTTP client would look roughly like this:

proper implementation of “windows” authentication in web api?

雨燕双飞 提交于 2020-11-30 06:38:11
问题 I've created a Web Api 2 app which will only be used on the corporate network. I've read about Windows authentication in Web API so it seems to be possible. But I need to figure out the proper implementation for this. I've included the following xml in my Web.config: <system.web> <authentication mode="Windows" /> </system.web> I seem to remember some type of event hook in old school webforms app. Something like BeginRequest() where a security check could be made before rendering a page. I

Error when trying to create a Controller in .NET CORE Web Application

南楼画角 提交于 2020-11-30 00:29:29
问题 I have a .NET CORE Web application created in Visual Studio 2017. It was created as a empty template. The startup.cs has the below code public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSingleton<IInventoryServices, InventoryServices>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvcWithDefaultRoute(); } The program.cs is like below: public class

Error when trying to create a Controller in .NET CORE Web Application

好久不见. 提交于 2020-11-30 00:26:32
问题 I have a .NET CORE Web application created in Visual Studio 2017. It was created as a empty template. The startup.cs has the below code public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSingleton<IInventoryServices, InventoryServices>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvcWithDefaultRoute(); } The program.cs is like below: public class

check user validation in Asp.net core with jwt authorization

我们两清 提交于 2020-11-29 03:38:52
问题 I implemented Microsoft Identity and JWT in my web api, a client can login and get a JWT token and store it in the application. since the expiration of the token the user can access the the server, but if I remove a user from my database, the removed user still has its token and can access the web api, how can I check the validation of the user? 回答1: One option is to validate the current user on the JwtBearerEvent OnTokenValidated event which will be triggered after every successful

check user validation in Asp.net core with jwt authorization

会有一股神秘感。 提交于 2020-11-29 03:38:06
问题 I implemented Microsoft Identity and JWT in my web api, a client can login and get a JWT token and store it in the application. since the expiration of the token the user can access the the server, but if I remove a user from my database, the removed user still has its token and can access the web api, how can I check the validation of the user? 回答1: One option is to validate the current user on the JwtBearerEvent OnTokenValidated event which will be triggered after every successful