Log4Net doesn't write when iis hosting WCF service - wcf

Log4Net doesn't write when iis hosting a WCF Service.
it works great when i use the self hosting ( Visual Studio Development Server),
but when i run it using the IIS it doesn't write anything.
i read about this prolem and the conclusion is that
it must be a permission problem, but i don't know how to solve it.
how can i check that i have a permission to write a log file?
where can i change the permission? change AppPool users?
Can you give me some simple steps of how to check if i have a permission problem?
i'm an administrator on my computer.
i'm trying to create the file in the project folder.
The file is a rolling file appender.
thank you.

For my IIS hosted WCF services with HTTP endpoints, logging to App_Data has proven to be the easiest solution.
<file value="App_Data\log.txt"/>

You need to make sure the AD user that the application pool is running under has create/read/modify privileges to the directory where you're outputting your log files. By default, as far as I know, your app-pool user can't create/modify files. So it sounds like you're on the right track.
Edit: Here is an article to help you determine who your app-pool is running as, if needed.

I ran into a similar situation with Enterprise Library not writing to a file using the Logging Application block for an ASP.NET application. This was EntLib 4.1, the eventual solution after trying ACL modifications was to assign the App Pool to run as Network Service and the text logging commenced, not saying this is your solution, or the best one, but its worth a try.

From my experience, in IIS 7+ you have to make sure the application pool has permission to write in the particular log directory. For example,

The problem was solved when i moved the path of the log from "c:\Log.txt" Hard drive to "c:\log\Log.txt" folder in the hard drive.

Related

Allow write permissions for ASP.NET Core API application

I am working on an ASP.Net Core 3.1 API application that downloads files. It will be saving those files to a folder outside the website. I know there will be an issue of allowing the process to write to the target directly. I found this post that talks about setting things up for .Net Framework on IIS7 (IIS7 Permissions Overview - ApplicationPoolIdentity) but I am deploying on IIS 8.5 and I am not able to find the user "IIS AppPool\DefaultAppPool".
Q1: So what exactly is the "IIS AppPool" part? Normally I am used to that being either the machine name or the domain name, but it is clearly neather since it is to be found on all machines.
SOLVED!!!!! I HAVE created a unique app pool for the app, let's call it 'upload-system'. I was going to ask how to enter it into the "Select User or Groups" and thought I should test it without quotes real quick... it worked!!!! I still want to know the answer to Q1, but I got the main problem working!!!!
The reason you cannot find the DefaultApppool is that your application pool may no longer have this application pool. If you want to give write permissions to the folder, you should try IIS AppPool\Application pool name. For example, your application pool name is Test. What you should assign to the folder is IIS AppPool\Test.
Find the application pool where your deployed application is located, and then assign this user permission to the folder.

LocalResource not available after publishing mvc4 to azure

I've a very simple application built in MVC4. This application allow the users to upload a file, and the application generates an output.
This app works great locally, but when I publish to azure (by right click -> publish), I get a less descriptive error. I've figured out that the error was because in the code, we accessed to a server relative path, and that is not possible in azure. So I've found a way to solve that in this link, that says that I should use LocalResource, rather than Server.MapPath. That make sense for me, but so far, I'm struggling with the suggested line.
LocalResource localResource = RoleEnvironment.GetLocalResource("DownloadedTemplates");
I'm not able to get it working, and also can't get a proper error. BTW I'm not sure how to enable the error log in azure :(
So, after going deeper in MSDN, I've seen that I should configure the Local Storage Resources, but as I've created a local MVC4 project, I can't find where I should configure this.
I need to be able to store a temporary file in the application (hosted in azure).
Did someone faced with this problem?
Anybody knows how to enable the Local Storage Resource in a project like that?
TIA!
Milton Rodríguez
Well, after struggling a while, I've ended up using Windows Azure Tools.
The steps:
Add a new project
Under Cloud category, select Windows Azure Cloud Service.Note that if you don't have this option, an option to install the needed SDK will be shown. Install it first.
Name it properly :)
New Windows Azure Cloud Service window will appear, select the role that fits your needs. In my case, I choose ASP.Net MVC4, and then removed it.Note that you can edit the name of the created role at the right.
In the Roles folder of your new project, select Add, and then Web Role Project in solution. Your project will be an option to add.
You can remove the other role in the folder, the web project created in step 4, and also the folder ending in Content (ie. WebRole1Content). Basically, you can remove the created assets, but the Azure Service, and link the service to your project.
You're almost done. Follow this link to configurate your local storage :)
Now you're done!

IIS7/Win7 - Make sure that the application pool identity has Read access to the physical path

I am running a localhost instance (so domains are not my issue!) on my laptop utilizing Win7 and IIS7. I am getting authentication errors on my website and my one virtual directory.
default website - localhost:80 c:\mydirectory\localhost
virtual directory - c:\mydirectory\weborb30
Please notice these are not under c:\inetpub\wwwroot!
Now, I did some googling/binging and discovered that I needed to add my [machinename$] to the ACLs. (Hope I said that right.) I did that, even though it is a domain thing. Nothing changed. I further read that IIS7 is now using ApplicationPoolIdentity and I tried finding that on my local machine - no luck there. So, I changed the App Pool to run under another built in account. Now, not only do I get the Authentication error I can no longer AttachProcess to W3WP.
How the heck do you PROPERLY setup VS2005, IIS7 on a WIN7 box to run locally???
I was having a similar problem and ended up fixing it by giving read permissions to the "IUSR" user and "IIS_IUSRS" group.
I'm not really sure why this works. It seems odd needing to give permissions to IUSR when I thought it would have been included in the IIS_IUSRS group. I think part of it relates to the account the application pool runs as (e.g. "IIS AppPool\Classic .NET AppPool" for a classic .NET application pool in IIS 7.5 / Windows 7), but I'm still unclear.
This StackOverflow question seems to be related.
Before you made changes to the app pools, all you probably needed to do was add read access to your physical directory for the "network service" account (that is the default account used by asp.net on vista & win7).
I think what you may be looking for at this point is this:
aspnet_regiis -ga <useraccount>
The -ga switch tells aspnet_regiis to configure all the security for asp.net. Usually you only need to do this stuff when you are using impersonation in your application, but if you are changing the default user for the application pools then you are effectivly doing the same thing IIS wide.
The best complete documentation I've found is on MSDN. It applies to the previous version of IIS, IIS 6, but it is pretty easy to apply it in IIS 7 environments
Just try to restart the IIS here: IIS Location to restart and don't use iisreset etc
if that doesn't work try to add it here first, and then Restart (right click again and restart through the interface.) then get it back to the correct permissions.. Restart again in the same way.
I hope it helps it solve most of the bugs for me in that subject..

WCF Threading current owner

I hosting a WCF service on Windows 7 IIS. When the service is trying to write to a config file and getting the error:
"Access to the path 'C:\Program Files (x86)\MIMS\Master\ahug_uqt.tmp' is denied."
This is not the name of the config file although I assume ConfigurationManager is creating a temp file then updating this to the real config file.
Anyway, I have checked that neil-laptop (that's my user), ASPNET, NETWORKSERVICE and LOCALSERVICE have full control over the programs folder and they do. When debugging into the service it shows the current thread principal as neil-laptop. This should not be the case as it is an IIS process.
So, how can I see which user the thread is running under so that I can give this the appropriate permissions. Bearing in mind also that the above worked on Win2003 and XP when I gave the users full control to the folder. Darn you Windows 7.
Hopefully,
Neil.
I modified the user that the IIS App Pool is running under to use the NETWORK SERVICE account and gave this account permissions to the appropriate folder.
Simple really. Not sure about security implications for this but the NETWORK SERVICE account is very limited in it's permissions so should be fine.

Programmatically Creating a IIS6 Website/App Pool in Nant

I'm relatively new to Nant, what i'd like to do is have a task that creates a new Website and AppPool in IIS6
is there a way to do this in Nant?
Essentially the task would need to set all the appropriate properties including the correct version of the .net Framework
Ideally i'd also like to check if the site is already present in IIS.
Have you looked at NantContrib? It might provide some better IIS support without having to write your own task (or shelling out).
It has some IIS specific tasks like iisapppool and mkiisdir.
You can do this from the command line using ADSUTIL, you can find more information here:
http://blogs.msdn.com/david.wang/archive/2007/12/12/howto-create-custom-application-pool-by-commandline.aspx
To do this in Nant you can use the exec task.
How are you planning on deploying your application? Do you need this just for local installation? There may be a better solution if you can give us some more details.