Problem with a WebSetup Project in VS2005

Feb 17 2009 4:25 AM
Good Morning All  I have inherited a Project, now the Guy had a Installer Project that has been written like this
1    namespace ClassLib
2    
3    {
4    
5    [RunInstaller(true)]
6    
7    public class ClassLib : Installer
8    
9    {
10   
11   public override void Install(System.Collections.IDictionary stateSaver)
12   
13   {
14   
15   base.Install(stateSaver);
16   
17   // Retrieve configuration settings
18   
19   string targetSite = Context.Parameters["TargetSite"];
20   
21   string targetVDir = Context.Parameters["TargetVdir"];
22   
23   string targetDir = Context.Parameters["TargetDir"];
24   
25   if (targetSite.StartsWith("/LM/"))
26   
27   {
28   
29   targetSite = targetSite.Substring(4);
30   
31   writeEventLogs();
32   
33   //adjust the web.config file.
34   
35   createConnectionString(targetSite, targetVDir, targetDir);
36   
37   //create ASP.Net 2 site...
38   
39   RegisterScriptMaps(targetSite, targetVDir);
40   
41   }
42   
43   }
44   
45   
46   
47   void RegisterScriptMaps(string targetSite, string targetVDir)
48   
49   {
50   
51   // Calculate Windows path
52   
53   string sysRoot = System.Environment.GetEnvironmentVariable("SystemRoot");
54   
55   //get the latest .net framework directory
56   
57   DirectoryInfo di = new DirectoryInfo(sysRoot + "/Microsoft.NET/Framework");
58   
59   
60   
61   DirectoryInfo[] frameworkDir = di.GetDirectories("v2.0.*", SearchOption.TopDirectoryOnly);
62   
63   
64   
65   int big = 0;
66   
67   for (int i = 0; i < frameworkDir.Length; i++)
68   
69   {
70   
71   int current = Convert.ToInt32(frameworkDir[i].Name.Substring(5));
72   
73   if (current > big)
74   
75   {
76   
77   big = current;
78   
79   }
80   
81   }
82   
83   string latestFramework = di.FullName + "\\v2.0." + big.ToString();
84   
85   // Launch aspnet_regiis.exe utility to configure mappings
86   
87   ProcessStartInfo info = new ProcessStartInfo();
88   
89   info.FileName = latestFramework + "\\aspnet_regiis.exe";
90   
91   info.Arguments = string.Format("-s {0}/ROOT/{1}", targetSite, targetVDir);
92   
93   info.CreateNoWindow = true;
94   
95   info.UseShellExecute = false;
96   
97   Process.Start(info);
98   
99   }
100  
101  void writeEventLogs()
102  
103  {
104  
105  //for debugging purposes write these values to eventlog.
106  
107  EventLog.WriteEntry("o!Web Server", Context.Parameters["Server"]);
108  
109  EventLog.WriteEntry("o!Web User", Context.Parameters["Username"]);
110  
111  EventLog.WriteEntry("o!Web Password", Context.Parameters["Password"]);
112  
113  EventLog.WriteEntry("o!Web Target Directory", Context.Parameters["TargetDir"]);
114  
115  EventLog.WriteEntry("o!Web Target Site", Context.Parameters["TargetSite"]);
116  
117  EventLog.WriteEntry("o!Web Virtual Directory", Context.Parameters["TargetVdir"]);
118  
119  }
120  
121  void createConnectionString(string targetSite, string targetVDir, string targetDir)
122  
123  {
124  
125  // Retrieve "Friendly Site Name" from IIS for TargetSite
126  
127  DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite);
128  
129  string friendlySiteName = entry.Properties["ServerComment"].Value.ToString();
130  
131  //set the connection timeout property
132  
133  entry.Properties["ConnectionTimeout"][0] = 1800;
134  
135  entry.CommitChanges();
136  
137  entry = new DirectoryEntry("IIS://LocalHost/" + targetSite + "/ROOT/" + targetVDir);
138  
139  entry.Properties["AspScriptTimeout"][0] = 1800;
140  
141  entry.Properties["AspSessionTimeout"][0] = 60;
142  
143  entry.CommitChanges();
144  
145  
146  
147  FileSecurity fSecurity = File.GetAccessControl(targetDir + "App_Data");
148  
149  //string DomainUserName = Environment.UserDomainName + "\\IUSR_" + Environment.MachineName;
150  
151  string LocalUserName = Environment.MachineName + "\\IUSR_" + Environment.MachineName;
152  
153  string LocalGroupName = Environment.MachineName + "\\IIS_WPG";
154  
155  // Add the FileSystemAccessRule to the security settings. 
156  
157  try
158  
159  {
160  
161  fSecurity.AddAccessRule(new FileSystemAccessRule(LocalGroupName, FileSystemRights.FullControl, AccessControlType.Allow));
162  
163  fSecurity.AddAccessRule(new FileSystemAccessRule(LocalUserName, FileSystemRights.FullControl, AccessControlType.Allow));
164  
165  //fSecurity.AddAccessRule(new FileSystemAccessRule(DomainUserName, FileSystemRights.Write, AccessControlType.Allow));
166  
167  // Set the new access settings.
168  
169  File.SetAccessControl(targetDir + "App_Data", fSecurity);
170  
171  }
172  
173  catch
174  
175  {
176  
177  }
178  
179  // Open Application's Web.Config
180  
181  Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetVDir, friendlySiteName);
182  
183  config.AppSettings.Settings["installpath"].Value = targetDir.Substring(0, targetDir.Length - 1);
184  
185  config.AppSettings.Settings["DBuser"].Value = login();
186  
187  config.AppSettings.Settings["adminEmail"].Value = Context.Parameters["adminEmail"];
188  
189  config.ConnectionStrings.ConnectionStrings["DBConnectionString"].ConnectionString = connectionString("oDirectv3");
190  
191  config.ConnectionStrings.ConnectionStrings["oDirectConnectionString"].ConnectionString = connectionString("oDirectv3");
192  
193  ((CompilationSection)config.GetSection("system.web/compilation")).Debug = false;
194  
195  //save web.config
196  
197  config.Save();
198  
199  }
200  
201  string connectionString(string db)
202  
203  {
204  
205  string server = string.Empty;
206  
207  if (Context.Parameters["Server"] != string.Empty)
208  
209  {
210  
211  server += "Data Source=" + Context.Parameters["Server"] + ";Initial Catalog=" + db + ";Persist Security Info=True;" + login();
212  
213  }
214  
215  return server;
216  
217  }
218  
219  string login()
220  
221  {
222  
223  //User ID=o;Password=abacus
224  
225  string login = string.Empty;
226  
227  if ((Context.Parameters["Username"] != string.Empty) && (Context.Parameters["Password"] != string.Empty))
228  
229  {
230  
231  login += "User ID=" + Context.Parameters["Username"] + ";Password=" + Context.Parameters["Password"];
232  
233  }
234  
235  return login;
236  
237  }
238  
239  public override void Uninstall(IDictionary savedState)
240  
241  {
242  
243  base.Uninstall(savedState);
244  
245  }
246  
247  public override void Commit(IDictionary savedState)
248  
249  {
250  
251  base.Commit(savedState);
252  
253  }
254  
255  public override void Rollback(IDictionary savedState)
256  
257  {
258  
259  base.Rollback(savedState);
260  
261  }
262  
263  }
264  

 

 

Now am not that familiar with this. now in the Custom action , CustomDataAction Property of the CustomAction, i have wrote the Following parameters

 

 

/Targetdir=”[TARGETDIR]\” /TargetVdir=”[TARGETVDIR]\” /targetsite=”[TARGETSITE]\”   

 

After the Installation, the Connectionstring does not get changed . i think that am not submitting all the parameters.

 

can someone helpo me on this regard

 

Thank you