james2code
james2code

Reputation: 894

cs-username not showing in IIS logs in IIS7 classic mode

I am running an asp.net application with forms authentication on IIS 7 in classic mode. Logging is turned on and the cs-username field is currently selected to be logged. However, the cs-username is always blank in the logs. Anyone have tips on how to determine the cause?

Upvotes: 3

Views: 6306

Answers (4)

Matt Watson
Matt Watson

Reputation: 1010

You can do the following and it will get set in theIIS logs cs-username.

public WebApiApplication()
{
    this.AuthenticateRequest += WebApiApplication_AuthenticateRequest;
}

void WebApiApplication_AuthenticateRequest(object sender, EventArgs e)
{
    HttpContext.Current.User = new GenericPrincipal(new GenericIdentity("SET THE USER INFO HERE"), null);
}

Upvotes: 0

Alvaro Pereira
Alvaro Pereira

Reputation: 1

I think that you have to save the asp.net LOGGIN in a HEADER variable and use na ISAPI filter to get this information and save on the IIS_LOG.

Upvotes: 0

tobint
tobint

Reputation: 1719

What Bryan says is true. In Classic mode, you go through double authentication processes. That is, IIS authenticates you first, and then ASP.NET authenticates you. In classic mode, the IIS Authentication is likely set to anonymous, in which case, IIS will log nothing in that field. If you turn on integrated pipeline, the authentication happens only once -- and within the IIS pipeline. That means that IIS can write data to the cs-username field.

Upvotes: 1

Bryan
Bryan

Reputation: 8788

cs-username knows nothing about ASP.NET / forms authentication, and vice-versa... You have Anonymous access turned on in IIS, yes? That's why there is no cs-username output.

Upvotes: 5

Related Questions