Accès refusé pour utilisateurs anonymes!
Bonjour,
je souhaite dans mon site web refuser l'accès aux utilisateurs anonymes. Je suis sous Windows 7 et j'utilise IIS 6.0.
Voici mon fichier Web.config:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <?xml version="1.0" encoding="utf-8"?>
<!--
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>
<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.
-->
<roleManager defaultProvider="AspNetWindowsTokenRoleProvider" enabled="true" />
<compilation debug="true" targetFramework="4.0" />
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<authorization>
<!-- interdit aux inconnus (anonymes) -->
<deny 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>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
<identity impersonate="false" />
</system.web>
<location path="achats.aspx">
<system.web>
<authorization>
<allow roles="acheteurs" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration> |
Ensuite je démarre l'application qui doit afficher un certain nombre de renseignements. Voici le fichier Default.aspx.cs:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text =
string.Format("Nom d'utilisateur: {0}\nRéférentiel: {1}\nAuthentifé ? {2}\nType: {3}\nMembre d'Acheteurs ? {4}",
User.Identity.Name,
User.Identity.AuthenticationType,
User.Identity.IsAuthenticated,
User.GetType().FullName,
User.IsInRole(@"Acheteurs")); // ou bien BRICE-ARNAUD\Acheteur
if (Roles.IsUserInRole("Acheteurs"))
Label1.Text = "Membre du groupe Acheteurs";
else
Label1.Text = "Ne figure pas dans le groupe Acheteurs";
}
} |
Normalement, dans le fichier Web.config le code
Code:
1 2 3 4
| <authorization>
<!-- interdit aux inconnus (anonymes) -->
<deny users="?" />
</authorization> |
n'autorise aux utilisateurs non authentifiés à se connecter. Donc quand je lance mon site web il me met accès refusé. Dans mon gestionnaire IIS le mode Authentification anonyme est activé. Il y'a deux autres mode: Authentification par formulaire et Emprunt d'identité ASP.net. Aussi que dois-je faire pour créer un utilisateur qui puisse s'authentifier pour ne plus avoir le message d'erreur avant de lancer le site web? Bref je ne vois pas comment procéder. J'utilise IIS 6.0, donc l'utilisateur à priori c'est Sébastien-PC\IIS_IUSRS. Merci d'avance pour votre réponse.
mumu27!