简体   繁体   中英

Error during page redirection (asp.net)

When I try to make a page redirection according to role using below code, somehow it gave me an error said that "The name 'Roles' does not exist in the current context". I don't have any clue what is wrong with my coding. Please help. Thanks.

protected void Login1_LoggedIn(object sender, EventArgs e)
{
    {
        if (Roles.IsUserInRole(Login1.UserName, "Aemy"))
            Response.Redirect("~/Admin/Home.aspx");
        else if (Roles.IsUserInRole(Login1.UserName, "User"))
            Response.Redirect("~/Welcome/User1.aspx");
    }
}

Are you missing a using statement for System.Web.Security in that file? I'm assuming here that you're receiving the error at compile time.

Edited for clarity: The question here is, when do you get this error? If you're getting this error when you attempt to compile the project then it means it can't resolve "Roles" to the member of the System.Web.Security namespace which probably means that you're missing a "using System.Web.Security" statement near the top of your file. If you get this error at run time when someone attempts to login then you've hit on a much stranger exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM