C# Forms Authentication with Redirect Help Needed
Posted on 2006-07-17
I've been using Forms authentication for a little while, but need help figuring out how to modify my web.config file to accomplish a redirect with variable information.
Here's my current web.config (pretty standard) regarding forms authentication:
<forms loginUrl="./login.aspx" timeout="30" slidingExpiration="true" />
<deny users="?" /> <!-- Deny Non-Logged In users -->
If a User has a bookmark or receives a link to my site in an email and thereby reaches an .aspx page when they are in a logged-out state, I DO want them to be bounced to login.aspx. BUT, I want to pass along the URL they were attempting to reach in the QueryString, so that if they subsequently successfully log in I can redirect them to the page they were attempting to reach in the first place.
If it were possible, I'd be creating a tag in web.config that looked like:
int numURLsegs = Convert.ToInt32( Request.Url.Segments.Length.ToString() );
string theQS = Request.Url.Query.ToString();
theLoginURL = "./login.aspx?o=" + Request.Url.Segments[ ( numURLsegs - 1 ) ].ToString().Trim() + theQS.ToString().Trim();
<forms loginUrl="<%=theLoginURL%>" timeout="30" slidingExpiration="true" />
I know it's not likely that C# can be in web.config, but I'm hoping there's a way to pass the referrer somehow.
If it's not possible to use standard Forms authentication to do this, any suggestion would be appreciated.