protected void btnAdd_Click(object sender, EventArgs e)
        {
            List<MimeMap> types = CollectFormData(true);

            // add empty error
            MimeMap type = new MimeMap();
            type.Extension = "";
            type.MimeType = "";
            types.Add(type);

            gvMimeTypes.DataSource = types;
            gvMimeTypes.DataBind();
        }
        public List<MimeMap> CollectFormData(bool includeEmpty)
        {
            List<MimeMap> types = new List<MimeMap>();
            foreach (GridViewRow row in gvMimeTypes.Rows)
            {
                TextBox txtExtension = (TextBox)row.FindControl("txtExtension");
                TextBox txtMimeType = (TextBox)row.FindControl("txtMimeType");

                // create a new HttpError object and add it to the collection
                MimeMap type = new MimeMap();
                type.Extension = txtExtension.Text.Trim();
                type.MimeType = txtMimeType.Text.Trim();

                if (includeEmpty || type.Extension != "")
                    types.Add(type);
            }

            return types;
        }
Esempio n. 3
0
    	private void FillVirtualDirectoryRestFromWmiObject(WebVirtualDirectory virtDir,
            ManagementBaseObject obj)
        {
            virtDir.ContentPath = (string)obj.Properties["Path"].Value;
            
            string httpRedirect = (string)obj.Properties["HttpRedirect"].Value;
            if(!String.IsNullOrEmpty(httpRedirect))
            {
                virtDir.RedirectExactUrl = httpRedirect.Contains(REDIRECT_EXACT_URL);
                virtDir.RedirectDirectoryBelow = httpRedirect.Contains(REDIRECT_DIRECTORY_BELOW);
                virtDir.RedirectPermanent = httpRedirect.Contains(REDIRECT_PERMANENT);
                virtDir.HttpRedirect = httpRedirect.Split(',')[0].Trim();
            }


            // HTTP headers
            ManagementBaseObject[] objHttpHeaders =
                ((ManagementBaseObject[])obj.Properties["HttpCustomHeaders"].Value);

            if (objHttpHeaders != null)
            {
                virtDir.HttpHeaders = new HttpHeader[objHttpHeaders.Length];
                for (int i = 0; i < objHttpHeaders.Length; i++)
                {
                    virtDir.HttpHeaders[i] = new HttpHeader();
                    string headerVal = (string)objHttpHeaders[i].Properties["Keyname"].Value;
                    if (String.IsNullOrEmpty(headerVal))
                        continue;

                    int sepIdx = headerVal.IndexOf(": ");
                    if (sepIdx == -1)
                        continue;

                    virtDir.HttpHeaders[i].Key = headerVal.Substring(0, sepIdx);
                    virtDir.HttpHeaders[i].Value = headerVal.Substring(sepIdx + 2);
                }
            }

            // HTTP errors (Skip inherited definitions)
            virtDir.HttpErrors = GetCustomHttpErrors(obj, virtDir, true).ToArray();

            // MIME mappings
            ManagementBaseObject[] objMimeMaps =
                ((ManagementBaseObject[])obj.Properties["MimeMap"].Value);

            if (objMimeMaps != null)
            {
                List<MimeMap> mimes = new List<MimeMap>();
                for (int i = 0; i < objMimeMaps.Length; i++)
                {
                    string mimeExt = (string)objMimeMaps[i].Properties["Extension"].Value;

                    if (String.IsNullOrEmpty(mimeExt))
                        continue;

                    MimeMap mime = new MimeMap();
                    mime.Extension = mimeExt;
                    mime.MimeType = (string)objMimeMaps[i].Properties["MimeType"].Value;
                    mimes.Add(mime);
                }

                virtDir.MimeMaps = mimes.ToArray();
            }

            // script mappings
            ManagementBaseObject[] objScriptMaps =
                ((ManagementBaseObject[])obj.Properties["ScriptMaps"].Value);

            virtDir.AspInstalled = false; // not installed
            virtDir.AspNetInstalled = ""; // none
            virtDir.PhpInstalled = ""; // none
            virtDir.PerlInstalled = false; // not installed
            virtDir.PythonInstalled = false; // not installed
    	    virtDir.ColdFusionInstalled = false; //not installed

            foreach (ManagementBaseObject objScriptMap in objScriptMaps)
            {
                string processor = (string)objScriptMap.Properties["ScriptProcessor"].Value;
                string extension = (string) objScriptMap.Properties["Extensions"].Value;
                if (String.Compare(AspPath, processor, true) == 0)
                    virtDir.AspInstalled = true;
                else if (String.Compare(AspNet11Path, processor, true) == 0)
                    virtDir.AspNetInstalled = ASPNET_11;
                else if (String.Compare(AspNet20Path, processor, true) == 0)
                    virtDir.AspNetInstalled = ASPNET_20;
				else if (String.Compare(AspNet40Path, processor, true) == 0)
					virtDir.AspNetInstalled = ASPNET_40;
                else if (String.Compare(Php4Path, processor, true) == 0)
                    virtDir.PhpInstalled = PHP_4;
                else if (String.Compare(Php5Path, processor, true) == 0)
                    virtDir.PhpInstalled = PHP_5;
                else if (String.Compare(PerlPath, processor, true) == 0)
                    virtDir.PerlInstalled = true;
                else if (String.Compare(PythonPath, processor, true) == 0)
                    virtDir.PythonInstalled = true;
                else if (String.Compare(ColdFusionPath, processor, true) == 0 && String.Compare(".cfm", extension, true) == 0)
                    virtDir.ColdFusionInstalled = true;
            }

            // application pool
            virtDir.ApplicationPool = obj.Properties["AppPoolId"].Value.ToString();
        }