Impersonation generates "Invalid Cast" error

Discussion in 'ASP .Net' started by Peter Afonin, Aug 30, 2003.

  1. Peter Afonin

    Peter Afonin Guest

    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.WindowsImpersonationContext
    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
     
    Peter Afonin, Aug 30, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TPS
    Replies:
    2
    Views:
    510
    MS News \(MS ILM\)
    Aug 15, 2003
  2. VB Programmer

    Question: Invalid Cast Exception Error

    VB Programmer, Oct 28, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,371
    VB Programmer
    Oct 28, 2003
  3. Glenn Robinson

    Invalid cast type error

    Glenn Robinson, Aug 26, 2004, in forum: Java
    Replies:
    20
    Views:
    5,099
    Glenn Robinson
    Aug 29, 2004
  4. =?Utf-8?B?YW1qYWQ=?=

    urgent asp.net invalid cast error

    =?Utf-8?B?YW1qYWQ=?=, Jun 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    519
    Winista
    Jun 7, 2006
  5. Dave Moore

    <asp:Image control giving an invalid cast specified error

    Dave Moore, Dec 14, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    183
    Dave Moore
    Dec 14, 2003
Loading...

Share This Page