Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

How would I make a static class in ASP.NET webforms that redirects the User to a specific page if member is not active? (c#)

I can't figure out how to turn the following code into a static class for use in all my pages.

var valDRecord = oe.account_profiles.Where(y => y.membership_number == User.Identity.Name).First();
if (valDRecord.active == false)
        {
            Response.Redirect("profileUpdate.aspx");
        }

Open in new window


This is the code in my class:
Can't figure out how to get the user.Identity.Name to work.
public class notActive
{
   public static void redirect()
    {
        AMEMEntities2 h = new AMEMEntities2();

        var valDRecord = h.account_profiles.Where(y => y.membership_number == User.Identity.Name).First();
        if (valDRecord.active == false)
        {
           HttpContext.Current.Response.Redirect("profileUpdate.aspx");
        }

    }

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

"Can't figure out how to get the user.Identity.Name to work."
Is the value coming back as blank?  What authentication are you working with?  If you are using Forms Authentication, you would need a different approach.
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bmanmike39
bmanmike39

ASKER

Thanks!

Just what I was looking for.