简体   繁体   English

错误 CS0103:当前上下文中不存在名称“IsInRole”

[英]ERROR CS0103: The name 'IsInRole' does not exist in the current context

I have this line into my web service project.我在我的 Web 服务项目中加入了这一行。 This is supposed to check if the current principal has the role of Viewer.这应该检查当前主体是否具有查看者的角色。

CODE代码

System.Threading.Thread.CurrentPrincipal.IsInRole("Viewer")

This throws an error like IsInRole("Viewer") is not into context.这会引发错误,例如 IsInRole("Viewer") is not into context。 Please help what to write here.请帮助在这里写什么。

Out of context typically means you have code where it shouldn't be, or attempting to access a variable that is not within scope.脱离上下文通常意味着您有不应该出现的代码,或者试图访问不在范围内的变量。 See screenshot below for an example of code statement in wrong place semantically.有关语义错误位置的代码语句示例,请参见下面的屏幕截图。

Another example is declaring a variable in a try block and trying to access it from the catch block.另一个例子是在 try 块中声明一个变量并尝试从 catch 块访问它。 The curly braces in C# define scope, the try and catch scopes are separate therefore, variables declared in the try block are not accessible from the catch block. C# 中的花括号定义作用域,try 和 catch 作用域是分开的,因此在 try 块中声明的变量不能从 catch 块访问。

断章取义截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 CS0103:当前上下文中不存在名称“_context” - Error CS0103: The name '_context' does not exist in the current context 错误 CS0103:当前上下文中不存在名称“currentScreen”(CS0103) - Error CS0103: The name 'currentScreen' does not exist in the current context (CS0103) 错误CS0103:名称“ TimeSpan”在当前上下文(CS0103)(testingProgram)中不存在? - Error CS0103: The name 'TimeSpan' does not exist in the current context (CS0103) (testingProgram)? 错误cs0103名称'IEnumerator'在当前上下文中不存在 - error cs0103 The Name 'IEnumerator' does not exist in the current context 错误CS0103:名称“ HttpUtility”在当前上下文中不存在 - error CS0103: The name `HttpUtility' does not exist in the current context "错误 CS0103:当前上下文中不存在名称“AssetPreview”" - error CS0103: The name 'AssetPreview' does not exist in the current context 错误CS0103当前上下文中不存在名称“图像” - Error CS0103 The name 'Image' does not exist in the current context Unity错误CS0103:当前上下文中不存在名称`' - Unity error CS0103: The name `' does not exist in the current context 错误 CS0103: 当前上下文中不存在名称“ ” - error CS0103: The name ' ' does not exist in the current context 错误 CS0103:当前上下文中不存在名称“x” - error CS0103: The name 'x' does not exist in the current context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM