Thursday, April 1, 2021

WebApi 2 - CORS error after deployment Access to the path '/bin/roslyn/csc.exe' denied

 This error can be seen after redeployment of the API website in developer tools (F12) 

 

This is a misleading error message; real underlying problem is application pool account for the API website does not have execute permissions on the API website’s folder.  

The permissions problem can be seen by trying to open api website on the IIS Server hosting this website. If we try to send AJAX request to the API website on the hosting IIS server, the error message changes to 




[Win32Exception (0x80004005): Access is denied] 

 

[ExternalException (0x80004005): Cannot execute a program. The command being executed was "<path of the API website folder on server>/bin/csc.exe" /shared /keepalive:"10" /noconfig  /fullpaths @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\5a229d66\a33ece8d\xf2kzry1.cmdline".]



 


This problem can be fixed by navigating to the IIS server and providing full control permissions for app pool account on the API Website folder.



If we don't want this issue to repeat after every deployment, we can add IncludeSetAclProviderOnDestination tag in the publish profile (.pubxml) file as explained at https://stackoverflow.com/questions/54911986/iis-application-pool-identity-permissions-reset-on-every-visual-studio-app-publi



<?xml version="1.0" encoding="UTF-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <PropertyGroup> <IncludeSetAclProviderOnDestination>False</IncludeSetAclProviderOnDestination> </PropertyGroup> </Project>

This parameter can also be added to .csproj file or as msbuild parameter as exlpained at https://blogs.iis.net/msdeploy/skipping-setting-an-acl-in-a-visual-studio-2010-deployment-package


1) Edit the .csproj file and set  <IncludeSetAclProviderOnDestination>False</IncludeSetAclProviderOnDestination>

2) msbuild.exe myproject.csproj /p:IncludeSetAclProviderOnDestination=False


Another way of specifying permissions is explained at https://davidsonsousa.net/blog/post/setting-folder-permissions-using-web-deploy


More references/options:



  1. https://docs.microsoft.com/en-us/answers/questions/202683/why-is-access-to-the-path-39binroslyn39-denied.html
  2. https://stackoverflow.com/questions/54893505/server-error-in-application-access-is-denied
  3. https://stackoverflow.com/questions/32780315/could-not-find-a-part-of-the-path-bin-roslyn-csc-exe


Wednesday, March 3, 2021

Partial views in bootstrap modal using AJAX

 This article explains how partial views can be used in bootstrap modal for CRUD operations on a related child entity. It uses ajax to dynamically load and save content displayed in a bootstrap modal dialog box.


https://www.codeproject.com/Articles/786085/ASP-NET-MVC-List-Editor-with-Bootstrap-Modals

Tuesday, February 16, 2021

Thursday, January 28, 2021

Friday, December 25, 2020

MVC Bootstrap dropdown menu and up down symbols

MVC  Bootstrap has a super easy way to create dropdown menus and add up/down symbols on these menus. Basically we just need to include this style in the css file.


/* Style to reverse the caret icon from pointing downwards to upwards */

.dropdown.open .dropdown-toggle .caret {

    border-top-width: 0;

    border-bottom: 4px solid;

}


Please see a fiddle in action at https://jsfiddle.net/pranavnk/o3z7yxf8/4/


reference: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_dropdown_icon&stacked=h


Regex Email validation in c# dot net core

 Use this regex /^_?[a-zA-Z0-9]([a-zA-Z0-9]*[._+-])*[a-zA-Z0-9_]+@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-...