F# 无法在F中将IIIdentity转换为WindowsIdentity

F# 无法在F中将IIIdentity转换为WindowsIdentity,f#,F#,我有下面的C代码,它工作得很好 WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity; WindowsImpersonationContext ctx = winId.Impersonate(); ctx.Undo(); 但我试图用F来转换这段代码。我已经写了下面的代码 Let winId = HttpContext.Current.User.Identity :> WindowsIdenti

我有下面的C代码,它工作得很好

WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsImpersonationContext ctx = winId.Impersonate();
ctx.Undo();
但我试图用F来转换这段代码。我已经写了下面的代码

Let winId = HttpContext.Current.User.Identity :> WindowsIdentity //Showing error
Let ctx = winId.Impersonate()
ctx.Undo()

在上述代码中,HttpContext.Current.User.Identity无法在WindowsIdentity中强制转换。请让我知道我该怎么做

问题是,当您要使用向下投射:?>操作符时,您正在使用向上投射:>操作符。向上转换在编译时被检查,因为您总是可以知道是否可以向上转换继承层次结构,但是向下转换层次结构可能会失败,因此它有一个单独的操作符,在运行时可能会失败