Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET 2.0 RedirectFromLoginPage

Posted on 2008-10-06
4
Medium Priority
?
625 Views
Last Modified: 2012-05-05
Hi,

I cannot seem to resolve an issue with this command.

If I attempt to access a page from the web site without first logging in, it sends me to the login page (so far so good).

However, after entering my credentials I do NOT get redirected to the originally requested page.

I have thus far not been able to find a solution so your help would be appreciated.

My setup...

I have a Custom login operation.

Then i am simply executing:

    FormsAuthentication.RedirectFromLoginPage("test", False)

I have also tried:

    FormsAuthentication.SetAuthCookie(txb_User.Text, False)
    FormsAuthentication.RedirectFromLoginPage(txb_User.Text, False)

Web.Config section:

    <authentication mode="Forms">
       <forms name=".iMedia" loginUrl="index.aspx" defaultUrl="main.aspx"  timeout="59" protection="All" path="/" slidingExpiration="False"/>
    </authentication>thanks.
   
0
Comment
Question by:Ramesh Srinivas
[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
4 Comments
 

Expert Comment

by:Mippes
ID: 22648445
Hi
in an web application written in ASP.NET 1.1 (Studio 2003) I used Forms Authentication
without an database, but with an login page and I got always redirected to the originally
requested page.
I hope my example will help you successful

Juergen
Web.config
==========
<authentication mode="Forms">
        <forms name=".ASPXAUTH" path="/" protection="All" timeout="20">
	    <credentials passwordFormat="SHA1">
	        <user name="admin" password=""/>
	        <user name="guest" password=""/>
	    </credentials>
        </forms>
</authentication>
 
Login.aspx
==========
<form id="Form1" method="post" runat="server">
	<H3 align="center">PC-Administration Login</H3>
	<P align="center">Please enter a user name and a password</P>
	<P align="center">Username: guest</P>	'You can only read contents
	<P align="center">Password: guest</P>
	<br>
	<br>
	<TABLE id="Table1" style="POSITION: absolute; TOP: 300px" cellSpacing="1" cellPadding="1" width="100%" border="0">
		<TR>
		    <TD>&nbsp;</TD>
		    <TD>Username</TD>
		    <TD><asp:textbox id="TxtUserName" runat="server" EnableViewState="true"></asp:textbox></TD>
		    <TD width="50%"><asp:requiredfieldvalidator id="ReqFieldValUser" runat="server" Display="Dynamic" EnableClientScript="False"
				     ControlToValidate="TxtUserName" ErrorMessage="Username necessarily" ForeColor="red"></asp:requiredfieldvalidator></TD>
		</TR>
		<TR>
		     <TD>&nbsp;</TD>
		     <TD>Password</TD>
		     <TD><asp:textbox id="TxtPassword" runat="server" TextMode="Password"></asp:textbox></TD>
		     <TD><asp:requiredfieldvalidator id="ReqFieldValPassword" runat="server" Display="Dynamic" EnableClientScript="False"
			  ControlToValidate="TxtPassword" ErrorMessage="Password necessarily" ForeColor="red"></asp:requiredfieldvalidator></TD>
		</TR>
		<TR>
		     <TD>&nbsp;</TD>
		</TR>
		<TR>
		     <TD>&nbsp;</TD>
		     <TD>&nbsp;</TD>
		     <TD align="center"><asp:button id="btnLogOn" runat="server" Text="Log In"></asp:button></TD>
		     <TD>&nbsp;</TD>
		</TR>
	</TABLE>
</form>
 
Login.aspx.vb
=============
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Page.RegisterStartupScript("doFocus", "<script>document.forms[0].elements[1].focus();</script>")
End Sub
 
Private Sub btnLogOn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogOn.Click
    If FormsAuthentication.Authenticate(txtUserName.Text, txtPassword.Text) Then
         FormsAuthentication.SetAuthCookie(TxtUserName.Text, False)
         Response.Redirect("Default.aspx")
    Else
         btnLogOn.Text = "Login invalid"
    End If
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:Ramesh Srinivas
ID: 22648475
Hi,

Thanks for your post however I am using 2.0 and my own login method (i query a database for user and password).

Also, your example does not look like it will redirect to the originally requested page (i.e. a page that requires authentication).

Your example will always redirect to Default.aspx.

thanks.
0
 

Expert Comment

by:Mippes
ID: 22648572
Hi,
it redirect to Default.aspx (Startpage from the webapplication) only if the login was successful !
Otherwise you stay always on Login.aspx.
0
 
LVL 11

Accepted Solution

by:
Ramesh Srinivas earned 0 total points
ID: 22648636
Yes, but thats not what I am looking for.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

715 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