RedirectFromLoginPage not redirecting to RedirectUrl

J

jjjooooohhnnn

Greetings,

I have encountered what appears to be a fairly common problem:
RedirectFromLoginPage is not redirecting to RedirectUrl. I have tried
all the advice that I could on the 'net, and nothing has worked yet. My
problem is very simple. I want to redirect from a login page to the
default page in one application. I am not crossing over to other
applications in other directories on the server.

Here is a description of the problem:
- Go to http://localhost/App1. From here, you are redirected to
http://localhost/App1/login.aspx. The Address bar says
http://localhost/App1/login.aspx?ReturnUrl=/NutritionFacts/default.aspx

- Enter a username and a password. Click Login.

- You remain at the page http://localhost/App1/login.aspx. However, the
Address bar now reads http://localhost/App1/default.aspx.


I am unable to get the application to redirect to default.aspx after
successfully logging in. After logging in, if I try to manually go to
default.aspx, I am redirected to login.aspx.


Here are the details of my situation:
- I am running Microsoft Visual C# .NET (Microsoft Visual Development
Environment 2003) on XP, using IIS 5.1.

- I have an application named 'App1' located at
c:\inetpub\wwwroot\App1.

- Inside c:\inetpub\wwwroot\App1\ I have:
- default.aspx
- login.aspx

- Here is my web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Forms">
<forms name=".App1" loginUrl="login.aspx" protection="All"
path="/">
</forms>
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data
source=127.0.0.1;Trusted_Connection=yes" cookieless="false"
timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>

- Here are the critical contents of login.aspx:
<form id="LoginForm" method="post" runat="server">
<TABLE id="LoginTable" cellSpacing="0" cellPadding="4" border="0">
<TR>
<TD align="right"><STRONG>Email address:</STRONG></TD>
<TD width="2%"></TD>
<TD><asp:textbox id="EmailAddressTextBox" tabIndex="1"
runat="server" Columns="18" MaxLength="256"></asp:textbox></TD>
</TR>
<TR>
<TD align="right"><STRONG>Password</STRONG>:</TD>
<TD></TD>
<TD><asp:textbox id="PasswordTextBox" tabIndex="2" runat="server"
Columns="18" MaxLength="16" TextMode="Password"></asp:textbox></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD align="right"><asp:button id="LoginButton" tabIndex="4"
runat="server" Text="Login"></asp:button></TD>
</TR>
</TABLE>
</form>

- Here is the LoginButton method:
private void LoginButton_Click(object sender, System.EventArgs e)
{
if ( IsValid )
{
FormsAuthentication.RedirectFromLoginPage( "John", false );
}
}

- If I right-click and get the properties from Explorer for
c:\inetpub\wwwroot\App1\, under the Web Sharing tab, "Share this
folder" is selected and the alias listed is 'App1'.

- In IIS Manager, if I right-click on App1, under the 'Virtual
Directory' tab, 'App1' is the Application Name. Clicking the Directory
Security tab and then Edit for 'Anonymous access and authentication
control', the 'Anonymous access' checkbox is selected with an
appropriate IUSR_xxx user name.


That about somes up my current situation. I have spent several hours on
this and have no clue how to fix the problem. Any help is greatly
appreciated. Please let me know if you need any more information to
help diagnose the problem.

Thanks,

-=John
 
J

jjjooooohhnnn

I have tried debugging the situation and learned that authentication
does appear to be occuring. I put the following in my global.asax.cs:
protected void Application_AuthenticateRequest(Object sender,
EventArgs e)
{
HttpApplication theApp = (HttpApplication) sender;

if( theApp.Request.IsAuthenticated && theApp.User.Identity is
FormsIdentity )
{
FormsIdentity theIdentity = (FormsIdentity) theApp.User.Identity;
}

if(HttpContext.Current.User != null)
{
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
if(HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;

// get data stored in cookie
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new GenericPrincipal(id, roles);
}
}
}
}

Initially, the code inside the nested if statements does not execute.
After RedirectFromLoginPage is called and the page is reloaded, the
code inside the nested if statements does execute. So, it appears that
authentication is occuring.

-=John
 
J

jjjooooohhnnn

More info: I have tried both IE and Firefox. Both browsers encounter
the problem.

-=John
 
J

jjjooooohhnnn

More info: I have tried replacing localhost with the IP address of the
machine. Still experiencing the problem.

-=John
 
P

Patrick Olurotimi Ige

John in ur web.config:-
<forms name=".App1" loginUrl="login.aspx" protection="All"
path="/">
Is ur cookie name = .App1?
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top