views:

636

answers:

1

I have a website, with basic Forms Authentication working alright. Users have emails that contain links to my site, with a querystring variable. Users are prompted to login correctly, but using

FormsAuthentication.RedirectFromLoginPage(userName, false);

Does not work when the original url contains a querystring.

I've tried these requests, without being logged:

http://localhost/default.aspx          -- redirect to login, then back to default OK
    This is the loaded URL before login:
    http://localhost/login.aspx

http://localhost/TaskDetail.aspx       -- redirect to login, then back to default FAIL
    This is the loaded URL before login:
    http://localhost/login.aspx?ReturnUrl=%2ftaskdetail.aspx

http://localhost/TaskDetail.aspx?id=5  -- redirect to login, then back to default FAIL
    This is the loaded URL before login:
    http://localhost/login.aspx?ReturnUrl=%2fTaskDetail.aspx%3fTaskID%3d2464&TaskID=2464

Any help is really appreciated.

+1  A: 

unfortunately, this is by design but here is a great article on this very issue that describes it, plus a workaround:

http://blogs.msdn.com/vijaysk/archive/2008/01/24/anatomy-of-forms-authentication-return-url.aspx

EDIT: My apologies, I thought there was a workaround in that blog the first time I read it. Try doing this a Response.Redirect to FormsAuthentication.GetRedirectURL() and adding in the correct querystring.

Russ Bradberry
Thanks for the response. I see how this functionallity is constructed; however, I am not able to find the workaround you mention in that link.
Nate Bross
i made an edit to my post, adding in a possible workaround.
Russ Bradberry
I've tried this `Response.Redirect(FormsAuthentication.GetRedirectUrl(uid.Text,false), false);` and I'm having no luck, it does redirect, but I simply endup at the login page again. Any thoughts?
Nate Bross
I've also tried with different combos of true/false for persistent ticket and end resposne, etc.
Nate Bross
before you redirect, you need to add the auth cookie. take a look at the way it is done here: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.getredirecturl.aspx
Russ Bradberry
Excellent, that is exactly what I needed. I assued the `GetRedirectUrl` set the auth cookie, just like `RedirectFromLogin`... Thanks a bunch!
Nate Bross