By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,079 Members | 916 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,079 IT Pros & Developers. It's quick & easy.

Impersonation generates "Invalid Cast" error

P: n/a
Hello:

When I try to access a SQL server or a network share from an ASP.Net
application that I run on my computer, I run into security problems (for
instance, I cannot execute DTS package using Trusted connection or get a
file information using FileInfo class). This is probably because my
application is running under PETER\ASPNET account, where PETER is my
computer's name. I can solve this problem by using Impersonation.

However, when I specify Impersonation in Web.config, it usually creates some
problems when I move my application to the server. So I prefer to
impersonate my application programmatically and then cancel it:

Dim impersonationContext As
System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
.................................................. ...........................
......................

impersonationContext.Undo()

Ususally this works OK, but this time the line

currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)

is producing an "Invalid Cast" error. I've noticed that User.Identity is
actually an empty string.

What could be wrong? Is there another way to solve these security issues
besides using Impersonation? I cannot add PETER\ASPNET account to the SQL
server or to the network share permissions.

I would greatly appreciate your suggestions.

Thank you,

--
Peter Afonin
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.