Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the issue with User.Identity.Name

What namespace is it from, cause it shows me that User doesnt exist in the current context!

Here are my list of namespaces. Which one should i add:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using System.Web.Security;

Another question, is that the way to check that the person who logged in is an administrator?

 if (Roles.IsUserInRole(User.Identity.Name, "Administrators"))
      {
like image 425
Dmitry Makovetskiyd Avatar asked Nov 20 '25 08:11

Dmitry Makovetskiyd


2 Answers

If you are in a code library rather than the web page itself you need:

HttpContext.Current.User
like image 88
Rozwel Avatar answered Nov 22 '25 00:11

Rozwel


You need the following namespace:

using System.Security.Principal;

The easiest way to check for roles is:

User.IsInRole("Administractor");
like image 36
lancscoder Avatar answered Nov 22 '25 00:11

lancscoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!