M
Mark Olbert
I have an ASP.NET application that refuses to honor the RedirectFromLogin() method of
FormsAuthentication.
What happens is, when I try to access a restricted page, the login page gets brought up, I enter a
username and password, which are validated, and then the redirect gets called.
Unfortunately, the redirect lands me right back on the login page! And when I check
User.Identity.Name on that "failed redirect", the username is blank, as if it was never set. I have
cookies enabled in my browser, BTW.
I am wondering if there is some IIS configuration that needs to be done to allow formsauthentication
to work. This might explain why the code used to work and now doesn't, since it's running on a
different server.
Here is the code that USED TO work (before I moved development off of my local XP box and onto a
Win2K server on my intranet):
switch( secZone )
{
case SCEF_Browser.WebZone.Administrator:
// administrative rights
FormsAuthentication.RedirectFromLoginPage("user1", false);
break;
// other cases left out; the above one does get triggered when you walk through the debugger
}
// this next demonstrates that the correct redirect URL is in place
string crap = FormsAuthentication.GetRedirectUrl("user1", false);
Here are extracts from my Web.config file:
<configuration>
<system.web>
<!-- snip -->
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are
"Windows", "Forms",
"Passport" and "None"
-->
<authentication mode="Forms">
<forms name=".ASPAUTHSCEF" protection="None" loginUrl="ssl/login.aspx"
timeout="30" />
</authentication>
<authorization>
<allow users="?" />
</authorization>
<!-- snip -->
<!-- SESSION STATE SETTINGS
By default ASP .NET uses cookies to identify which requests belong to a particular
session.
If cookies are not available, a session can be tracked by adding a session identifier to
the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
</system.web>
<location path="ssl/members">
<system.web>
<authorization>
<allow users="user1" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>
FormsAuthentication.
What happens is, when I try to access a restricted page, the login page gets brought up, I enter a
username and password, which are validated, and then the redirect gets called.
Unfortunately, the redirect lands me right back on the login page! And when I check
User.Identity.Name on that "failed redirect", the username is blank, as if it was never set. I have
cookies enabled in my browser, BTW.
I am wondering if there is some IIS configuration that needs to be done to allow formsauthentication
to work. This might explain why the code used to work and now doesn't, since it's running on a
different server.
Here is the code that USED TO work (before I moved development off of my local XP box and onto a
Win2K server on my intranet):
switch( secZone )
{
case SCEF_Browser.WebZone.Administrator:
// administrative rights
FormsAuthentication.RedirectFromLoginPage("user1", false);
break;
// other cases left out; the above one does get triggered when you walk through the debugger
}
// this next demonstrates that the correct redirect URL is in place
string crap = FormsAuthentication.GetRedirectUrl("user1", false);
Here are extracts from my Web.config file:
<configuration>
<system.web>
<!-- snip -->
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are
"Windows", "Forms",
"Passport" and "None"
-->
<authentication mode="Forms">
<forms name=".ASPAUTHSCEF" protection="None" loginUrl="ssl/login.aspx"
timeout="30" />
</authentication>
<authorization>
<allow users="?" />
</authorization>
<!-- snip -->
<!-- SESSION STATE SETTINGS
By default ASP .NET uses cookies to identify which requests belong to a particular
session.
If cookies are not available, a session can be tracked by adding a session identifier to
the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
</system.web>
<location path="ssl/members">
<system.web>
<authorization>
<allow users="user1" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>