asp.net-core-1.0

AntiXSS in ASP.Net Core

时光总嘲笑我的痴心妄想 提交于 2019-11-29 09:31:22
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 when saving the text this code could execute when others visits the page. I want to be able to

Failed to make the following project runnable (Object reference not set to an instance of an object.)

家住魔仙堡 提交于 2019-11-29 09:31:05
When I create default web project in Visual Studio 2015 (Update 3) with installed .NET Core 1.0 SDK and Tooling (preview 2) and restart the Visual Studio after reverting local source control changes I am getting the following compilation error : Failed to make the following project runnable: MyDefaultWebProject (.NETCoreApp,Version=v1.0) reason: Object reference not set to an instance of an object. According to Visual Studio the error is located in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets on line 262 On this line there is the following

HttpContext.Authentication.SignOutAsync does not delete auth cookie

放肆的年华 提交于 2019-11-29 09:14:24
According to ASP.NET Core documentation the method HttpContext.Authentication.SignOutAsync() must delete the authentication cookie as well. Signing out To sign out the current user, and delete their cookie (italics mine - A.C.) call the following inside your controller await HttpContext.Authentication.SignOutAsync("MyCookieMiddlewareInstance"); But it does not! Everything else seems okay, esp. auth scheme, because user gets signed-in correctly and the cookie .AspNetCore. is created. Any ideas why cookie remains after the user's sing-out? You didn't post enough code to tell, but I suspect after

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

早过忘川 提交于 2019-11-29 09:02:59
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 octavioccl You will not find an equivalent method in EF 7. By convention, a property whose CLR type can contain null will be configured as optional. So what

Injecting IHttpContextAccessor into ApplicationDbContext ASP.NET Core 1.0

落花浮王杯 提交于 2019-11-29 07:55:35
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<ApplicationDbContext> options, IHttpContextAccessor httpContextAccessor) : base(options) { _httpContextAccessor =

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

一笑奈何 提交于 2019-11-29 07:08:29
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" .NET Core works with dependencies via NuGet . If your projects are in the same solution, then yes, you can add a reference using the Visual Studio UI ("Add reference" command). A background reference will be added as a NuGet package.

ASP.NET Core RC2 Seed Database

霸气de小男生 提交于 2019-11-29 06:18:45
My problem is i am trying to seed an Entity Framework Core database with data and in my mind the below code show work. I've realised that this should not be called in the ApplicationDbContext constructor and should be called from the startup but im not sure how to do this. EDIT: Based on the solution provided by Ketrex, my solution is as follows: Startup.cs: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ... app.ApplicationServices.GetRequiredService<ApplicationDbContext>().Seed(); } Seed extension: public static class

How to save IFormFile to disk?

做~自己de王妃 提交于 2019-11-29 05:59:03
问题 I'm trying to save a file on disk using this piece of code. IHostingEnvironment _hostingEnvironment; public ProfileController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } [HttpPost] public async Task<IActionResult> Upload(IList<IFormFile> files) { foreach (var file in files) { var fileName = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var filePath = _hostingEnvironment.WebRootPath + "\\wwwroot\\" + fileName;

Can not find runtime target for framework .NETCoreApp=v1 compatible with one of the target runtimes for some projects

五迷三道 提交于 2019-11-29 03:52:11
I have a solution with many .NET Core projects. I did NuGet updates to all of the project and now when I try to build I get the following errors (for some of the projects - not all): Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'. Possible causes: 1. The project has not been restored or restore failed - run `dotnet restore` 2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section. 3. You may be trying to publish a library, which is not

Right way to work with RSS in ASP.NET Core 1.0 RC2

孤街浪徒 提交于 2019-11-29 02:33:16
问题 What is the right/best way to get data from an RSS feed using ASP.Net Core 1.0 (RC2) in C#. I want to work with the data in the RSS feed from my Wordpress blog which is https://blogs.msdn.microsoft.com/martinkearn/feed/ I know that in ASP.net 4.x, you'd use RssReader or SyndicationFeed but I cannot find an equivalent for ASP.net core. This is as far as I have got which returns the raw feed but I do not know how to extract the data from it. I want to enumerate the items and get the title and