Authentication Form: UserData vuoto

mercoledì 04 ottobre 2006 - 16.07

Fabioale Profilo | Newbie

Ciao a tutti ...


Vi scrivo perchè avrei un problema:

Sto creando una Web Application che utilizza un' Authentication Form.
Nella pagina di Login , dopo aver inserito Username e password correttamente, viene creato un cookie con FormsAuthenticationTicket , come descritto al seguente link

http://support.microsoft.com/default.aspx?scid=kb%3Bit%3B308157

A Login effettuato , nella pagina .aspx successiva ho la necessità di accedere allo UserData del ticket .
Il problema stà nel fatto che la stringa relativa allo UserData risulta vuota.
Questo è il codice che ho utilizzato per recuperare lo UserData:

protected void Page_Load(object sender, EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (null == authCookie)
{
return;
}

FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch (Exception ex)
{
return;
}
if (null == authTicket)
{
return;
}
string[] roles = authTicket.UserData.Split(new char[] { '|' });
}

Dov'è il problema???

Per completezza vi invio anche il web-config:

<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="ws_name" value="XEDA.NET® - eXtended Engine for Database Assistant"/>
<add key="xml_servername" value="Server.xml"/>
<add key="xml_path" value="C:\Inetpub\wwwroot\aspnetsbs\Xeda\xml\"/>
<add key="Server" value="10.10.80.8"/>
<add key="Uid" value="dan"/>
<add key="Pwd" value="dan"/>
<add key="dbName" value="Xeda"/>
</appSettings>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Forms">
<forms
name=".ASPXAUTH"
loginUrl="Login.aspx"
protection="All"
path="/" />
</authentication>
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>

<location path="prova.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="index.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
</configuration>




Vi ringrazio anticipatamente per le vostre eventuali risposte al mio quesito

porporato Profilo | Newbie

Ho avuto anch'io lo stesso problema, e mi ha fatto perdere parecchio tempo.

Preciso che il mio codice funzionava perfettamente su una applicazione, mentre su un'altra applicazione risiedente sullo stesso web server dava il problema che citi tu.

Per l'introduzione di username/password utilizzo un oggetto di tipo login e verifico l'autenticazione nell'evento Authenticate.
Al termine della routine non facevo alcun redirect, perché avevo impostato l'attributo defaultUrl nel webconfig, e perciò se l'autenticazione andava a buon fine il redirect era automatico.

Dopo decine di tentativi di vario tipo, ho scoperto che se, dopo aver verificato il buon esito dell'autenticazione e aver scritto il cookie, redireziono l'utente con un response.redirect, nell'evento Application_AuthenticateRequest del global.asax continuo a leggere perfettamente i dati del cookie!
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5