asp.net-core-1.0

RequireHttpsAttribute with .NETCore RC2 causes HTTP302 redirect loop on Azure

亡梦爱人 提交于 2019-11-28 10:59:36
问题 I've been trying to get a .NETCore RC2 web app working on Azure with the RequireHttpsAttribute set but I'm having issues. To remove the possibility of this being a problem that I've introduced with my code, I cut things back to the bare minimum and recreated it using the "out of box" VS2015 .NETCore RC2 template. If I deploy the standard VS2015 .NETCore RC2 web app the site runs fine. If I then add [RequireHttps] to the controllers it works fine locally, but on Azure it causes an HTTP302

View scaffold templates in ASP.NET Core

巧了我就是萌 提交于 2019-11-28 10:37:39
MVC 5 has the very handy feature when creating a view to be able to select a template for scaffolding out the view. This uses a T4 template file to generate a CSHTML file based on a specified type. Is there a way to do anything like this in ASP.Net Core 1.0? You need to add references on Tools. But only for build time in project.json , add the following to the dependencies section: "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { "version": "1.0.0-preview2-final", "type": "build" }

Get user with assigned roles

拥有回忆 提交于 2019-11-28 07:58:42
问题 Using ASP.NET Core identity, I create a new user with UserManager.CreateAsync() and assign them to an existing role with UserManager.AddToRoleAsync . This works, as the realtion between user and role is stored in the AspNetUserRoles table of the database. But when I fetch the user using the UserManager (e.g. UserManager.FindByMail() method) then the Role list is empty. I also tried the Include function from EF like this: var user = userManager.Users.Include(u => u.Roles).FirstOrDefault(u => u

How to get bin folder in ASP.NET Core 1.0

我怕爱的太早我们不能终老 提交于 2019-11-28 06:53:25
With asp.net core 1.0 There are lots of functionality added. But there is not way to get Bin Folder path. Can anyone please know how we can get the bin folder path for asp.net core 1.0 application. Well, the bin folder does exists but it is moved to artifacts folder next to the solution file. Since ASP.NET Core RC 1 compiles everything in memory, you will find empty bin folder. But if you set "Produce output on build" option to true (Right click Project file -> Properties and Build tab) then you will find the generated files in bin folder. I don't think so there is any direct property

AntiXSS in ASP.Net Core

吃可爱长大的小学妹 提交于 2019-11-28 02:56:28
问题 Microsoft Web Protection Library (AntiXSS) has reached End of Life. The page states "In .NET 4.0 a version of AntiXSS was included in the framework and could be enabled via configuration. In ASP.NET v5 a white list based encoder will be the only encoder." I have a classic cross site scripting scenario: An ASP.Net Core solution where users can edit text using a WYSIWYG html-editor. The result is displayed for others to see. This means that if users inject a JavaScript into the data they submit

Equivalent for .HasOptional in Entity Framework Core 1 (EF7)

核能气质少年 提交于 2019-11-28 02:24:21
问题 Consider two classes. public class File { [Key] public string Id { get; set; } public string Message_Id { get; set; } internal Message Message { get; set; } } public class Message { [Key] public string Id { get; set; } } In EF6, for N : 1..0 relation there was this fluent API. modelBuilder.Entity<File>() .HasOptional(e => e.Message ).WithMany().HasForeignKey(e => e.Message_Id); What is equivalent in Entiity Framework Core 1? Thank you 回答1: You will not find an equivalent method in EF 7. By

Injecting IHttpContextAccessor into ApplicationDbContext ASP.NET Core 1.0

微笑、不失礼 提交于 2019-11-28 01:32:45
问题 I am trying to figure out how to get access to the current logged in username outside of an ASP.NET Controller. For example I am trying to do this: Track Created and Modified fields Automatically with Entity Framework Code First To setup tracking on entities in the DbContext . Here is my ApplicationDbContext but I keep getting an error saying _httpContextAccessor is null : private readonly IHttpContextAccessor _httpContextAccessor; public ApplicationDbContext(DbContextOptions

.NET Core and Angular 2 Work Flow

五迷三道 提交于 2019-11-28 01:32:34
I am wondering what the correct filing structure is for setting up a .NET Core 1.0.0 MVC application with Angular 2. I have browsed various tutorials and lectures but they all seem to have different ways of implementing angular 2 into .NET. Also, what are the best practices for implementing angular 2 into a .NET MVC app (a.k.a. when should I use angular SPA practices vs. using POST/GET with .NET) and how should I correctly setup the work flow? Thank you. I use asp.net in conjunction with Angular 2 all the time. I don't know if there yet exists a "correct" method to setting up a .NET Core 1.0.0

How do I import a .NET Core project to another .NET Core project in Visual Studio?

懵懂的女人 提交于 2019-11-28 00:43:26
问题 I need to use some classes from another project. How can I just import or create a reference to that project in Visual Studio? Right now if I use "Add reference" in Visual Studio, I get the error: ".NET Core projects only support referencing .NET framework assemblies in this release. <br/> To reference other assemblies they need to be included in a NuGet package" 回答1: .NET Core works with dependencies via NuGet. If your projects are in the same solution, then yes, you can add a reference

ASP.NET Core MVC controllers in separate assembly

冷暖自知 提交于 2019-11-27 21:51:34
I'm using ASP.NET MVC Core RC-2. I have a web project targeting the full .NET framework. I also have a separate class library in the solution, also targeting the full framework. In the class library, I have a controller, marked with a route attribute. I have referenced the class library from the web project. This assembly references the nuget package Microsoft.AspNetCore.Mvc v. 1.0.0-rc2-final . It was my understanding that this external controller would be discovered automatically, e.g. http://www.strathweb.com/2015/04/asp-net-mvc-6-discovers-controllers/ However this doesn't work for me- I