Posts

Avoid AsNoTracking and Include when querying using Entity Framework in ASP.NET

 https://www.devtrends.co.uk/blog/avoid-asnotracking-and-include-when-querying-using-entity-framework-in-asp.net

SharePoint Online authentication using CSOM

Image
Jerryzy   •  Follow 10,436 Reputation points Apr 1, 2021, 9:55 PM Hi  @Lakshman Bana  , PnP.Framework Library supported to use App Id and App Secret to get the ClientContext and this library supported both .NET Framework and .NET Standard: Please first install PnP.Core as this is the dependent package for PnP.Framework: Copy Install-Package PnP.Core -Version 1.1.0 Install-Package PnP.Framework -Version 1.4.0 Then authentication with App Id and AppSecret ( register in https://siteurl/_layouts/15/AppRegNew.aspx) like this: Copy using Microsoft.SharePoint.Client; using PnP.Framework; ClientContext ctx = new AuthenticationManager().GetACSAppOnlyContext("SiteUrl", "AppId", "AppSecret"); ctx.Load(ctx.Web); ctx.ExecuteQuery(); Here is a detailed blog for your reference: https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs Recommend:  M365 – SharePoint Online – CSOM – Getting SharePoint client context using ...

Using Visual Studio Code to Check in a Folder to DevOps

 https://stackoverflow.com/questions/67616266/how-to-connect-visual-studio-code-with-azure-git-repo Issue  When pushing to..., I got the following error: git push EUM-Config main error: RPC failed; curl 56 HTTP/2 stream 7 was reset send-pack: unexpected disconnect while reading sideband packet fatal: the remote end hung up unexpectedly Everything up-to-date Solution: git config --global http.version HTTP/1.1 https://stackoverflow.com/questions/66366582/github-unexpected-disconnect-while-reading-sideband-packet

DevOps: Authentication failed for Azure Git

Issue: Visual Studio keep asking username and password when trying to clone a repository.  Solution: https://stackoverflow.com/a/70528023/4979261 Login into Azure Dev Ops portal. Go to Project you wish to clone. Select Repo from left menu. Click on Clone from right top corner. Click Generate Git Credential Enter given username & password where you are cloning repository. you are done!

Use USB Connection to Debug Android Devices from Desktop Chrome

Image
Quick Start:      How to get the web console log in Chrome for Android Where to locate the Build Number?       How to activate ‘Developer options’ on your Android smartphone Troubleshooting:      Remote debug Android devices The Key Points: If the device does not show up in the Devices list: 1.    Revoke USB Debugging Authorizations  from the  Developer Options 2. Unplug and reconnect the USB between Android device and PC     Swipe down to check the USB File Transfer options. It must be set to "USB tethering".     Answer Yes for  Allow USB Debugging  prompt on your Android device That's all.

The Best Article to Explain ASP.NET Core Endpoint Routing

  https://www.tektutorialshub.com/asp-net-core/asp-net-core-endpoint-routing/

Using .NET OpenAPI tool to auto-generate client code

 https://markheath.net/post/openapi-autogen-aspnetcore Note: please user Browse button to select OpenAPIs\swagger.json when adding OpenAPI

Push Existing Static Website Code to DevOps Using Visual Studio Code, and Publish to Azure from DevOps

Push Existing Static Website Code to DevOps Using Visual Studio Code Note: This can't be done via Visual Studio as Visual Studio doesn't have any project template for static web site (contain html, JavaScript, css, images etc only , no any .NET related code) Step 1: Create a local folder c:\dev\wan\Peace Fountain as the .Git repository Step 2: In DevOps      2.1 Create a project named Peace Fountain     2.3 Click "Clone in VS Code", select c:\dev\wan\Peace Fountain as repository location.            Note: This will create a  Peace Fountain sub folder under c:\dev\wan\Peace Fountain. We can see the auto-created .git under folder C:\dev\wan\Peace Fountain\Peace Fountain.      2.4 Copy all existing static web site code to C:\dev\wan\Peace Fountain\Peace Fountain Step 3: In Visual Studio Code     3.1 Commit All     3.2 When you click Synchronize Change button (the bottom line), you may see error:...

Visual Studio 2019: Switch an existing project from TFS to Azure DevOps

Steo 1: Create the empty projetc on  Azure DevOps Step 2:   Open existing project, Click Solution/File/Source Control/Advanced/Remove Map, Advanced/Change Source Control/Unbind all Step 3: Team Explorer/Manage Connections/Connect to project Step 4: Right click the Solution, Create Git repository/Other: Existing remote/Paste the URL of the remote repository/Create and push

"Your connection to this site is not private" in SharePoint 2016

This happened only when access from localhost. SharePoint 2016 Management Shell New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword Credit to:   https://www.enjoysharepoint.com/your-connection-to-this-site-is-not-private-sharepoint-2016/

Common WCAG / AODA Web Accessibility issues and Quick Fixes

Web Accessibility Evaluation Tool:  https://webaim.org/services/evaluation Empty link Before:  <a href="#"><span class="fa fa-search"></span></a> After:   <a href="#" aria-label (or title) ="Search"><span class="fa fa-search" aria-hidden="true"></span></a> Missing form label Before:                                                         <input type="text" class="form-control" placeholder="Search for..." id="searchQuery"> After: <label class="control-label sr-only" for="searchQuery">Search for...</label> <input type="text" class="form-control" placeholder="Search for..." id="searchQuery">

Visual Studio 2019: SharePoint 2010 Visual Webpart issue

Now days I have to use the modern Visual Studio 2019 to update the old SharePoint 2010 web site to meet the AODA accessibility standard.  Issue 1: ScriptManager and UpdatePanel not found in namespace System.Web.UI Solution:  Firstly locate the project where <asp:ScriptManager> is used. Usually it's used in the master page (in the branding project). Then add a reference to the assembly  System.Web.Extensions . Select Project-> Add Reference and then select the assembly name.  https://stackoverflow.com/questions/19122286/scriptmanager-and-updatepanel-not-found-in-namespace-system-web-ui Issue 2 The auto-generated webart.ascx.g.cs is missing 1. The “Site URL” property of your project The “Site URL” property of your project should be correct. 2. Click on the *.ascx and see its property The “Custom Tool” property should be set to “SharePointWebPartCodeGenerator” value. Configure properties, save *.ascx, make any temporary changes to *.ascx file, save again and PU...

SameSite Cookies

 https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/ https://www.thinktecture.com/en/identity/samesite/prepare-your-identityserver/ https://brockallen.com/2019/01/11/same-site-cookies-asp-net-core-and-external-authentication-providers/ For debugging purpose Go to chrome://flags and disable #same-site-by-default-cookies. If needed, also disable #cookies-without-same-site-must-be-secure . Restart Chrome for the changes to take effect. https://support.google.com/chrome/thread/34237768?hl=en

Visual Studio 2019: https://localhost:xxxx does't work on IIS Express

VS 2019 version 16.4, Net Core 3.1 SDK https://stackoverflow.com/questions/58175973/visual-studio-2019-this-site-can-t-provide-a-secure-connection-on-localhost/58209538#58209538 Try 1: dotnet dev-certs https --clean dotnet dev-certs https --trust didn't work Try 2: Repairing Visual Studio 2019: didn't work! Solution: Uninstall IIS 10.0 Express and then reinstall it!

Common Net Core Issues when debugging a web app using IIS Express

Remote Access to Local ASP.NET Core Applications from Mobile Devices - Kloud Blog https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti Error: unable to connect to web server 'IIS Express' Solution: restart Visual Studio as Administrator Error: Bad host name when starting using http://localhost:xxx Solution:  Delete .vs folder (requires to close Visual Studio 2017) The ssl port is used. Please check launchSettings.json, set  "sslPort" to 0.  Error: This site can’t be reached when starting a SSL site Solution:  To fix self-signed certificate on the local machine you need to:  Delete .vs folder (requires to close Visual Studio 2017) Run these commands in cmd As Administrator: cd "C:\Program Files (x86)\IIS Express" IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:12345/ -UseSelfSigned Make sure you run VS2017 As Administrator and check if the issue addressed Note:...

Visual Studio 2019: Attached to Process not hitting break points for Net Core

Image
Cagri (Charlie) Aslan [MSFT] Aug 30, 2019 at 06:32 PM Can you check if you’ve used the correct debugger? i.e. Managed (CoreCLR) vs Managed (4.6)? You want the CoreCLR one to debug a coreclr app. https://developercommunity.visualstudio.com/content/problem/717375/debug-attached-to-process-not-hitting-break-points.html

Failed to Login Visual Studio 2019 with my Microsoft Account

Open Visual Studio Click Help > Send Feedback > Report a problem An instance of Visual Studio Feedback will open Attempt to sign in using your MS account If sign in is successful, check if you are signed into Visual Studio https://developercommunity.visualstudio.com/content/problem/70622/unable-to-login-into-visual-studio-2017-with-micro.html

Visual Studio 2019: Net Core Deployment Mode and Target Runtime

To avoid the weird 502.3 or other errors, please follow these rules: Deployment Mode Always select Self-contained except for Net Core 3.1 unless Net core 3.1 is installed on Windows Server  2012 R2+ (Net Core 3.1 requires 2012 R2+) Target Runtime Always select Win-x64. Though the "portable" option should work for all platforms, but it contains too many DLLs. Please check the publish profiles to make sure the profile is correct, e.g. no <_IsPortable>true</_IsPortable>. Sometimes the generated publish profile may not correct, please delete and re-create the profile. The recreation of publish profile is also suggested when Deployment Mode or Target Runtime is changed. Publish Mode Always use \\share instead of FTP. A lot of times using FTP can't correctly complete the deployment.

Using ReCaptcha v2 Insible in MVC Net Core 2 Applications

Suppose There is only one form in the page The form will be submitted in a way that can fire the the onsubmit event like either of the following: <input type="submit" value="Submit" /> <button type="submit">Submit</button> You can not submit a form in a way that can bypass the onsubmit event like the following (because the direct invocation of submit() will not fire the onsubmit event): <button type='button' onclick='getElementById("myForm").submit();'>Submit</button> The flow Clicking on submit -> Model client validation by jquery.validate -> reCaptcha client validation by grecaptcha.execute() -> (reCaptcha puzzle challenges if any) -> submitted by reCaptcha data-callback -> Model server validation -> reCaptcha server validation -> done Only after the reCaptcha client side validation has been passed, the form has chance to reach the back end. However, the ReCapt...

Using ReCaptcha v3 in MVC Net Core 2 Applications

/Views/Shared/_reCaptcha.cshtml @using Microsoft.Extensions.Configuration @inject IConfiguration _configuration <script src="https://www.google.com/recaptcha/api.js?render=@_configuration.GetSection('Recaptcha_v3')['SiteKey']"></script> grecaptcha.ready(function () { var $form = getForm(); if ($form.length == 0) { $(".grecaptcha-badge").hide(); } else { $form.on("submit", function(e){ e.preventDefault(); submitWithUserResponseToken($form); }); } }); function getForm() { return $("form").eq(0); } function submitWithUserResponseToken($form) { if ($form.length > 0) { grecaptcha.execute('@_configuration.GetSection("Recaptcha_v3")["SiteKey"]', { action: $form.attr('name') }).then ...