Thứ Sáu, 13 tháng 11, 2020

[ASP.NET] Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

 LỖI


Server Error in '/' Application.

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))


ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.


=> IIS ->Site -> Authentication -> ASP.NET impersonating -> Enable 

Thứ Năm, 5 tháng 11, 2020

[Plesk] How to change default MySQL directory in Plesk Window

 Note: Custom data directory location for client's MySQL has been supported since Plesk 17.8 MU #41


To change database location follow next steps:

  1. Connect to the server using RDP as Administrator.

  2. Shut down MySQL service through Control Panel > Administrative Tools > Services > right-click MySQL57 > Stop.

    Note: if MysQL 5.6 is used, stop MySQL Server service instead.

  3. Copy "%plesk_dir%"\Databases\MySQL\data to the new location (e.g. D:\MySQL\data).

  4. Edit "datadir" option in the C:\"%plesk_dir%"\Plesk\Databases\MySQL\my.ini file in the following way:

    [MySQLD]
    port=3306
    ...
    datadir=D:\\MySQL\\Data
    ...

  5. Give "Full control" permission to the "NT SERVICE\MySQL57" group: right-click the destination folder > Properties > Security.

    Note: if MysQL 5.6 is used, Give "Full control" permission to the "NT SERVICE\MySQL56" group instead.

  6. Start "MySQL57" service Control Panel > Administrative Tools > Services > right-click MySQL57 > Start.

  7. To prevent "Plesk Reconfigurator" to change the path to the new folder location edit the C:\%plesk_dir%\etc\DiskSecurity.xml file in the following way:

    <!-- [PRODUCT_ROOT_D]\MySQL\bin -->
    ...
    <Entry AccounType="1" Domain="NT SERVICE" Account="MySQL57" Path="<D:\MySQL\Data>" AceFlags="FilesOnly" AccessMask="ReadAndExecute" EntryFlags="0x04" />
    ...

    Note: D:\MySQL\Data is the path to the new folder location and can be changed to any required one.

  8. To prevent the resetting of datadir value it is required to change the path in the MYSQL_DATA_D registry to the required one:
    1. 
    Click the Start button.
    2. Type regedit.exe and press the Enter button:


    3. In the opened Windows registry navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\PLESK\PSA Config\Config and find the MYSQL_DATA_D string which contains the actual database directory:

    Indexable text here
    4. Change this value to the required one:
    screenshot1.PNG

Thứ Tư, 4 tháng 11, 2020

[ASP.NET CORE] Bật Development environment để show chi tiết lỗi

 Thông báo lỗi có dạng

The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.


Để set Development mode có thể set trong web.config thêm cụm tag <environmentVariables>


<system.webServer>
   <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\Application.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>