buunguyen / combres

ASP.NET and MVC performance optimization library ⛺
Other
123 stars 37 forks source link

Resources with mode Dynamic requiring authentication causes problems. #2

Closed mvestergaard closed 11 years ago

mvestergaard commented 11 years ago

We use combres in our application which is mostly meant for intranet purposes. This means that the site in most cases requires authentication.

Some of the resources we use are dynamic. When combres tries to load these it causes a 401 authentication error. As far as i can tell this is because combres will request the resource using a WebClient, however this web client does not use the credentials of the user logged onto the site, and therefore does not have access.

Would it be possible to set the WebClient.UseDefaultCredentials property to true? This should cause the WebClient to use the same credentials as the current request when using impersonation.

Perhaps make it an extra setting that can be setup per resource.

mvestergaard commented 11 years ago

I've forked the project and made changes that I think will fix the problem. I'll create a pull request once I've been able to validate.

https://github.com/mvestergaard/combres/commit/3c0b236e3fecdab75a7470be0d5133374eba799b

mvestergaard commented 11 years ago

UseDefaultCredentials did not solve the problem. For now I'll go back to loading the dynamic resources without combres, and just rely on browser caching to prevent too many extra requests.

buunguyen commented 11 years ago

Have you tried adding the auth type? See this post: http://stackoverflow.com/questions/1680718/domain-credentials-for-a-webclient-class-dont-work.

CredentialCache cc = new CredentialCache();
cc.Add(
    new Uri("http://intranet/"), 
    "NTLM", 
    new NetworkCredential("username", "pass", "domain")); // also try with CredentialCache.DefaultCredentials
client.Credentials = cc;