Thursday, February 24, 2011

System.UnauthorizedAccessException: Access to the path is denied

During my recent deployment to a QA box, one of the functionalities "Upload File" of the web app would not work.

Here is what I had done. During development I observed that the file upload would work when I was running the app in Debug mode, from within Visual Studio. When I tried running the app from virtual directory (as in http://localhost/MyApp/Upload.aspx) the file upload would fail with "Logon failure: unknown user name or bad password", about which I blogged a while ago. And hence I added the code to impersonate the current logged in user. And it worked fine.

However, the same impersonation code would not work when the app was deployed on the server. Another thing I should point out is, the file copy is happening on a server different from the app server. When I commented out the impersonation code, it started working. I am still not sure why it so happened.


Windows authentication for an NT group

Recently I implemented authentication system where the logged in user has to be part of the company domain (handled by IIS) and should belong to an app specific NT group. The code used was simple
foreach (System.Security.Principal.IdentityReference group in currentContext.Request.LogonUserIdentity.Groups)
{
groupName = group.Translate(typeof(System.Security.Principal.NTAccount)).ToString();
if (groupName.Equals(userGroup, StringComparison.InvariantCultureIgnoreCase))
{
userIsInGroup = true;
break;
}
}

It worked fine on development machine, but would redirect me to access denied page on the QA server.

After logging the current context user in app (during security check) I found the web app was running under the admin account. And the admin account was not part of my app NT group. The reason this was happening was because Windows explorer cached the admin account credentials, that I use for copying the published files on the server.

To clear the cache, I had to run the following from command prompt:
rundll32.exe keymgr.dll, KRShowKeyMgr
This brings up a UI that has all the server names for which Windows explorer has cached the credentials. Select the server and click on "Remove" and that should do the trick.

Thursday, February 3, 2011

Multiple group headers in BOXI Crystal reports

Yesterday I just found an interesting issue with Crystal Reports XI.
We had a report where in we had to place 5 group headers. After applying all the options what we observed was that the group headers would appear multiple times whenever the group values changed. Searched a lot for answers but to no avail. We're working on it and I'll post the solution as well once we get it.
Workaround::
The solution to this kind of issue is that we should put the different grouping fields in different group header and suppress those groups. Whatever values are to be shown on the report needs to go in the last group header whose corresponding Group Footer has the New Page After property set. This resolves the issue.