Link to home
Start Free TrialLog in
Avatar of Michael Sterling
Michael SterlingFlag for United States of America

asked on

How do I add querystring parameters and values in my Authenticate routine?

I'm using a login control in my ASP .NET 3.5 [C#] web application and i'm wanting to add some information to the url that it gets redirected to once the user authenticates. How do I do this? See the code snippet below...
//so once a user clicks the login button my 
//"onauthenticate" routine looks like this:
protected void myLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
     if ( Membership.ValidateUser(myLogin.UserName, myLogin.Password))
     {
          //HERE IS WHERE I THINK I NEED TO ADD INFO
          //TO MY URL STRING SO THE REDIRECTED URL 
          //WILL CONTAIN QUERY STRING PARAMETERS AND
          //VALUES BUT HOW DO I DO IT?
          e.Authenticate = true;
     }
}

Open in new window

SOLUTION
Avatar of sindhuxyz
sindhuxyz

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 Michael Sterling

ASKER

ok...so,...in my routine above what exactly to i do to get the page that the user was intending to go to, so that i can tack on the other piece of the url string to it to do the redirect? all attempts that i've made and appending to that string have failed. I think there is a "ReturnUrl" property that is inherit, within that routine. when ever i try to grab that property, and try to concatenate strings to it it never redirects properly or at all...
Avatar of sindhuxyz
sindhuxyz

I am not clear what you are trying, you have already authenticated user and you can put parameters in url which can be used on page.
so what i'm trying to do, is, in the example above you state i can simply do this:

Respons.Redirect("www.yourdomain.com/page.aspx?info1=abc&info2=123")

the part of it that confuses me is this: www.yourdomain.com/page.aspx

in my code sample below, i keep getting redirected back to the login page with this:

http://localhost/Login.aspx?ReturnUrl=%2fAddEditStudent.aspx%3fAccessLevel%3dQUSuperMan&AccessLevel=QUSuperMan

in the url...
redir = Request.QueryString["ReturnUrl"];
            string[] usersBelongingToRole = Roles.GetRolesForUser(myLogin.UserName);

            foreach (String s in usersBelongingToRole)
            {
                roles = String.Format(roles.ToString() + "{0}", s);
            }

            if (roles.IndexOf("QUSuperMan") != -1)
            {
                if (String.Compare(redir, "/AddEditStudent.aspx") == 0)
                    Response.Redirect("/AddEditStudent.aspx?AccessLevel=QUSuperMan");
            }
            else if (roles.IndexOf("QUCoach") != -1)
            {
                if (String.Compare(redir, "/AddEditStudent.aspx") == 0)
                    Response.Redirect("/AddEditStudent.aspx?AccessLevel=QUCoach");
            }
            else
            {
                if (String.Compare(redir, "/AddEditStudent.aspx") == 0)
                    Response.Redirect("/AddEditStudent.aspx?AccessLevel=QUStudent");
            }

Open in new window

ASKER CERTIFIED SOLUTION
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
still working on this...
thank you for you help