asp.net-core-mvc

Analog System.Security.Permissions in .NET Core

早过忘川 提交于 2019-12-11 05:21:01
问题 I am trying to port project to .NET Core, but can't find analog System.Security.Permissions. Project uses construction like that [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")] or [EnvironmentPermission(SecurityAction.LinkDemand, Unrestricted = true)] , '' 回答1: Code Access Security isn't and won't be available in .Net Core. Since all code is effectively running under full trust, it should be enough to remove those attributes. If you actually want to restrict some code,

MVC tracking fields such as Author and Editor (Created By and Modified By)

送分小仙女□ 提交于 2019-12-11 05:07:09
问题 I'm looking for the best way to track the Author and Editor fields for all the entities in my database. I started by creating a base model which all my models inherit from: public class DatabaseEntity { [Key] public int Id { get; set; } [Display(Name = "Last Modified By")] public ApplicationUser Editor { get; set; } [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] [Display(Name = "Last Modified")] public DateTime LastModified { get; set; } [Display(Name =

Using OnAuthorizationCodeReceived to retrieve Azure GraphAPI AccessToken

∥☆過路亽.° 提交于 2019-12-11 04:46:52
问题 I am currently using code in my pipeline to cache the bearer token for the Graph API using Azure AD. This code was ported from a working ASP.NET 4 application, but it feels like the new OpenIdConnectOptions in Core should make this easier. Is there a more direct call that I can use in the OnAuthorizationCodeReceived event that will use the AuthenticationContext to cache the token once the code is received? Here is my current code: var azureSettings = app.ApplicationServices.GetService

Context.Response.SignOut no longer exists after ASP.NET vNext beta 6 upgrade

余生颓废 提交于 2019-12-11 04:18:43
问题 In my AccountController under beta4 of ASP.NET vNext, we were logging out by using: Context.Response.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationScheme); Context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationType); This worked great and the user ended up on the login page of Office 365 as we expected. After updating to beta6, the SignOut method was shown as an error. We replaced it with the below, but the logout never seems to correctly happen. The user is

Building REST APIs using ASP.NET Core with Razor syntax

别等时光非礼了梦想. 提交于 2019-12-11 04:18:06
问题 As I was exploring the articles and contents on the internet about building REST APIs using asp.net core, I found out that razor web pages are not commonly used for front-end. Most of them are focused on Angular 1 && 2 for dealing with api data coming from the server (Ex: $http.get, $http.post). I was just wondering if there is any article that introduces how to use pure razor web pages as a front-end for dealing with web api or is there any ways to do it properly using .net core? For ex:

Authorize attribute does not redirect to Login page when using .NET Core 2's AddJwtBearer

五迷三道 提交于 2019-12-11 04:14:55
问题 I can't make any samples to work when using the new AddJwtBearer. I have a HomeController attributed with Authorize: [Authorize] public class HomeController : Controller { public IActionResult Index() { return View(); } } I was trying out the new ASP.NET Core AddJwtBearer and I have this code in ConfigureServices just before services.AddMvc(): services.AddAuthentication(opts => { opts.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; opts.DefaultChallengeScheme =

EF Core Entity Circular Reference

天涯浪子 提交于 2019-12-11 04:06:26
问题 I am using C#.net and ef core. I have the models below. When I get my list of competitions, I want to only get my related user. However, I am getting the User and all the User's competitions. How can I achieve this? I had to do the following to get my list of competitions to show: .AddJsonOptions(opt => opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore) public partial class Competition { public int CompetitionId { get; set; } public int UserId { get;

Is is possible to make SEO friendly Url's in ASP.NET Core like this one

有些话、适合烂在心里 提交于 2019-12-11 03:54:36
问题 I wanted to ask you guys if is it possible, to make some routing like this for my project /{action}/{title} ? I was wondering if that is possible, does this url has to be a primary key too? Since there is no ID passed to know which blog post is this. Thank you. 回答1: You can do this quite easily with attribute routing: [Route("blogs")] public class BlogController { [AcceptVerbs("GET", "HEAD", Route = "{slug}")] public IActionResult View(string slug) { } } This maps all requests to /blogs

Class library lost intellisense in VS2017 after .NET Core MVC auto-migration

社会主义新天地 提交于 2019-12-11 03:24:11
问题 After migrating a VS2015 MVC Core application with two projects (web app and class library) to VS2017 I've lost intellisense on all views within the class library. Pretty much everything in every single view is broken, so I'm sure it's something fairly basic that the migration tool didn't take care of for me. Even the @model directive in each razor view is an error. The csproj looks like this: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework>

Not hitting error page on ASP.NET 5 app

时光毁灭记忆、已成空白 提交于 2019-12-11 02:30:04
问题 I'm playing with a new ASP.NET 5 MVC 6 app. So far, it's an empty, out-of-the-box application Visual Studio creates when ASP.NET 5 MVC project is selected. In the Home controller action, I added the line to see if I'd get redirected to the generic error page i.e. ~/Views/Shared/Error.cshtml throw new UnauthorizedAccessException("Test exception!"); When I run the project, all I get is an exception in my code but don't get redirected to the error page. The following is the standard Startup.cs -