Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

ASP.NET 2.0 + Error + Roles

I am trying to implement a basic Roles class but get the following error, but have no idea what it means, can someone please help

--------------------------------------------------------------------------------

Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'SitePrincipal'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'SitePrincipal'.

Source Error:


Line 17:         {
Line 18:
Line 19:             if (!((SitePrincipal)Context.User).IsInRole("Site Admin"))
Line 20:                 Response.Redirect("../Login.aspx");
Line 21:
 
Thanks
0
dkilby
Asked:
dkilby
1 Solution
 
OblivionSYCommented:
If you are using Roles and Forms authentication, you can set the permission in the web.config file. It will automatically direct users to the login page if they are not members of the specified role.

However, if you want to do it this way, off the top of my head, try just typing it as

IPrinciple

or use

HttpContext.Current.User.IsInRole("Site Admin")

is SitePrincipal your own implementation?
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now