System.UnauthorizedAccessException: Access to path is denied - asp.net

Good afternoon,
I have recently purchased a server with Plesk 12 as the Control Panel.
I don't have much experience using Plesk.
For testing purposes, I created a simple ASP.NET project which tries to read/write from a txt, as shown below:
String logPath = #"C:\inetpub\vhosts\xxx.com\httpdocs\log_application_error.txt";
StreamWriter textWriter = new StreamWriter(logPath, true);
When the StreamWriter instance is created, I get the following error:
System.UnauthorizedAccessException: Access to the path 'C:\inetpub\vhosts\xxx.com\httpdocs\log_application_error.txt' is denied.
I tried granting read/write permissions to the txt file, and even granted Full Control to "Everyone", but the result was the same.
Plesk seems to hide everything so that it is handled through the Control Panel. I don't see any Applications Pools on the IIS so I am not even sure what is the identity it is running under.
Any help would be greatly appreciated.

Try to set "Additonal write/modify permissions" at "Hosting settings" of your domain:

Try to fix it with following commands:
cacls C:\Windows\assembly\GAC_MSIL /E /R psacln /T /C
cacls C:\Windows\assembly\GAC_MSIL /E /R psaadm /T /C

Related

How do I change the physical path of web site in IIS10 with APPCMD to Amazon FSx path?

I need to change the physical path of a web site through command line via the appcmd.exe tool which I want to point to Amazon FSx, but I can't figure out why I have errors. Here is what I'm using in PowerShell as admin:
PS C:\Windows\system32> appcmd list app
APP "Test Services/" (applicationPool:Test Services)
APP "Test Simple Site/" (applicationPool:Test Simple Site)
APP "Test/" (applicationPool:Test)
PS C:\Windows\system32> appcmd list vdir
VDIR "Test Services/" (physicalPath:\amznfsxthjfzxec.test.local\share\Sites\TestServices)
VDIR "Test Simple Site/" (physicalPath:\amznfsxthjfzxec.test.local\share\Sites\TestSimple)
VDIR "Test/" (physicalPath:C:\inetpub\wwwroot)
PS C:\Windows\system32> appcmd set site /site.name:"Test" /application[path='Test/'].virtualDirectory[path='Test/'].physicalPath:"\\amznfsxthjfzxec.test.local\share\Sites\Test"
ERROR ( message:Malformed collection indexer; format is [#position,name='value',name2='value2',...]. The #position specifier
is optional, and be '#start', '#end', or '#N' where N is a numeric
index into the collection. )
Could you please advise me? Thank you!
If you want to replace physical path for the virtual directory under site level.
Please try this
appcmd.exe set config -section:system.applicationHost/sites /[name='Default Web Site'].[path='/'].[path='/myvir'].physicalPath:"\\WIN10\Share" /commit:apphost
If you also have an application under my site like "mysite/myapplication" and the virtual dirtory is "mysite/myapplication/my virtual.
Then you could try this
appcmd.exe set config -section:system.applicationHost/sites /[name='Mysite'].[path='/myapp'].[path='/myvir'].path:"\\WIN10" /commit:apphost
Please remember to run cmd as adminsitrator when you try this.

Execute of .bat from does not start with expected user

I have the following code:
Dim billy As New System.Diagnostics.ProcessStartInfo("C:\somepath\dumpuser.bat", "")
billy.RedirectStandardOutput = True
billy.WindowStyle = Diagnostics.ProcessWindowStyle.Hidden
billy.UseShellExecute = False
Dim joey As System.Diagnostics.Process
joey = System.Diagnostics.Process.Start(billy)
dumpuser.bat:
echo %username%
net user %username% /domain 2>&1
exit /B 1
I get the following output:
C:\Windows\SysWOW64\inetsrv>echo SERVERXX$
SERVERXX$
C:\Windows\SysWOW64\inetsrv>net user SERVERXX$ /domain 2>&1
The request will be processed at a domain controller for domain xxxxx.com.
There is no such user: SERVERXX$.
More help is available by typing NET HELPMSG 3755.
C:\Windows\SysWOW64\inetsrv>exit /B 1
I would expect the output of %username% to be xxxx\IUSR_SERVERXX because the application pool is set to identity = "xxxxx\IUSR_SERVERXX"
We are using this script to debug the permissions problem, the real .bat file prints to a printer. We are debugging it because the printer "broke" after we changed the identity for the application pool. We have narrowed it down to a permissions problems.
We had other permissions problems on reading and writing files after the change to the application pool identity. Those were solved very simply by changing the permissions on the file. This is different because the script is being executed by a user that is not even defined on the local machine or in active directory on the domain controller.
The question:
How can I get this script to execute as xxxx\IUSER_SERVERXX?
This was a false alarm.
The problem is that .bat is not a reliable way to get the username.
We wrote this c# code and called it in the .bat file as well.
using System;
class Sample
{
public static void Main()
{
Console.WriteLine();
Console.WriteLine("UserName: {0}", Environment.UserName);
}
}
That code output the username we would expect.
We then realized that the problem was not a bad user id, but permissions on the printers.

.bashrc file not created in ldap client machine when using ldap authentication

My objective is to configure a machine as client to use ldap authentication from a ldap server. I added user in ldap server. Also registered ldap service to be used by client.
But the problem is when I am trying to login into the ldap client machine, I am not getting the "user#hostname" prompt, instead I am getting "-bash-4.1$".
I searched and find its something to do with ".bashrc" files such as ".bash_history", ".bash_profile", ".bash_logout".
I can manually create these files but I want them to be automatically generated, and executed while login.
If anyone knows the cause of the problem and the solution please share.
Thanks,
Yogesh
You should create a script in /etc/profile.d for this propose, like that:
cat /etc/profile.d/bash_create.sh
a='export PS1="\[$(tput bold)\]\[$(tput setaf 2)\][\u#\h \W]\\$ \[$(tput sgr0)\]"'
b='export other variable'
c='export other variable'
d='alias ...."
if [ ! -f BASHRC ]; then #if not exists
echo -e "$a\n$b\n$c\n$d" >> $BASHRC
source $BASHRC #execute bash script
fi
I had this problem too and I solved deleting the "/home/< ldapuser >" and then I login again and the home directory was created. Also you can check if /etc/pam.d/system-auth has properly pam_oddjob_mkhomedir.so
session optional pam_oddjob_mkhomedir.so umask=0077
To enable mkhomedir you can run
authconfig --enablemkhomedir --update

White page when deploying Symfony2 Project

After I finished my project of symfony2 on windows I wanted to deploy it on a digitalocean server with Linux-Ubuntu OS. But there are some problems I can't figure them out. Please help me soon.
I uploaded the web folder files to folder html on server and other files (src , app , bin, vendor) to www folder. I also followed the instructions on config.php and solved the problems. But yet:
1- When I trying to type url : ip_address/app.php/ on browser a white page comes. No page and No error!
2- When I want to clear the cache in production env using the putty this error happens. ( Unable to write in the "C:/wamp/www/my-project/app/cache/prod" directory) but there is no such problem when clearing on localhost (I think this problem is because of transferring the project from windows to linux)
Please help me.
You probably have some errors (maybe cache directory).
For testing open the file web/app_dev.php and comment this:
/*if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/
Now you can access your page via ip_address/app_dev.php/ and see errors. When you finish, don't forget to uncomment this.
If you have problems with cache, then I suggest you to upload code without cache directory. Then create this directory in the server and give it right permissions.

How to check whether ASP.NET 4.0 registered on IIS 7.5

Is there any reliable way how to check whether ASP.NET 4.0 registered on IIS 7.5 programmatically? I need to test it in the installer as prerequisite, before ASP.NET application installation start.
If ASP.NET 4.0 not registered on the IIS, later during the installation just installed application cannot be run and returns 500 internal server error (and it is too late to solve the problem). Instead, I want to show some warning (and hint how to solve the issue) before any installation steps started. But no reliable solution found yet.
AFAIK, registry entries reading sometimes may not work correctly. So now, I run aspnet_regiis.exe -lv to list versions (as suggested here) and parse the output. But even if .NET not registered correctly my test (falsely) succeeds, because the output is (contains version 4.0):
2.0.50727.0 C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll
4.0.30319.0 C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
(Win7 32bit)
Running aspnet_regiis.exe -ir can repair it in this case.
It's similar issue as this question, but I need test it programmatically.
Do you have any ideas or experiences?
Using your own answer as a basis, this can also be done using the command line (with elevation):
%WINDIR%\System32\inetsrv\appcmd.exe list apppool /managedRuntimeVersion:v4.0
If anything is returned, ASP.NET 4.0 is registered.
The issue with this approach is that it seems to be possible to create 4.0 application pools manually even if the filter is not installed, and then this method would not work.
EDIT:
I have ended up running these three checks:
aspnet_regiis.exe -lv (should return a line containing "c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll")
appcmd.exe list apppool /managedRuntimeVersion:v4.0 (should return a line containing "MgdVersion:v4.0")
appcmd.exe list config -section:system.webServer/isapiFilters (should return a line containing "c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll")
Note that I only care about 32bit versions.
If all three checks pass, it can be concluded that ASP.NET 4.0 is registered. Still not 100% false positive-proof though.
This is an old question, but I'm posting an answer because your question is one of the top results on google, and it's unanswered.
The registry key you are looking for is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0. If that key is present, then .Net 4 has been installed and is registered in IIS.
If you just want to check if .Net 4 is installed, you can check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full.
In Powershell it could be done like this:
# load the IIS-Commandlets
Import-Module WebAdministration
# get the isapi filters currently loaded
Get-WebConfigurationProperty -Filter "/system.webServer/isapiFilters/filter" -name *
An output could look like this:
name : ASP.Net_4.0_32bit<br/>
path : %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll<br/>
enabled : True<br/>
enableCache : True<br/>
preCondition : runtimeVersionv4.0,bitness32<br/>
ItemXPath : /system.webServer/isapiFilters/filter[#name='ASP.Net_4.0_32bit']<br/>
Attributes : {name, path, enabled, enableCache...}<br/>
ChildElements : {}<br/>
ElementTagName : filter<br/>
Methods :<br/>
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema<br/>
name : ASP.Net_4.0_64bit<br/>
path ........
Based on that we could write this code to check and install .NET 4 if needed:
$DotNet4Missing = $true
# lets make sure we got .net 4 correctly setup
$isapiFilters = Get-WebConfigurationProperty -Filter "/system.webServer/isapiFilters/filter" -name *
"/system.webServer/isapiFilters/filter count: {0}" -f $isapiFilters.Count
foreach ($filter in $isapiFilters)
{
"filter.name: {0}" -f $filter.name
if ($filter.name -eq "ASP.Net_4.0_64bit")
{
"-> Found .NET 4 - GREAT!"
$DotNet4Missing = $false
}
}
if ($DotNet4Missing)
{
"Missing .NET 4 IIS integration - running aspnet_regiis.exe"
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "-iru"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
"aspnet_regiis.exe stdout: {0}" -f $stdout
"aspnet_regiis.exe stderr: {0}" -f $stderr
"aspnet_regiis.exe ExitCode: {0}" -f $p.ExitCode
}
Summary: The problem described above occurs on non-server operating system (Win7). The .NET 4.0 is not registered on the IIS even if you install IIS before .NET 4.0 (and so .NET should be registered on IIS correctly). This causes unexpected problems during any ASP.NET application installation -- until aspnet_regiis.exe -ir is ran from the commandline. There is no problem with Win 2008 (i.e. when IIS installed before .NET 4.0 then .NET is registered correctly on IIS and everything works as expected).
So finally my colleague told me what possibly could be solution of the problem. I've verified that following solution works fine (also on Win7). ServerManager from Microsoft.Web.Administration namespace can be employed easily:
public static bool IsAspNetRegistered()
{
using (var mgr = new ServerManager())
{
return mgr.ApplicationPools.Any(pool => pool.ManagedRuntimeVersion == "v4.0");
}
}
In case of successful .NET registration on IIS, there is at least one application pool which runtime version is set to "v4.0" so this fact was used for the check.
Of course, if anybody deletes all application pools, this method can work incorrectly. But this is bit pathological situation I don't care. The main issue is to prevent that although everything is done according our installation recommendations, still not possible to install the application on the machine.

Resources