asp.net-core-2.0

ASP.Net / ASP.NET Core Web API unauthorized requests returns 302 redirect response instead of 401

限于喜欢 提交于 2019-12-09 05:54:32
问题 In ASP.Net / ASP.Net Core WebAPI, When the client/browser tries to access a WebAPI endpoint which is decorated with [Authorized] attribute. It gets a 302-Found status code with a redirect response to the Login page, instead of 401-Unauthorized for an unauthorized request. Note: I have noticed that Fail(AuthorizationContext context) method in AuthorizeAttribute filter sets the response code as 401-Unauthorized , but eventually browser gets a 302-Found response. How can I send the 401 response

How to Add an implementation of 'IDesignTimeDbContextFactory<DataContext>' to the project in asp.net-core-2.0

让人想犯罪 __ 提交于 2019-12-09 05:14:09
问题 Here are the list of packages which I have installed : Installed Packages I am using Entityframework core 2.0. First time I have successfully created database using entity framework code first migration(add-migration and update-database command). Now when I update my entities and try to run migration it's giving me following error. Unable to create an object of type 'DataContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/

ASP.NET Core 2.0 Redirecting user from AuthorizationHandler, HandleRequirementAsync method

Deadly 提交于 2019-12-09 03:43:00
问题 I am trying to implement AuthorizationHandler in .net core 2.0 where i need to authorize the user and based on the condition wanted to redirect to different action methods within my application validation works ok but how i can redirect user to the Access Denied or Login page when authorization failed. protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasPermissionRequirement requirement) { var controllerContext = context.Resource as

ASP.NET Core MVC Dependency Injection via property or setter method

只谈情不闲聊 提交于 2019-12-08 19:51:40
问题 It has been well documented, how to inject dependencies into services. Question: But is it (already) possible in ASP.NET Core 2.0 to have the system's DI mechanism automatically inject a service into a method or into a property? Sidenote: In PHP-Symfony this pattern is called setter injection. Example: Say I have a common MyBaseController class for all controllers in my project and I want a service (e.g. the UserManager service) to be injected into MyBaseController that can be later accessed

How to change starting page, using Razor Pages in .NET Core 2?

假装没事ソ 提交于 2019-12-08 17:30:28
问题 I wanted to set my starting page to /Members/Index. When I was using MVC, I configured it as following: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Members}/{action=Index}/{id?}"); }); But now I'm trying new Razor Pages approach, and now Members is folder and Index is Razor Page. How to set this page in folder as starting one? I can add Index page in root directory and make redirect there, but I was looking for something cleaner. 回答1: For testing purposes

Automapper Profiles not being loaded in Startup?

Deadly 提交于 2019-12-08 17:13:42
问题 I'm using: AutoMapper 6.1.1 AutoMapper.Extensions.Microsoft.DependencyInjection 3.0.1 It seems my profiles are not being loaded, every time I call the mapper.map I get AutoMapper.AutoMapperMappingException: 'Missing type map configuration or unsupported mapping.' Here my Startup.cs class ConfigureServices method // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //register

Why do I get a 404 trying to post a large file to a Core Web API

廉价感情. 提交于 2019-12-08 15:14:59
问题 I am very new to file transfer between HttpClient and a Web API, so please excuse any ignorance and guesswork in my code. I have been trying to post a file created with System.IO.Compression.ZipFile to my web API now for about a day, and always I get a 404 response. If I post with an empty stream, the API action method is invoked, so I know the 404 is due to content and not the URI. This method is in the client WPF application that attempts to post the file: public async Task PostDirAsync

Could not load file or assembly System.Data.SqlClient, Version=4.2.0.2 when I use System.Data.SqlClient Version 4.4.3

会有一股神秘感。 提交于 2019-12-08 14:56:17
问题 I use System.Data.SqlClient Version 4.4.3 for all .NET Standard 2.0 class libraries in my ASP.NET Core 2.0 project. Why do I get Could not load file or assembly 'System.Data.SqlClient, Version=4.2.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) when the project is published with VSTS to Azure App Service? And of course it perfectly works on my machine! All this worked

Bind variable number of tags with asp-for

泄露秘密 提交于 2019-12-08 12:46:15
问题 I have a view where an user can trigger an action that will insert input tags in the page: The 'Add more' button is tied to a jquery click event. HTML: <div id="details"> <label>More details</label> <input placeholder="Foo" asp-for=""> <input placeholder="Bar" asp-for=""> </div> <button id="add-details" type="button">Add more</button> JS: $("#add-details").click(function(){ $("#details").append(`<input placeholder="Foo" asp-for=""> <input placeholder="Bar" asp-for="">`) }); Now, I want to

I get a Not found error when I deploy ASP.NET CORE 2.0 WebApi to IIS under Default Website

余生颓废 提交于 2019-12-08 09:27:17
问题 It works well with the label "2" outside of default website but it does run inside the default website 回答1: Try the following... Install the hosting bundle again, and then publish from Visual Studio again. If that doesn’t fix it, go to the publish output folder and run dotnet run <YourWebDll>.DLL 回答2: I assume you already install either SDK or Runtime in web server. Then, you need to install ASP.NET Core Module in web server. Here is the download link. Trouble Shooting If it still doesn't