Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

RemoveClaim

You should use identity to add or remove a claim. Try this to add a claim.

var user = User as ClaimsPrincipal;
var identity = user.Identity as ClaimsIdentity;
identity.AddClaim(new Claim(ClaimTypes.Role, "somenewrole"));
To remove a claim,

var user = User as ClaimsPrincipal;
var identity = user.Identity as ClaimsIdentity;
var claim = (from c in user.Claims
                         where c.Value == "somenewrole"
                         select c).Single();
identity.RemoveClaim(claim);
BTW, it is better to use User from your controller instead of HttpContext.Current.User.
Comment

PREVIOUS NEXT
Code Example
Csharp :: Delete last modification on EntityFramework Core 
Csharp :: ip validation .net core 
Csharp :: how to add multiple values in session in asp.net visual studio 
Csharp :: c# psobject get value 
Csharp :: pyqt single instance 
Csharp :: identity-1.us-south.iam.test.cloud.ibm.com:443 
Csharp :: panning script c# on phone 
Csharp :: c# webbrowser control append 
Csharp :: Conditional IQueryable Linq extension 
Csharp :: add integer to string c# 
Csharp :: constructor in protobuf-net 
Csharp :: how to get connection string from xml file in c# 
Csharp :: how to create new function c# 
Csharp :: how to use javascriptexecutor for loop in selenium c# 
Csharp :: FileSystemEventHandler raised twice 
Csharp :: unity async await 
Csharp :: unity int to bool 
Csharp :: c# datagridview filter 
Csharp :: protected override void OnExiting(Object sender, EventArgs args) { base.OnExiting(sender, args); Environment.Exit(Environment.ExitCode); } 
Csharp :: build a project from dotnet using cli 
Csharp :: c# windows forms function after load 
Csharp :: Unity inverse kinematics nothing is happening 
Csharp :: _swapbatch.foreach multiple statements c# 
Html :: html rupee symbol 
Html :: how to center html element in bootstrap 5 
Html :: flutter build web release html renderer 
Html :: meta no cache 
Html :: bootstrap col-md-5 center 
Html :: adding a favicon in html 
Html :: Wrap the last word of a paragraph in span tags using jQuery 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =