Cerco di implementare l'autenticazione e l'autorizzazione di ASP.NET sopra il nostro database esistente. Abbiamo un sito Web che chiama un webservice per recuperare i suoi dati. Per utilizzare il servizio web, ho bisogno di fornire il nome utente e la password. Sapendo ciò, ho deciso di implementare IIdentity e IPrincipal per archiviare la password crittografata ed essere in grado di fornirla quando si eseguono chiamate al servizio web. In futuro, potremmo voler utilizzare più della sicurezza integrata di asp.net, quindi implemento l'appartenenza e il provider di ruoli e sovrascrivo solo ciò di cui ho bisogno (ValidateUser e GetRoles) Tuttavia, dopo aver convalidato l'utente grazie al implementazione del provider di appartenenze Sto ancora impostando la mia CustomIdentity su Context.User per poter recuperare la sua password quando necessario.SerializationException su 'CustomIdentity' quando l'utente è negato in ASP.NET
Funziona perfettamente finché l'utente è autorizzato a visitare la pagina. ma quando l'utente viene negato, invece di lanciare un'eccezione AccessDeniedException, il framework genera un'eccezione di serializzazione su CustomIdentity. Ho trovato un perfectly similar behaviour with more details described on this link, ma nessuna risposta è stata pubblicata.
La mia eccezione è esattamente lo stesso sul link qui sopra
Type is not resolved for member'CW.CustomAuthentication.CWIdentity,CW.CustomAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.Serialization.SerializationException: Type is not resolved for member 'CW.CustomAuthentication.CWIdentity,CW.CustomAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SerializationException: Type is not resolved for member 'CW.CustomAuthentication.CWIdentity,CW.CustomAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
Microsoft.VisualStudio.WebHost.Connection.get_RemoteIP() +0
Microsoft.VisualStudio.WebHost.Request.GetRemoteAddress() +65
System.Web.HttpRequest.get_UserHostAddress() +18
System.Web.HttpRequest.get_IsLocal() +13
System.Web.Configuration.CustomErrorsSection.CustomErrorsEnabled(HttpRequest request) +86
System.Web.HttpContext.get_IsCustomErrorEnabled() +42
System.Web.Configuration.UrlAuthFailedErrorFormatter.GetErrorText(HttpContext context) +16
System.Web.Security.UrlAuthorizationModule.WriteErrorMessage(HttpContext context) +29
System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) +8777783
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
È corretto utilizzare l'appartenenza e personalizzato IIdentity e IPrincipal allo stesso tempo? In caso negativo, dove aggiungere proprietà come la password o altri dati utente se utilizzo i provider di appartenenza e ruolo?
Con i migliori saluti,
Stephane Erbrech
@serbrech: se rileggete gentilmente la vostra domanda, noterete sicuramente che non avete pubblicato l'eccezione. In effetti, per favore prenditi il tempo di postare l'eccezione * complete * catturandola, quindi pubblicando il risultato di 'ex.ToString()'. –
appena aggiunto l'eccezione che ottengo, se aiuta –
@serbrech: grazie. La tua 'CW.CustomAuthentication.CWIdentity' è serializzabile? Hai provato che può essere serializzato usando 'BinaryFormatter'? –