asp.net-core-mvc

How to access dbcontext & session in Custom Policy-Based Authorization

非 Y 不嫁゛ 提交于 2020-03-18 05:15:28
问题 Is it possible that we can access dbcontext to get my table data and session in custom Policy-Based Authorization? Anyone can help how to achieve it? services.AddAuthorization(options => { options.AddPolicy("CheckAuthorize", policy => policy.Requirements.Add(new CheckAuthorize())); }); services.AddSingleton<IAuthorizationHandler, CheckAuthorize>(); public class CheckAuthorize : AuthorizationHandler<CheckAuthorize>, IAuthorizationRequirement { protected override Task HandleRequirementAsync

asp.net Core mvc hide and exclude Web Api Controller Method

三世轮回 提交于 2020-03-17 09:16:19
问题 I know there is the ApiExplorerSettings attribute [ApiExplorerSettings(IgnoreApi = true)] public async Task<IActionResult> MyMethod(int id) But that does not stop a client of the api to call the endpoint method. I need to know if there is an attribute that disables the endpoint and does not allow requests. I want to avoid doing it by modifying the routing mechanism. 回答1: The simplest MVC approach might be to use the NonAction attribute, like so: [ApiExplorerSettings(IgnoreApi = true)]

ASP.NET Core disable Windows Authentication

孤人 提交于 2020-03-05 10:30:37
问题 I have .NET Core MVC web application where during creation I set Windows authentication. Now I want to disable Windows authentication and enable anonymous authentication (I have my own authentication mechanism). Here is what I have set in my config file .vs\config\applicationhost.config <security> <authentication> <anonymousAuthentication enabled="true" /> <windowsAuthentication enabled="false" /> </authentication> </security> My problem is that when I reopen the solution and run it, the

ASP.NET Core disable Windows Authentication

China☆狼群 提交于 2020-03-05 10:30:10
问题 I have .NET Core MVC web application where during creation I set Windows authentication. Now I want to disable Windows authentication and enable anonymous authentication (I have my own authentication mechanism). Here is what I have set in my config file .vs\config\applicationhost.config <security> <authentication> <anonymousAuthentication enabled="true" /> <windowsAuthentication enabled="false" /> </authentication> </security> My problem is that when I reopen the solution and run it, the

How to use views in Entity Framework?

☆樱花仙子☆ 提交于 2020-03-04 20:14:51
问题 How can I use database views in Entity Framework? I have the following view in the SQL database called pl SELECT dbo.Product.Productkey, dbo.Product.Productcode, dbo.Product.Productname, dbo.rcode.code, dbo.rcode.label FROM dbo.Product INNER JOIN dbo.rcode ON dbo.Product.programtypekey = dbo.rcode.rcodekey How can I read from the above view in application using EF? Currently I am readinmg from a table as shown below. I want to ready from view instead. In my context, I have public virtual

How to use views in Entity Framework?

柔情痞子 提交于 2020-03-04 20:14:32
问题 How can I use database views in Entity Framework? I have the following view in the SQL database called pl SELECT dbo.Product.Productkey, dbo.Product.Productcode, dbo.Product.Productname, dbo.rcode.code, dbo.rcode.label FROM dbo.Product INNER JOIN dbo.rcode ON dbo.Product.programtypekey = dbo.rcode.rcodekey How can I read from the above view in application using EF? Currently I am readinmg from a table as shown below. I want to ready from view instead. In my context, I have public virtual

Can't get razor page route to work using anchor tag helper

三世轮回 提交于 2020-03-04 18:48:38
问题 Background This is a follow on issue to an initial question I asked around asp.net core v3.1 razor page routes. I added the following to the startup as suggested in the solution here which allowed me to route to the razor page in both ways I wanted: services.AddMvc() .AddRazorPagesOptions(options => options.Conventions.AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signup") ); /identity/account/signup /identity/account/signupandapply/<fooapplyid> Issue I'm

Problem running project after Identity scaffolding in ASP.NET Core MVC project on Linux

穿精又带淫゛_ 提交于 2020-02-28 07:50:25
问题 I've tried adding <PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="2.2.0" /> However 2.2.0 is the latest version available at this time, which doesn't match the error. The error is still the same after rebuilding the app. project.csproj: <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <RuntimeIdentifier>linux-x64</RuntimeIdentifier> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore

Problem running project after Identity scaffolding in ASP.NET Core MVC project on Linux

蓝咒 提交于 2020-02-28 07:48:30
问题 I've tried adding <PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="2.2.0" /> However 2.2.0 is the latest version available at this time, which doesn't match the error. The error is still the same after rebuilding the app. project.csproj: <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <RuntimeIdentifier>linux-x64</RuntimeIdentifier> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore

Using nameof() with Url.Action() and async methods in ASP.NET Core 3.x MVC

给你一囗甜甜゛ 提交于 2020-02-25 01:52:07
问题 Let's say I have a ASP.NET Core 3.0 MVC application, which features a simple controller containing two actions and using attribute based routing: [Route("home")] public class HomeController : Controller { public static string ControllerName { get; } = "Home"; public HomeController() { } string GenerateUrls() { string url1 = Url.Action(nameof(Action1), ControllerName); string url2 = Url.Action(nameof(Action2Async), ControllerName); return $"Action1: '{url1}'\nAction2: '{url2}'"; } [HttpGet("a1