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

x
?
Solved

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

Posted on 2011-10-05
7
Medium Priority
?
281 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:Michael Sterling
  • 4
  • 2
7 Comments
 
LVL 5

Assisted Solution

by:sindhuxyz
sindhuxyz earned 600 total points
ID: 36921281
you can add info in url like this

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

To get info back on page.aspx, use

dim s as string= response.querystring("info1")

0
 
LVL 1

Author Comment

by:Michael Sterling
ID: 36921363
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...
0
 
LVL 5

Expert Comment

by:sindhuxyz
ID: 36921447
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Michael Sterling
ID: 36921756
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

0
 
LVL 5

Accepted Solution

by:
LlamaJoe earned 1400 total points
ID: 36922465
all the membership provider does is set an authentication cookie on the client - it is made to allow you to send a link to any page that requires authentication, direct the user to the login page, then redirect back to the originally requested page.  
It looks like you've already figured out how to authenticate (Membership.ValidateUser()) - but you're missing the fun, crucial element - the validation is not complete until the cookie is set
FormsAuthentication.SetAuthCookie(userName.Text, false);
so the cookie has to be set, the page has to be submitted - so that the cookie is in the browser, then you can redirect to the page you want.

OR, take a look at the second example in step 4 in the link below regarding how to create the FormsAuthenticationTicket and set a redirect.
http://support.microsoft.com/kb/301240

0
 
LVL 1

Author Comment

by:Michael Sterling
ID: 36946457
still working on this...
0
 
LVL 1

Author Closing Comment

by:Michael Sterling
ID: 36967955
thank you for you help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question