FormsAuthentication.RedirectFromLoginPage is not redirecting to the correct page.

J

Jeremy Chapman

I have built a web app. While testing I have found that if I browse to a
page in the app, then get redirected to the login page and enter my
credentials. The FormsAuthentication.RedirectFromLoginPage call is
redirecting to the default.aspx page rather than the original page the user
was at.

Here is the details of my application:

Web.config:
<authentication mode="Forms">
<forms name="Login.APSXAUTH"
loginUrl="login.aspx"
timeout="20"
protection="All"
path="/"/>
</authentication>

In each page of my application (with the exception of the login.aspx)
checks a variable in the Session. If the value is null, then a call to
Response.Redirect("login.aspx",false) is done.

When inspecting Request object in the page load of login.aspx when the
redirect first takes place, I can see that the URLReferrer is correct.

I then enter my credentials in the login page, and click a submit button.
When inspecing the Request object in the submit button click event at this
point, the URLReferrer points to my default.aspx page, not the page that
originally redirected me to the login.aspx page. As well, if I make a call
to FormsAuthentication.GetRedirectUrl, it returns the default.aspx. Making a
call to FormsAuthentication.RedirectFromLoginPage(username, false) redirects
me to the default.aspx and not the original page I was browsing. Is there
some additional things I need to do to determine the correct page to
redirect to?
 
A

ajamrozek

I handle this kind of functionality in a Session variable
(Page.Session("ReturnURL")). I set this value to the
Request.URL.ToString() in the header.ascx control that's placed on all
my pages. If this Session variable = Nothing when I exec the login
procedure, then I redirect to the default page, otherwise I redirect
to the URL stored in the Session variable. There's some other code in
there to disregard the login page as a RedirectURL and some other
functionality that was needed but not necessarily pertinent to this
case.
HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top