Solved

C# Forms Authentication with Redirect Help Needed

Posted on 2006-07-17
2
267 Views
Last Modified: 2010-07-27
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:

<authentication mode="Forms">
      <forms loginUrl="./login.aspx" timeout="30"  slidingExpiration="true" />
</authentication>
<authorization>
        <deny users="?" /> <!-- Deny Non-Logged In users -->
</authorization>

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();

<authentication mode="Forms">
      <forms loginUrl="<%=theLoginURL%>" timeout="30"  slidingExpiration="true" />
</authentication>

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.

Thanks,
Andy


 
0
Comment
Question by:smooga
  • 2
2 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
The url should be passed already as part of the Forms mechanism. Check your querystring and there should be a key named URL with the original URL you targeted before being redirected to Login.aspx.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
You should be able to bounce the user back to the original URL using:

    FormsAuthentication.RedirectFromLoginPage("username", false);

You should be able to double-check the URL you originally targeted using:

    string url = FormsAuthentication.GetRedirectUrl("username", false);
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now