All'interno di un HttpModule, a seguito di una riscrittura URL, sto sto testando autorizzazioni utente ad un ad un percorso virtuale situato all'interno della mia applicazione usando:Come testare le autorizzazioni utente per la directory virtuale?
// Since we are now rewriting the path we need to check again that the
// current user has access to the rewritten path.
// Get the user for the current request
// If the user is anonymous or authentication doesn't work for this suffix
// avoid a NullReferenceException in the UrlAuthorizationModule by creating
// a generic identity.
string virtualCachedPath = cache.GetVirtualCachedPath();
IPrincipal user = context.User ?? new GenericPrincipal(
new GenericIdentity(string.Empty, string.Empty), new string[0]);
// Do we have permission to call
// UrlAuthorizationModule.CheckUrlAccessForPrincipal?
PermissionSet permission = new PermissionSet(PermissionState.None);
permission.AddPermission(
new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted));
bool hasPermission =
permission.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
bool isAllowed = true;
// Run the rewritten path past the auth system again, using the result as
// the default "AllowAccess" value
if (hasPermission && !context.SkipAuthorization)
{
isAllowed = UrlAuthorizationModule.CheckUrlAccessForPrincipal(
virtualCachedPath, user, "GET");
}
Dove virtualCachedPath
è qualsiasi percorso virtuale per esempio ~/app_data/cache
situato con la radice l'applicazione.
Questo, tuttavia, genera un ArgumentException
ma se testati contro una directory virtuale esterna.
[ArgumentException: percorso virtuale esterno all'applicazione corrente non supportato. Nome parametro: virtualPath]
Ad es
Qual è il metodo corretto per verificare il permesso all'utente di una directory virtuale?
Hai assolutamente ragione. Il metodo che stavo usando per determinare il percorso non era corretto. –