Where do I type in the redirect code for authentication?

bobbellows
bobbellows used Ask the Experts™
on
I am somewhat new to asp.net and aspx. I think I understand the code. However, I used asp.net configuration tool in VS 2008. I don't know where to write the code to override the redirect. Can you help me?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
Are you using asp.net built-in Login Control?
Then you can do redirect in LoggedIn event of Login control.
OR please share your login page code (markup and code-behind).
Greg GambleProgrammer

Commented:
Try this in the web.config
<system.web>
   <authentication mode="Forms">
      <forms loginUrl="logon.aspx" name=".ASPXFORMSAUTH">
      </forms>
   </authentication>
</system.web>

Open in new window

Author

Commented:
Thanik you all for responding. My day job has me working overtime right now so I couldn't get back to my project or you guys right away. Thank you for your patience.

First of all I related this question with question  ID: 21459415. That's the code I was referring to. What I'm tryiing to accomplish I believe is very simple. When someone times out and requestss a page they are sent to login again. After they submit their credentials they are taken to their requested page.  Instead of them going to their requested page I would rather send them to a page I choose. Basically I'm hijacking their redirect.

GURU SAMI:

I did use the Login Controlof VS 2008. Attached is the code you requested.  Also attached is the recommended code from the original question.
Markup:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
    <link href="StyleSheets/FormStyles.css" rel="stylesheet" type="text/css" />
    <link href="StyleSheets/GeneralStyles.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <asp:Login ID="Login1" runat="server" 
        DestinationPageUrl="~/Teachers/LoginStep2.aspx" ForeColor="Yellow">
        <CheckBoxStyle Font-Bold="False" Font-Names="Verdana" ForeColor="Aqua" />
        <TextBoxStyle BackColor="#F1ECD8" BorderColor="Red" BorderStyle="Groove" 
            BorderWidth="3px" Font-Names="Verdana" Font-Size="Medium" ForeColor="#5D034D" />
        <LoginButtonStyle BackColor="#F1ECD8" Font-Names="Verdana" 
            ForeColor="#5D034D" />
        <LabelStyle Font-Names="Verdana" Font-Size="Medium" ForeColor="Lime" />
        <FailureTextStyle BackColor="Yellow" Font-Names="Verdana" />
        <TitleTextStyle Font-Bold="True" Font-Names="Verdana" Font-Size="Large" 
            ForeColor="Lime" />
    </asp:Login>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p class="LargeTextLime">
        &nbsp;</p>
    <p class="LargeTextLime">
        User Login</p>
</asp:Content>
*********************
Code Behind:


Partial Class login
    Inherits System.Web.UI.Page

End Class
************
Code from related question:

Step 1 
SetAuthCookie :-

'Validate User Login Information first
'If the user login information is valid
SetAuthCookie(strUserName,true)
Response.Redirect("MyPage.aspx")

Step 2
Listing defaultURL in web.config :-

<authentication mode="Forms">   
    <forms loginUrl="member_login.aspx" defaultUrl="index.aspx" />
</authentication>

Open in new window

Top Expert 2013
Commented:
If you used asp.net configuration Tool i.e. you are using asp.net membership provider + asp.net Login Control then then
1: Ideally there is no need to set the cookie explicitly. It is done for your automatically if user validation succeeds.
2: As said earlier use LoggedIn event to redirect.

.aspx.vb

 Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As EventArgs) Handles Login1.LoggedIn
        'do redirect wherever you want based
        'e.g. if you want to redirect to defaultUrl set in web.config you can use like below
         Response.Redirect(FormsAuthentication.DefaultUrl)
    End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial