asp.net-core-webapi

Routing is not working with self-hosted web API [duplicate]

冷暖自知 提交于 2019-11-26 20:58:11
问题 This question already has an answer here : WebApi giving 404 whilst debugging; works when published (1 answer) Closed 4 months ago . This is essentially what I have, a very simple set of three files with fresh asp.net core 2.1 (actually copy-pasted from tutorials): public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup

How to return a specific status code and no contents from Controller?

夙愿已清 提交于 2019-11-26 18:52:29
问题 I want the example controller below to return a status code 418 with no contents. Setting the status code is easy enough but then it seems like there is something that needs to be done to signal the end of the request. In MVC prior to ASP.NET Core or in WebForms that might be a call to Response.End() but how does it work in ASP.NET Core where Response.End does not exist? public class ExampleController : Controller { [HttpGet][Route("/example/main")] public IActionResult Main() { this

How to stop self-referencing loop in .Net Core Web API?

三世轮回 提交于 2019-11-26 17:11:32
问题 I'm having some issues which I'm guessing are related to self-referencing using .NET Core Web API and Entity Framework Core. My Web API starting choking when I added .Includes for some navigation properties. I found what appears to be a solution in the older Web API but I don't know how to implement the same thing for .NET Core Web API (I'm still in the early learning stages). The older solution was sticking this in the Application_Start() of the Global.asax: GlobalConfiguration.Configuration

Still logged in MVC site, but can't call web API

♀尐吖头ヾ 提交于 2019-11-26 16:57:30
问题 I have an ASP.NET MVC site, IdentityServer4 host and a web API. When I log in the MVC site, using external provider (Facebook), I'm logged in fine. From the MVC site I can also consume the web API correctly. However, the next day, I'm still logged in into the MVC site, but when I then try to access the web API, I get a 'not authorized exception'. So although I'm still logged in in the MVC site, I'm not authenticated anymore to call a web API from within the MVC site. I'm wondering how to

Creating a proxy to another web api with Asp.net core

北城以北 提交于 2019-11-26 15:32:09
问题 I'm developing an ASP.Net Core web application where I need to create a kind of "authentication proxy" to another (external) web service. What I mean by authentication proxy is that I will receive requests through a specific path of my web app and will have to check the headers of those requests for an authentication token that I'll have issued earlier, and then redirect all the requests with the same request string / content to an external web API which my app will authenticate with through

Return file in ASP.Net Core Web API

萝らか妹 提交于 2019-11-26 11:46:05
Problem I want to return a file in my ASP.Net Web API Controller, but all my approaches return the HttpResponseMessage as JSON. Code so far public async Task<HttpResponseMessage> DownloadAsync(string id) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent({{__insert_stream_here__}}); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return response; } When I call this endpoint in my browser, the Web API returns the HttpResponseMessage as JSON with the HTTP Content Header set to application/json . If this

RS256 vs HS256: What&#39;s the difference?

浪子不回头ぞ 提交于 2019-11-26 07:51:02
问题 I\'m using Auth0 to handle authentication in my web app. I\'m using ASP.NET Core v1.0.0 and Angular 2 rc5 and I don\'t know much about authentication/security in general. In the Auth0 docs for ASP.NET Core Web Api, there are two choices for the JWT algorithm being RS256 and HS256. This may be a dumb question but: What\'s the difference between RS256 and HS256? What are some use cases (if applicable)? 回答1: Both choices refer to what algorithm the identity provider uses to sign the JWT. Signing

ASP.NET Core return JSON with status code

醉酒当歌 提交于 2019-11-26 06:12:11
问题 I\'m looking for the correct way to return JSON with a HTTP status code in my .NET Core Web API controller. I use to use it like this: public IHttpActionResult GetResourceData() { return this.Content(HttpStatusCode.OK, new { response = \"Hello\"}); } This was in a 4.6 MVC application but now with .NET Core I don\'t seem to have this IHttpActionResult I have ActionResult and using like this: public ActionResult IsAuthenticated() { return Ok(Json(\"123\")); } But the response from the server is

Return file in ASP.Net Core Web API

三世轮回 提交于 2019-11-26 01:59:03
问题 Problem I want to return a file in my ASP.Net Web API Controller, but all my approaches return the HttpResponseMessage as JSON. Code so far public async Task<HttpResponseMessage> DownloadAsync(string id) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent({{__insert_stream_here__}}); response.Content.Headers.ContentType = new MediaTypeHeaderValue(\"application/octet-stream\"); return response; } When I call this endpoint in my browser, the Web API