Bonjour,
Pour mon site web, je souhaite modifier le web.config par le code.
J'ai trouvé des tuto mais ça n'a pas l'air de fonctionner.
Voici mon code :
et le web.config :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="change.aspx.cs" Inherits="change" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Configuration" %> <%@ Import Namespace="System.Web.Configuration" %> <script language="C#" runat="server"> public void Page_Load(object source, EventArgs e) { appDomaine.Text = ConfigurationManager.AppSettings.Get("domaine"); appGroupe.Text = ConfigurationManager.AppSettings.Get("groupe"); } void ModifySetting_OnClick(Object source, EventArgs e) { ConfigurationManager.AppSettings.Set("domaine", appDomaine.Text); ConfigurationManager.AppSettings.Set("groupe", appGroupe.Text); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <b>Domaine :</b> <asp:TextBox runat="server" id="appDomaine" /><br /> <b>Groupe:</b> <asp:TextBox runat="server" id="appGroupe" /><br /> <asp:Button runat="server" id="ModifySetting" OnClick="ModifySetting_OnClick" Text="Modify" /> <br /> </div> </form> </body> </html>
J'ai essayer de rajouter ces lignes là dans la fonction Page-Load :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <appSettings> <add key="domaine" value="dom_1" /> <add key="groupe" value="grp_2" /> </appSettings>
Et cette fois ci, j'ai bien les nouvelles valeurs dans mes champs texte mais rien n'est modifier dans le web.config.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 ConfigurationManager.AppSettings.Set("domaine", "test-1"); ConfigurationManager.AppSettings.Set("groupe", "test-2");
En les retirants, je les ai toujours dans les champs texte malgré le fait que le web.config n'est pas changé.
Je ne vois pas ce qui cloche.
De plus, l'authentification se fait par formulaire la première fois. Lorsque le web.config est modifier, l'authentification doit se faire par authentification Windows.
Comment puis-je modifier la partie authentification ?
Merci d'avance.
Partager