asp.net-core-webapi

.Net Core web api not working after deployed to Azure

梦想与她 提交于 2019-12-07 14:24:55
问题 I do have a simple .Net Core web api application, the one made by Visual Studio when a new project is created. I want to deploy it to an Azure App Service via FTP (part of a TFS 2017 build job), which is successful: However, when trying a GET like http://somerandomname.azurewebsites.net/api/values all I get is a 404 with the text The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. From Kudu I get the following error: What am I missing? 回答1:

Sustainsys SAML2 Sample for ASP.NET Core WebAPI without Identity

最后都变了- 提交于 2019-12-07 11:55:20
问题 Does anyone have a working sample for Sustainsys Saml2 library for ASP.NET Core WebAPI only project (no Mvc) and what's more important without ASP Identity? The sample provided on github strongly relies on MVC and SignInManager which I do not need nor want to use. I added Saml2 authentication and at first it worked fine with my IdP (I also checked the StubIdP provided by Sustainsys) for first few steps so: IdP metadata get properly loaded My API properly redirects to sign-in page Sign-in page

Custom DateTime model binder in ASP.NET Core 1 (RTM)

流过昼夜 提交于 2019-12-07 11:30:00
问题 I'm writing and ASP.NET Core 1 application, which has a Web API Controller where supplier will post data. This is a simplified version of the Model class to which I will bind the incoming data: public class Lead { public int SupplierId { get; set; } public DateTime Date { get; set; } } The problem is that the dates will be posted with German formatting, for instance, 30.09.2016 . I do not want to set the global culture of the application to de-DE because a) I'm not German, and b) the rest of

Angular 7 to dotnetcore 2.1 web api call gives no response

爷,独闯天下 提交于 2019-12-07 09:01:27
问题 below is the code from login.component.ts, login() { const val = this.form.value; if (val.email && val.password) { this.authService.login(val.email, val.password) .subscribe( data => { if (data && data.Token) { // store user details and jwt token in local storage to keep user logged in //between page refreshes localStorage.setItem('currentUser', JSON.stringify(data)); console.log("user logged in"); this.router.navigate([this.returnUrl]); } else { console.log("user not logged in"); } }, error

How to generate unit test cases in VS 2017 .net core project?

梦想与她 提交于 2019-12-07 08:58:55
问题 "Create Unit Tests" context menu option is missing in Visual Studio 2017 for .Net core project? I read some articles saying that "Create Unit Tests" context menu option is removed in VS2017/Core/x64 config. But those were old articles. So, wanted to check if this option is available now? If not, do we have any other alternatives (extensions) to generate the test cases? If so, kindly let me know the steps. I am working on VS 2017/.NetCore 2.0 project. Appreciate your help! 回答1: Perhaps you've

Pass multiple parameters in a POST API without using a DTO class in .Net Core MVC

孤街醉人 提交于 2019-12-07 06:42:50
问题 I have an action on my web project which calls to an API [HttpPost] public async Task<IActionResult> ExpireSurvey(int id) { var token = await HttpContext.GetTokenAsync("access_token"); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); var path = "/api/forms/ExpireSurvey"; var url = Domain + path; var data = JsonConvert.SerializeObject(id); HttpContent httpContent = new StringContent(data

Asp.net core 2.0 middleware - accessing config settings

让人想犯罪 __ 提交于 2019-12-07 06:34:57
问题 In a asp.net core web api middleware, is it possible to access the configuration inside the middleware? Can someone guide me how this is done? 回答1: In a middle-ware you can access settings. To achieve this, you need to get IOptions<AppSettings> in the middle-ware constructor. See following sample. public static class HelloWorldMiddlewareExtensions { public static IApplicationBuilder UseHelloWorld( this IApplicationBuilder builder) { return builder.UseMiddleware<HelloWorldMiddleware>(); } }

ASP.NET Core ways to handle custom response/output format in Web API

别来无恙 提交于 2019-12-07 06:22:39
问题 I'd like to create custom JSON format, that would wrap the response in data and would return Content-Type like vnd.myapi+json Currently I have created like a wrapper classes that I return in my controllers but it would be nicer if that could be handled under the hood: public class ApiResult<TValue> { [JsonProperty("data")] public TValue Value { get; set; } [JsonExtensionData] public Dictionary<string, object> Metadata { get; } = new Dictionary<string, object>(); public ApiResult(TValue value)

How to do simple header authorization in .net core 2.0?

橙三吉。 提交于 2019-12-07 06:04:33
问题 I have been unable to find information on this particular issue after the 2.0 changes to .NET Core. I have cookie authorization like this: services.AddAuthentication("ExampleCookieAuthenticationScheme") .AddCookie("ExampleCookieAuthenticationScheme", options => { options.AccessDeniedPath = "/Account/Forbidden/"; options.LoginPath = "/Account/Login/"; }); For another part (of my controllers I would like to simply authorize based on a simple header. In the examples I've found, either I am

Route controller and action in middleware

孤者浪人 提交于 2019-12-07 04:15:41
问题 I am trying to retrieve the controller and action, I have tried to this point by using var routeData = context.GetRouteData(); inside the middleware's Invoke method, but it yields null every time. Is it possible at all to retrieve route data in middleware? What I am trying to achieve is to check whether the requested action has a [RequireToken] attribute, and if so, it will check the incoming headers for a specific token. 回答1: The action/controller context is very specific to the MVC portion