asp.net-core-mvc

Checking login user AuthorizePolicy in Razor page on Asp.Net Core

非 Y 不嫁゛ 提交于 2019-12-04 23:38:09
I'm looking for a variant of this @if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.Administrator)) { <div id="editArticle"> but instead of checking after the role I'm after a check into the policy much like you would in a controller by doing this. [Authorize(Policy = Policies.RequireAdmin)] James P This seems similar to question asked here I found this link which may be helpful: https://docs.asp.net/en/latest/security/authorization/views.html Examples from that page: @if (await AuthorizationService.AuthorizeAsync(User, "PolicyName")) { <p>This paragraph is displayed because you

Equivalent of “@section” in ASP.NET Core MVC?

牧云@^-^@ 提交于 2019-12-04 23:20:34
In the default _Layout.cshtml file, scripts are defined in "environment"s like so: <environment names="Development"> <script src="~/lib/jquery/dist/jquery.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> </environment> <environment names="Staging,Production"> <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js" asp-fallback-src="~/lib/jquery/dist/jquery.min.js" asp-fallback-test="window.jQuery"> </script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/bootstrap.min.js" asp

ASP.NET Core MVC View Components

别等时光非礼了梦想. 提交于 2019-12-04 23:07:49
In ASP.NET Core MVC (formerly MVC 6) there is a new area of functionality called View Components which appear to be a better alternative to Partial Views. I've seen the following View Component Example . But there doesn't seem much more information currently as to their usage. I'm trying to evaluate if its worth using this pattern and if this can/(or is intended) to be used as a more baked in method to help with donut caching . View components are definitively great and it's certainly an improvement. The one big improvement is that you can run asynchronous operations on view components where

NormalizedUserName VS Username in DotNet Core

家住魔仙堡 提交于 2019-12-04 22:47:45
I'm trying to create a custom implementation of IUserLoginStore for MongoDB and I noticed when using UserManager<ApplicationUser> with the method var userResult = await _userManager.CreateAsync(user); it goes through the implementation of GetUserNameAsync FindByNameAsync SetNormalizedUserNameAsync GetUserIdAsync I would like to clarify two questions: what's the purpose of having a NormalizedUsername and a UserName? the only difference that I could notice id that the normalizedUserName is in uppercase. I'm using my Implementation only to store users from an external login(Google plus), is there

“netcoreapp1.0” is an unsupported framework. - Asp.Net Core Music Store

倾然丶 夕夏残阳落幕 提交于 2019-12-04 22:34:57
问题 I'm just trying out asp.net core for the first time. Opening up the newly updated music store app but I can't get it to build Nuget tells me: Errors in C:\development\MusicStore\test\E2ETests\project.json "netcoreapp1.0" is an unsupported framework. How can I get the .net framework reference to restore? 回答1: RC2 was released yesterday, and now you can. You need: Install tooling for VS2015 from https://go.microsoft.com/fwlink/?LinkId=798481 (link from step 1) Upgrade NuGet (VS Extensions) - 3

Is there any replace of AssemblyBuilder.DefineDynamicAssembly in .NET Core?

旧街凉风 提交于 2019-12-04 22:14:09
How to port the following code to .Net Core: AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName( Guid.NewGuid().ToString()), AssemblyBuilderAccess.RunAndSave); Is it possible? add this to your project.json "dependencies": { "System.Reflection.Emit": "4.0.1" }, and use AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run); AssemblyBuilderAccess.RunAndSave is not supported at the moment link to souce . Update: For new .csproj projects use: <ItemGroup> <PackageReference Include="System.Reflection.Emit" Version="4.3.0" /> <

Format date within View in ASP.NET Core MVC

喜夏-厌秋 提交于 2019-12-04 21:39:21
问题 I have problem in regarding with converting the datetime to date using a model. Model from Class Library public partial class LoanContract { [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")] public DateTime LoanDateStart { get; set; } } Model from Project public class ModelLoan { public LoanContract loanContract { get; set; } } Code in controller myList.loanContract = new LoanContract { LoanDateStart = DateTime.Today }; View: <input disabled type="date" asp-for="loanContract.LoanDateStart"

Execute non-query procedure not working asp.net core

血红的双手。 提交于 2019-12-04 21:15:15
I want to execute a stored procedure which returns three values (Email, Name, CompanyID) and get one parameter (CompanyID) but it's not working. I have created a class with these properties and a stored procedure which returns the data. By it is showing DatabaseFacade error. My code is: List<MyClass> AppUser = new List<MyClass>(); //Class with three properties SqlParameter param1 = new SqlParameter("@CompanyID", CompanyID); AppUser = _context.Database.SqlQuery<CC>("GetUserAndRolesForCompany", param1).ToList(); Showing this error: I have include System.Linq 'DatabaseFacade' does not contain a

Using FluentScheduler - ASP.NET Core MVC

非 Y 不嫁゛ 提交于 2019-12-04 21:00:56
问题 I currently have a simple website setup with ASP.NET Core MVC (.NET 4.6.1), and I would like to periodically do some processes like automatically send emails at the end of every day to the registered members. After doing some searching, I came across two common solutions - Quartz.NET and FluentScheduler. Based on this SO thread, I found the approach of using FluentScheduler more easier to digest and use for my simple task. After quickly implementing the following lines of code into my Program

Implementing custom claim with extended MVC Core Identity user

痴心易碎 提交于 2019-12-04 20:38:51
问题 How can I create a custom authorize claim in MVC Core 2.0 (using AspNetCore.identity) to verify a custom user boolean property? I have extended the IdentityUser (ApplicationUser) to include a boolean value "IsDeveloper". I am using claims based authentication and would like to add a custom claim, but am not certain where to start. How can I create a custom claim that will: Find the current (customized) Core.Identity user. Evaluate the a custom identity user bool value? I understand the core