Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logging-in Redirection to wrong form

Status
Not open for further replies.

iaswnidou

Programmer
Apr 19, 2005
140
0
0
GR
Hello

I'm working on a asp.net 2.0 website that uses forms authentication. In the login.aspx there is the following code that takes you to default.aspx

Code:
<asp:Login ID="Login1" runat="server" RememberMeSet="false" LoginButtonType="Link" TitleText="Login to the Ethic referal page" CssClass="dropShadowPanel" Width="100%">
                                    <LayoutTemplate>
                                        <table border="0" cellpadding="1" cellspacing="0" style="border-collapse: collapse">
                                            <tr>
                                                <td>
                                                    <table>
                                                        <tr><td colspan="3" style="height: 30px">&nbsp;</td></tr>
                                                        <tr>
                                                            <td align="right" style="padding-left: 60px;">User Name:&nbsp;</td>
                                                            <td><asp:TextBox ID="UserName" runat="server" Width="200px" MaxLength="50"></asp:TextBox>&nbsp;<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                                                                    ErrorMessage="*" ToolTip="User Name is required." ValidationGroup="Login1" Font-Size="Medium"></asp:RequiredFieldValidator></td>
                                                            <td>&nbsp;(your email)</td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;</td>
                                                            <td colspan="2"><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Username is not in the correct format." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="Login1" ControlToValidate="UserName"></asp:RegularExpressionValidator></td>
                                                        </tr>
                                                        <tr>
                                                            <td align="right">
                                                                <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:&nbsp;</asp:Label></td>
                                                            <td colspan="2">
                                                                <asp:TextBox ID="Password" runat="server" width="200" TextMode="Password" MaxLength="50"></asp:TextBox>
                                                                <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                                                    ErrorMessage="*" ToolTip="Password is required." ValidationGroup="Login1" Font-Size="Medium"></asp:RequiredFieldValidator>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="center" colspan="3" style="color: red">
                                                                <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;</td>
                                                            <td align="right"><asp:CheckBox ID="RememberMe" runat="server" TextAlign="Left" Text="Remember me next time?" /></td>
                                                        </tr>
                                                        <tr height="25px">                                                            
                                                            <td align="right" colspan="2">
                                                                <div style="height: 15px; margin-right: 5px; width: 70px; background-color: #4168b3; vertical-align: middle; text-align: center; font: bold 11px Arial;">
                                                                    <asp:LinkButton ForeColor="#ccd7e9" ID="LoginLinkButton" runat="server" CommandName="Login" ValidationGroup="Login1">Log In</asp:LinkButton>
                                                                </div>                                                               
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                        <td colspan="3" style="text-align: center;">
                                                        If you have not registered click&nbsp;
                                                        <asp:LinkButton id="lbRegister" Font-Underline="true" runat="server" CausesValidation="false" OnClick="lbRegister_Click">here</asp:LinkButton>
                                                        &nbsp;to sign up.
                                                        </td>
                                                        </tr>
                                                        <tr><td>&nbsp;</td></tr>
                                                        <tr>
                                                        <td colspan="3" style="text-align: center;">
                                                        <a onclick="javascript:window.open('ResetPassword.aspx',null, 'height=180,width=400,status=yes,toolbar=no,menubar=no,location=no');" target="_blank" style="text-decoration: underline; cursor:hand">Forgot your password?</a>
                                                        </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </LayoutTemplate>
                                </asp:Login>

Once in default.aspx, through a menu control (that is on a master page) you can navigate to, let's say, page B. If I log out from page B and log back in, then i'm taken to page B directly and not to default.aspx.

Can you explain this behavior?

Thanks
 
Where exactly you mean? On logging out?

this is the log out button method

Code:
protected void lbLogOut_Click(object sender, EventArgs e)
{
   Session.RemoveAll();
   FormsAuthentication.SignOut();
   FormsAuthentication.RedirectToLoginPage();
}
 
I thought it's something wrong with the web.config..
 
Basically this happens to any page i redirect through the menu. After I log out it remembers the last page i visited.
 
Is there a URL somewhere?

I don't know how it redirects from the login to default. I thought it's something default that the membership provider does.
 
Oh sorry that's what you meant!

Yes there is actually

Code:
ReturnUrl=%2fEthicAdmin%2fSignUpClient.aspx

how do you get rid of it?
 
You could hard-code a redirect e.g.
Code:
Protected Sub Login1_LoggedIn (ByVal sender As Object, ByVal e As System.EventArgs)
  Response.Redirect("default.aspx")
End Sub


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thanks a lot. It works.

If someday you think of a more elegant solution, like declaratively through the web.config, please post back.

Have a good day.
 
The ReturnURL parameter is built into the authentication framework, so I don't think you can simply disable it (i.e. from the web.config file). There will be methods you can use to strip it off the URL, but I think the method I mentioned above is the easiest solution.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
As a side note, I notice that although you have asked 27 questions in the ASP.NET forum, you haven't marked any of the answers as valuable, and I can only see one or two acknowledgements of other peoples responses. If you are not getting the answers that you need read FAQ222-2244 to see how to ask better questions. If you are getting the answers you need see FAQ222-2244 to see how to acknowledge the answers given.

Paragraph 16 of the FAQ explains about this being a two-way forum, to give guidance on answering other peoples questions, as I also notice that you haven't yet made any posts in other peoples threads.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top