Solved

C# Forms Authentication with Redirect Help Needed

Posted on 2006-07-17
2
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17122590
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
ID: 17122615
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 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