{"id":36921,"date":"2018-03-04T11:21:40","date_gmt":"2018-03-04T19:21:40","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=12165"},"modified":"2018-03-04T11:21:40","modified_gmt":"2018-03-04T19:21:40","slug":"asp-net-core-2-1-0-preview1-gdpr-enhancements","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/asp-net-core-2-1-0-preview1-gdpr-enhancements\/","title":{"rendered":"ASP.NET Core 2.1.0-preview1: GDPR enhancements"},"content":{"rendered":"<p>2018 sees the introduction of the General Data Protection Regulation, an EU framework to allow EU citizens to control, correct and delete their data, no matter where in the word it is held. In ASP.NET Core 2.1 Preview 1 we\u2019ve added some features to the ASP.NET Core templates to allow you to meet some of your GDPR obligations, as well as a cookie \u201cconsent\u201d features to allow you to annotate your cookies and control whether they are sent to the user based on their consent to have such cookies delivered.<\/p>\n<h2>HTTPS<\/h2>\n<p>In order to help keep users&#8217; personal data private, ASP.NET Core configures new projects to be served over HTTPS by default. You can read more about this feature in<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/webdev\/2018\/02\/27\/asp-net-core-2-1-https-improvements\/\">Improvements to using HTTPS<\/a>.<\/p>\n<h2>Cookie Consent<\/h2>\n<p>When you create an ASP.NET Core application targeting version 2.1 and run it you will see a new banner on your home page, <figure id=\"attachment_12175\" aria-labelledby=\"figcaption_attachment_12175\" class=\"wp-caption alignnone\" ><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/snip_20180227142630-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/03\/snip_20180227142630-1-300x20.png\" alt=\"Cookie Consent Bar\" width=\"300\" height=\"20\" class=\"size-medium wp-image-12175\" \/><\/a><figcaption id=\"figcaption_attachment_12175\" class=\"wp-caption-text\">Cookie Consent Bar<\/figcaption><\/figure><\/p>\n<p>This is the consent feature in action. This feature allows you to prompt a user to consent to your application creating \u201cnon-essential\u201d cookies. Your application should have a privacy policy and an explanation of what the user is consenting to that conforms to your GDPR requirements. By default, clicking \u201cLearn more\u201d will navigate the user to \/Privacy where you could publish the details about your app.<\/p>\n<p>The banner itself is contained in the <code>_CookieConsentPartial.cshtml<\/code> shared view. If you open this file you can see some code showing how the user\u2019s consent value is retrieved and how it can be updated. The current consent status is exposed as an <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/fundamentals\/request-features\">HttpFeature<\/a>, <code>ITrackingConsentFeature<\/code>. If a user consents to allowing the use of cookies a new cookie will be created by calling <code>CreateConsentCookie()<\/code> on the feature. The status of the user\u2019s consent can be examined by the <code>CanTrack<\/code> property on the feature, however you don\u2019t need to do this manually, instead you can use the <code>IsEssential<\/code> property on cookie options. For example <code>context.Response.Cookies.Append(\"Test\", \"Value\", new CookieOptions { IsEssential = false });<\/code> would append a non-essential cookie to the response. If a user has not indicated their consent this cookie will not be appended to the response but will be silently dropped. Conversely marking a cookie as essential, <code>context.Response.Cookies.Append(\"Test\", \"Value\", new CookieOptions { IsEssential = true });<\/code> will always create the cookie in the response, no matter the user\u2019s consent status. You can provide feedback on the cookie consent tracking feature at <a href=\"https:\/\/github.com\/aspnet\/Security\/issues\">https:\/\/github.com\/aspnet\/Security\/issues<\/a>.<\/p>\n<h2>Data Control<\/h2>\n<p>The GDPR gives users the right to examine the data your application holds on it, edit the data and delete the data entirely from your application. Obviously, we cannot know what data you have, where it lives or how its all linked together but what we do know is what personal data a default ASP.NET Core Identity application holds and how to delete Identity users, so we can give you a starting point. When you create an ASP.NET Core application with Individual Authentication and the data stored in-app you might notice two new options in the user profile page, Download and Delete. <figure id=\"attachment_12185\" aria-labelledby=\"figcaption_attachment_12185\" class=\"wp-caption alignnone\" ><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/snip_20180227145719-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/03\/snip_20180227145719-1-300x127.png\" alt=\"Default Data Control actions\" width=\"300\" height=\"127\" class=\"size-medium wp-image-12185\" \/><\/a><figcaption id=\"figcaption_attachment_12185\" class=\"wp-caption-text\">Default Data Control actions<\/figcaption><\/figure><\/p>\n<p>Download takes its data from ASP.NET Core Identity and creates a JSON file for download, delete does as you\u2019d expect, it deletes the user. You will probably have extended the identity models or added new tables to your database which uses a user\u2019s identity as a foreign key, so you will need to customize both these functions to match your own data structure and your own GDPR requirements, to do this you\u2019ll need to override the view for each of these functions. If you look at the code created in your application you will see that a lot of the old template code has vanished, this is because of the new \u201c<a href=\"https:\/\/blogs.msdn.microsoft.com\/webdev\/2018\/03\/02\/aspnetcore-2-1-identity-ui\/\">Identity UI as a library<\/a>\u201d feature. To override the functionality, you need to manually create the view as it would appear if ASP.NET Identity\u2019s UI were not bundled into a library. For now, until tooling arrives, this is a manual process. The Download capability is contained in <code>DownloadPersonalData.cshtml.cs<\/code> and the Delete capability is in <code>DeletePersonalData.cshtml.cs<\/code>. You can see each of these files in the <a href=\"https:\/\/github.com\/aspnet\/Identity\/blob\/release\/2.1\/src\/UI\/Areas\/Identity\/Pages\/Account\/Manage\/DeletePersonalData.cshtml.cs\">Identity UI GitHub repository<\/a>. For example, to override the data in the download page you must create an Account Folder under AreasIdentityPages, then a Manage folder under the account folder and finally a DownloadPersonalData.cshtml and associated DownloadPersonalData.cshtml.cs. For the cshtml file you can take the <a href=\"https:\/\/github.com\/aspnet\/Identity\/blob\/release\/2.1\/src\/UI\/Areas\/Identity\/Pages\/Account\/Manage\/PersonalData.cshtml\">source<\/a> from GitHub as a starting point, then add your own namespace, a using statement for Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage.Internal and the instruction to wire up MVC Core Tag Helpers, for example if application namespace is WebApplication21Auth the .cshtml file would look like this: <\/p>\n<p>Then for the corresponding .cs file you can take the default implementation from the <a href=\"https:\/\/github.com\/aspnet\/Identity\/blob\/release\/2.1\/src\/UI\/Areas\/Identity\/Pages\/Account\/Manage\/DownloadPersonalData.cshtml.cs\">source<\/a> as a starting point for the OnPost implementation so your version might look like the following: <\/p>\n<p>You can give feedback on the data control features of Identity at <a href=\"https:\/\/github.com\/aspnet\/Identity\/issues\">https:\/\/github.com\/aspnet\/Identity\/issues<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>These features should put you in a good starting position for the GDPR but remember the GDPR places a lot more requirements on your company and application than just the features we provide, including protection of data at rest, risk assessments and management, data breach reporting and so on. You should consult with a GDPR specialist to see what implications the regulation has for your company.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2018 sees the introduction of the General Data Protection Regulation, an EU framework to allow EU citizens to control, correct and delete their data, no matter where in the word it is held. In ASP.NET Core 2.1 Preview 1 we\u2019ve added some features to the ASP.NET Core templates to allow you to meet some of [&hellip;]<\/p>\n","protected":false},"author":3338,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,7509],"tags":[7542],"class_list":["post-36921","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-aspnetcore","tag-asp-net-core-2-1-0-preview1"],"acf":[],"blog_post_summary":"<p>2018 sees the introduction of the General Data Protection Regulation, an EU framework to allow EU citizens to control, correct and delete their data, no matter where in the word it is held. In ASP.NET Core 2.1 Preview 1 we\u2019ve added some features to the ASP.NET Core templates to allow you to meet some of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/36921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/3338"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=36921"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/36921\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=36921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=36921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=36921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}