Example #1
0
        public void FullyQualifiedDomainNameVsIndividualLabels()
        {
            var idn = new IdnMapping();

            // ASCII only code points
            Assert.Equal("\u0061\u0062\u0063", idn.GetAscii("\u0061\u0062\u0063"));
            // non-ASCII only code points
            Assert.Equal("xn--d9juau41awczczp", idn.GetAscii("\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067"));
            // ASCII and non-ASCII code points
            Assert.Equal("xn--de-jg4avhby1noc0d", idn.GetAscii("\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0"));
            // Fully Qualified Domain Name
            Assert.Equal("abc.xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0"));
        }
Example #2
0
        public void EmbeddedNulls()
        {
            var idn = new IdnMapping();

            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0, 2));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0, 3));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0, 4));
        }
Example #3
0
        public bool IsValidEmail(string strIn)
        {
            var invalid = false;
            if (String.IsNullOrEmpty(strIn))
                return false;

            MatchEvaluator DomainMapper = match =>
            {
                // IdnMapping class with default property values.
                IdnMapping idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    invalid = true;
                }
                return match.Groups[1].Value + domainName;
            };

            // Use IdnMapping class to convert Unicode domain names.
            strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
            if (invalid)
                return false;

            // Return true if strIn is in valid e-mail format.
            return Regex.IsMatch(strIn,
                      @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                      @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$",
                      RegexOptions.IgnoreCase);
        }
 private static string DomainMapper(Match match)
 {
     var idn = new IdnMapping();
     var domainName = match.Groups[2].Value;
     domainName = idn.GetAscii(domainName);
     return match.Groups[1].Value + domainName;
 }
        public bool IsValidUsername(string strIn)
        {
            bool invalid = false;
            if (String.IsNullOrEmpty(strIn))
                return false;

            MatchEvaluator DomainMapper = match =>
            {
                // IdnMapping class with default property values.
                var idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    invalid = true;
                }
                return match.Groups[1].Value + domainName;
            };

            // Use IdnMapping class to convert Unicode domain names. 
            // strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
            if (invalid)
                return false;

            // Return true if strIn is in valid e-mail format. 
            return Regex.IsMatch(strIn,
                @"^[a-z][a-zA-Z]*$",
                RegexOptions.IgnoreCase);
        }
Example #6
0
        public bool IsEmail(string src)
        {
            if (string.IsNullOrWhiteSpace(src))
                return false;

            try
            {
                // Use IdnMapping class to convert Unicode domain names.
                var idn = new IdnMapping();
                src = Regex.Replace(
                    src, 
                    @"(@)(.+)$", 
                    match => match.Groups[1].Value + idn.GetAscii(match.Groups[2].Value), 
                    RegexOptions.None, 
                    TimeSpan.FromMilliseconds(200));

                // Validate email address using Regex.
                return Regex.IsMatch(
                    src,
                    @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                    RegexOptions.IgnoreCase, 
                    TimeSpan.FromMilliseconds(250));
            }
            catch (Exception ex)
            {
                this.loggingService.Exception(ex, "Error while validation email address:", src);
                return false;
            }
        }
Example #7
0
        private void VerifyStd3AsciiRules(string unicode)
        {
            var idnStd3False = new IdnMapping { UseStd3AsciiRules = false };
            var idnStd3True = new IdnMapping { UseStd3AsciiRules = true };

            Assert.Equal(unicode, idnStd3False.GetAscii(unicode));
            Assert.Throws<ArgumentException>(() => idnStd3True.GetAscii(unicode));
        }
Example #8
0
 private string DomainMapper(Match match)
 {
     IdnMapping idn = new IdnMapping();
     string domainName = match.Groups[2].Value;
     try { domainName = idn.GetAscii(domainName); }
     catch (ArgumentException) { _emailIsInvalid = true; }
     return match.Groups[1].Value + domainName;
 }
		void GetAsciiInvalid (IdnMapping m, string s, object label)
		{
			try {
				m.GetAscii (s);
				Assert.Fail (label != null ? label.ToString () + ":" + s : s);
			} catch (ArgumentException) {
			}
		}
Example #10
0
        public static string DomainMapper(Match match)
        {
            // IdnMapping class with default property values.
            var idn = new IdnMapping();

            var domainName = match.Groups[2].Value;
            domainName = idn.GetAscii(domainName);
            return match.Groups[1].Value + domainName;
        }
		private string DomainMapper(Match match) {
			// IdnMapping class with default property values.
			IdnMapping idn = new IdnMapping();

			string domainName = match.Groups[2].Value;
			try {
				domainName = idn.GetAscii(domainName);
			} catch(ArgumentException) {
				this._invalid = true;      
			}      
			return match.Groups[1].Value + domainName;
		}
Example #12
0
        private string DomainMapper(string strIn)
        {
            string ret = Regex.Replace(strIn, @"(@)(.+)$", (match) =>
            {
                IdnMapping idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                    domainName = idn.GetAscii(domainName);
                return match.Groups[1].Value + domainName;
            }, RegexOptions.None, TimeSpan.FromMilliseconds(200));

            return ret;
        }
Example #13
0
        public static bool IsValidEmail(string email)
        {
            bool invalid = false;
            if (String.IsNullOrEmpty(email))
            {
                return false;
            }

            try
            {
                email = Regex.Replace(email, @"(@)(.+)$", match =>
                    {
                        //use IdnMapping class to convert Unicode domain names.
                        var idn = new IdnMapping();

                        string domainName = match.Groups[2].Value;
                        try
                        {
                            domainName = idn.GetAscii(domainName);
                        }
                        catch (ArgumentException)
                        {
                            invalid = true;
                        }

                        return match.Groups[1].Value + domainName;
                    },
                    RegexOptions.Compiled, TimeSpan.FromMilliseconds(200));
            }
            catch (RegexMatchTimeoutException)
            {
                return false;
            }

            if (invalid)
            {
                return false;
            }

            //return true if input is in valid e-mail format.
            try
            {
                return EmailRegex.IsMatch(email);
            }
            catch (RegexMatchTimeoutException)
            {
                return false;
            }
        }
Example #14
0
		private static string ConvertUnicodeToPunycodeDomain(Match match)
		{
			string str;
			IdnMapping idnMapping = new IdnMapping();
			string value = match.Groups[2].Value;
			try
			{
				value = idnMapping.GetAscii(value);
				return string.Concat(match.Groups[1].Value, value);
			}
			catch
			{
				str = null;
			}
			return str;
		}
Example #15
0
        internal static string GetAscii(string name)
        {
            if (!string.IsNullOrWhiteSpace(name))
            {
                try
                {
                    name = idnMapping.GetAscii(name);
                }
                catch (ArgumentException)
                {
                    // In the case of invalid unicode we will use the original name.
                }
            }

            return(name);
        }
Example #16
0
    bool IsValidEmail(string email)
    {
        if (string.IsNullOrWhiteSpace(email))
        {
            return(false);
        }

        try
        {
            // Normalize the domain
            email = Regex.Replace(email, @"(@)(.+)$", DomainMapper,
                                  RegexOptions.None, TimeSpan.FromMilliseconds(200));

            // Examines the domain part of the email and normalizes it.
            string DomainMapper(Match match)
            {
                // Use IdnMapping class to convert Unicode domain names.
                var idn = new System.Globalization.IdnMapping();

                // Pull out and process domain name (throws ArgumentException on invalid)
                var domainName = idn.GetAscii(match.Groups[2].Value);

                return(match.Groups[1].Value + domainName);
            }
        }
        catch (RegexMatchTimeoutException e)
        {
            return(false);
        }
        catch (ArgumentException e)
        {
            return(false);
        }

        try
        {
            return(Regex.IsMatch(email,
                                 @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                 @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                                 RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
        }
        catch (RegexMatchTimeoutException)
        {
            return(false);
        }
    }
Example #17
0
        public void SimpleValidationTests()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--yda", idn.GetAscii("\u0101"));
            Assert.Equal("xn--yda", idn.GetAscii("\u0101", 0));
            Assert.Equal("xn--yda", idn.GetAscii("\u0101", 0, 1));

            Assert.Equal("xn--aa-cla", idn.GetAscii("\u0101\u0061\u0041"));
            Assert.Equal("xn--ab-dla", idn.GetAscii("\u0061\u0101\u0062"));
            Assert.Equal("xn--ab-ela", idn.GetAscii("\u0061\u0062\u0101"));
        }
Example #18
0
        // Проверка домена, чтобы все его символы были из ASCII
        public string DomainMapper(Match match)
        {
            // IdnMapping class with default property values.
            IdnMapping idn = new IdnMapping();

            string domainName = match.Groups[2].Value;
            Console.WriteLine("domain={0}", domainName);
            try
            {
                // Метод IdnMapping.GetAscii нормализует имя домена, преобразует нормализованное имя в представление
                domainName = idn.GetAscii(domainName);
            }
            catch (ArgumentException)
            {
                invalid = true;
            }
            return match.Groups[1].Value + domainName;
        }
            public string DomainMapper(Match match)
            {
                m_Invalid = false;

                // IdnMapping class with default property values.
                var idn = new IdnMapping();

                string domainName = match.Groups[2].Value;

                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    m_Invalid = true;
                }

                return match.Groups[1].Value + domainName;
            }
Example #20
0
        private static void VerifyMessage(SqrlMessage sqrl)
        {
            string url = sqrl.Uri.ToString()
                            .Replace("https://", "sqrl://")
                            .Replace("http://", "qrl://");

            var idn = new IdnMapping();
            var puny = idn.GetAscii(url);
            var punyBytes = Encoding.ASCII.GetBytes(puny);
            var signatureBytes = sqrl.SignatureBytes;

            var signature = new byte[punyBytes.Length + signatureBytes.Length];
            Buffer.BlockCopy(signatureBytes, 0, signature, 0, signatureBytes.Length);
            Buffer.BlockCopy(punyBytes, 0, signature, signatureBytes.Length, punyBytes.Length);

            if (!CryptoSign.Open(signature, sqrl.PublicKeyBytes))
            {
                throw new SqrlAuthenticationException("Signature verification failed.");
            }
        }
        internal static SslPolicyErrors VerifyCertificateProperties(
            X509Chain chain,
            X509Certificate2 remoteCertificate,
            bool checkCertName,
            bool isServer,
            string hostName)
        {
            SslPolicyErrors sslPolicyErrors = SslPolicyErrors.None;

            if (!chain.Build(remoteCertificate))
            {
                sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors;
            }

            if (checkCertName)
            {
                if (string.IsNullOrEmpty(hostName))
                {
                    sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
                }
                else
                {
                    int hostnameMatch;

                    using (SafeX509Handle certHandle = Interop.Crypto.X509Duplicate(remoteCertificate.Handle))
                    {
                        IPAddress hostnameAsIp;

                        if (IPAddress.TryParse(hostName, out hostnameAsIp))
                        {
                            byte[] addressBytes = hostnameAsIp.GetAddressBytes();

                            hostnameMatch = Interop.Crypto.CheckX509IpAddress(
                                certHandle,
                                addressBytes,
                                addressBytes.Length,
                                hostName,
                                hostName.Length);
                        }
                        else
                        {
                            // The IdnMapping converts Unicode input into the IDNA punycode sequence.
                            // It also does host case normalization.  The bypass logic would be something
                            // like "all characters being within [a-z0-9.-]+"
                            //
                            // Since it's not documented as being thread safe, create a new one each time.
                            IdnMapping mapping = new IdnMapping();
                            string matchName = mapping.GetAscii(hostName);

                            hostnameMatch = Interop.Crypto.CheckX509Hostname(certHandle, matchName, matchName.Length);
                        }
                    }

                    if (hostnameMatch != 1)
                    {
                        Debug.Assert(hostnameMatch == 0, "hostnameMatch should be (0,1) was " + hostnameMatch);
                        sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
                    }
                }
            }
            return sslPolicyErrors;
        }
Example #22
0
    private static CheckResult TryAccessURL(String strOriginalURL)
    {
        CheckResult r = new CheckResult();

        try
        {
            UriBuilder ubBuildURL = null;
            try
            {
                r.BuildURL = strOriginalURL;
                ubBuildURL = new UriBuilder(strOriginalURL);

                //IdnMappingオブジェクトを作成する
                System.Globalization.IdnMapping im = new System.Globalization.IdnMapping();
                //punycodeにエンコードする
                string punycode = im.GetAscii(ubBuildURL.Host);

                ubBuildURL.Host = punycode;
            }
            catch (Exception err)
            {
                r.StatusCode        = err.Message;
                r.StatusDescription = strOriginalURL;
                Console.WriteLine("{0}:::::{1}", r.StatusCode, r.StatusDescription);
                throw err;
            }

            //WebRequestの作成
            System.Net.HttpWebRequest webreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(ubBuildURL.Uri);

            r.BuildURL = ubBuildURL.Uri.ToString();

            System.Net.HttpWebResponse webres = null;
            try
            {
                //サーバーからの応答を受信するためのWebResponseを取得
                webres = (System.Net.HttpWebResponse)webreq.GetResponse();

                //応答したURIを表示する
                System.Diagnostics.Trace.WriteLine(webres.ResponseUri + "\n");
                //応答ステータスコードを表示する
                System.Diagnostics.Trace.WriteLine(String.Format("{0}::{1}", webres.StatusCode, webres.StatusDescription) + "\n");
                r.StatusCode        = webres.StatusCode.ToString();
                r.StatusDescription = webres.StatusDescription.ToString();
            }
            catch (System.Net.WebException ex)
            {
                //HTTPプロトコルエラーかどうか調べる
                if (ex.Status == System.Net.WebExceptionStatus.ProtocolError)
                {
                    //HttpWebResponseを取得
                    System.Net.HttpWebResponse errres =
                        (System.Net.HttpWebResponse)ex.Response;
                    //応答したURIを表示する
                    System.Diagnostics.Trace.WriteLine(errres.ResponseUri + "\n");
                    //応答ステータスコードを表示する
                    System.Diagnostics.Trace.WriteLine(String.Format("{0}:::{1}", errres.StatusCode, errres.StatusDescription));
                    r.StatusCode        = errres.StatusCode.ToString();
                    r.StatusDescription = errres.StatusDescription.ToString();
                }
                else
                {
                    r.StatusCode = ex.ToString();
                    System.Diagnostics.Trace.WriteLine(ex.Message + "\n");
                }
            }
            finally
            {
                //閉じる
                if (webres != null)
                {
                    webres.Close();
                }
            }
        }
        catch (Exception e)
        {
            r.StatusCode        = e.Message;
            r.StatusDescription = e.Message;
        }

        return(r);
    }
 private static string GetAsciiZoneName(string zoneName)
 {
     if (string.IsNullOrEmpty(zoneName)) return zoneName;
     var idn = new IdnMapping();
     return idn.GetAscii(zoneName);
 }
Example #24
0
        public void SurrogatePairsSeparatedByAsciiAndNonAscii()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--a-nha4529qfag", idn.GetAscii("\uD800\uDF00\u0101\uD800\uDF01\u0061\uD800\uDF02"));
        }
Example #25
0
        public void SurrogatePairsSeparatedByNonAscii()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--yda263v6b6kfag", idn.GetAscii("\uD800\uDF00\u0101\uD800\uDF01\u305D\uD800\uDF02"));
        }
Example #26
0
        public void SurrogatePairsSeparatedByAscii()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--ab-ic6nfag", idn.GetAscii("\uD800\uDF00\u0061\uD800\uDF01\u0042\uD800\uDF02"));
        }
Example #27
0
        public void SurrogatePairsConsecutive()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--097ccd", idn.GetAscii("\uD800\uDF00\uD800\uDF01\uD800\uDF02"));
        }
Example #28
0
        internal unsafe static string UnicodeEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
        {
            IdnMapping map = new IdnMapping();

            // hostname already validated
            allAscii = true;
            atLeastOneValidIdn = false;
            string idn = null;
            if (end <= start)
                return idn;

            string unescapedHostname = Uri.StripBidiControlCharacter(hostname, start, (end - start));

            string unicodeEqvlHost = null;
            int curPos = 0;
            int newPos = 0;
            int length = unescapedHostname.Length;
            bool asciiLabel = true;
            bool foundAce = false;
            bool checkedAce = false;
            bool foundDot = false;


            // We run a loop where for every label
            // a) if label is ascii and no ace then we lowercase it
            // b) if label is ascii and ace and not valid idn then just lowercase it
            // c) if label is ascii and ace and is valid idn then get its unicode eqvl
            // d) if label is unicode then clean it by running it through idnmapping
            do
            {
                asciiLabel = true;
                foundAce = false;
                checkedAce = false;
                foundDot = false;

                //find the dot or hit the end
                newPos = curPos;
                while (newPos < length)
                {
                    char c = unescapedHostname[newPos];
                    if (!checkedAce)
                    {
                        checkedAce = true;
                        if ((newPos + 3 < length) && (c == 'x') && IsIdnAce(unescapedHostname, newPos))
                            foundAce = true;
                    }
                    if (asciiLabel && (c > '\x7F'))
                    {
                        asciiLabel = false;
                        allAscii = false;
                    }
                    if ((c == '.') || (c == '\u3002') ||    //IDEOGRAPHIC FULL STOP 
                        (c == '\uFF0E') ||                  //FULLWIDTH FULL STOP
                        (c == '\uFF61'))                    //HALFWIDTH IDEOGRAPHIC FULL STOP
                    {
                        foundDot = true;
                        break;
                    }
                    ++newPos;
                }

                if (!asciiLabel)
                {
                    string asciiForm = unescapedHostname.Substring(curPos, newPos - curPos);
                    try
                    {
                        asciiForm = map.GetAscii(asciiForm);
                    }
                    catch (ArgumentException)
                    {
                        throw new UriFormatException(SR.net_uri_BadUnicodeHostForIdn);
                    }

                    unicodeEqvlHost += map.GetUnicode(asciiForm);
                    if (foundDot)
                        unicodeEqvlHost += ".";
                }
                else
                {
                    bool aceValid = false;
                    if (foundAce)
                    {
                        // check ace validity
                        try
                        {
                            unicodeEqvlHost += map.GetUnicode(unescapedHostname.Substring(curPos, newPos - curPos));
                            if (foundDot)
                                unicodeEqvlHost += ".";
                            aceValid = true;
                            atLeastOneValidIdn = true;
                        }
                        catch (ArgumentException)
                        {
                            // not valid ace so treat it as a normal ascii label
                        }
                    }

                    if (!aceValid)
                    {
                        // for invalid aces we just lowercase the label
                        unicodeEqvlHost += unescapedHostname.Substring(curPos, newPos - curPos).ToLowerInvariant();
                        if (foundDot)
                            unicodeEqvlHost += ".";
                    }
                }

                curPos = newPos + (foundDot ? 1 : 0);
            } while (curPos < length);

            return unicodeEqvlHost;
        }
		void GetAscii (IdnMapping m, string source, string expected, object label)
		{
			Assert.AreEqual (expected, m.GetAscii (source), label != null ? label.ToString () : expected);
		}
Example #30
0
        //
        // Will convert a host name into its idn equivalent
        //
        internal unsafe static string IdnEquivalent(char* hostname, int start, int end, ref bool allAscii, ref string bidiStrippedHost)
        {
            string idn = null;
            if (end <= start)
                return idn;

            // indexes are validated

            int newPos = start;
            allAscii = true;

            while (newPos < end)
            {
                // check if only ascii chars
                // special case since idnmapping will not lowercase if only ascii present
                if (hostname[newPos] > '\x7F')
                {
                    allAscii = false;
                    break;
                }
                ++newPos;
            }

            if (allAscii)
            {
                // just lowercase for ascii
                string unescapedHostname = new string(hostname, start, end - start);
                return ((unescapedHostname != null) ? unescapedHostname.ToLowerInvariant() : null);
            }
            else
            {
                IdnMapping map = new IdnMapping();
                string asciiForm;
                bidiStrippedHost = Uri.StripBidiControlCharacter(hostname, start, end - start);
                try
                {
                    asciiForm = map.GetAscii(bidiStrippedHost);
                }
                catch (ArgumentException)
                {
                    throw new UriFormatException(SR.net_uri_BadUnicodeHostForIdn);
                }
                return asciiForm;
            }
        }
Example #31
0
        public void Initiate()
        {
            using (var db = new NRDbContext())
            {
                IdnMapping idn = new IdnMapping();
                Guid associationId = (Guid)this.RouteData.Values["associationId"];

                Association association = db.Associations.Include(l => l.PageAbout).Include(l => l.PageLink).Include(l => l.PagePress).Include(l => l.PageSponsor).Include(l => l.Sponsors).Where(a => a.AssociationID == associationId).FirstOrDefault(); //Find(associationId);
                //db.Entry(association).Collection("PageAbout").Load();
                if (association == null) throw new NullReferenceException("Association");

                Basedata.AssociationID = association.AssociationID;

                GetBoard();

                Basedata.SEO = this.RouteData.Values["SEO"] == null ? false : (bool)this.RouteData.Values["SEO"];
               
                Basedata.NetworkID = association.NetworkID;
                Basedata.AssociationName = string.Format(General.BrandTitleAssociation,association.Name);
                Basedata.Host = string.Format("http://{0}.natteravnene.dk", association.Name.ValidDKDomainName());
                Basedata.MainUrl = Request.Url.Host == idn.GetAscii(string.Format("{0}.natteravnene.dk", association.Name.ValidDKDomainName()));
                Basedata.urlCanonical = urlCanonical(association.Name);
                Basedata.Established = (DateTime)association.Established;
                
                Basedata.CVRNR = association.CVRNR;
                if (Basedata.Chairmann != null)
                {
                    Basedata.AssociationEmail = string.IsNullOrWhiteSpace(association.AssociationEmail) ? Basedata.Chairmann.Email : association.AssociationEmail;
                    Basedata.ContactPhone = string.IsNullOrWhiteSpace(association.ContactPhone) ? Basedata.Chairmann.Mobile : association.ContactPhone;
                }
                else
                {
                    Basedata.AssociationEmail = association.AssociationEmail;
                    Basedata.ContactPhone = association.ContactPhone;
                }

               


                
                Basedata.PageAbout = tagReplace(association.PageAbout);
                Basedata.UseLinksPage = association.UseLinksPage;
                Basedata.PageLink = tagReplace(association.PageLink);
                Basedata.UsePressPage = association.UsePressPage;
                Basedata.PagePress = tagReplace(association.PagePress);
                Basedata.PageSponsor = tagReplace(association.PageSponsor);
                Basedata.Sponsors = association.Sponsors.Where(S => S.Finish == null || (DateTime)S.Finish > DateTime.Now).OrderBy(S => S.Sequence).ToList();
                Basedata.UseSponsorPage = association.UseSponsorPage & Basedata.Sponsors.Any();

               

                string LogoDirSetting = ConfigurationManager.AppSettings["Logos"];

                if (string.IsNullOrWhiteSpace(LogoDirSetting)) { throw new ArgumentNullException(); }

                ViewBag.LocalLogoPath = Path.Combine(LogoDirSetting, Basedata.AssociationID + ".jpg");

                if (!System.IO.File.Exists(Server.MapPath(ViewBag.LocalLogoPath)))
                {
                    ViewBag.LocalLogoPath = Path.Combine(LogoDirSetting, "Natteravnene_logo.jpg"); ;
                }

                ViewBag.UseSponsorerPage = Basedata.UseSponsorPage;
                ViewBag.UseLinksPage = Basedata.UseLinksPage;
                ViewBag.UsePressPage = Basedata.UsePressPage;
                ViewBag.Canonical = Basedata.urlCanonical;
                ViewBag.Association = Basedata.AssociationName;
                ViewBag.Host = Basedata.Host;
                ViewBag.AssociationContactPhone = Basedata.ContactPhone;
                ViewBag.AssociationContactEmail = Basedata.AssociationEmail;
                ViewBag.CVR = association.CVRNR;
                ViewBag.AssociationZIP = association.Zip;
                ViewBag.AssociationCity = association.City;
                ViewBag.AssociationCountry = (int)association.Country == 0 ? null : association.Country.DisplayName();
                ViewBag.Founded = association.Established == null ? null : ((DateTime)association.Established).ToString("yyyy-MM-dd");
            }

        }
Example #32
0
        private void Initialize()
        {
            if (_port == DefaultPort || _port == 0)
            {
                new SmtpPermission(SmtpAccess.Connect).Demand();
            }
            else
            {
                new SmtpPermission(SmtpAccess.ConnectToUnrestrictedPort).Demand();
            }

            _transport = new SmtpTransport(this);
            if (MailEventSource.Log.IsEnabled()) MailEventSource.Log.Associate(this, _transport);
            _onSendCompletedDelegate = new SendOrPostCallback(SendCompletedWaitCallback);

            if (_host != null && _host.Length != 0)
            {
                _host = _host.Trim();
            }

            if (_port == 0)
            {
                _port = DefaultPort;
            }

            if (_targetName == null)
                _targetName = "SMTPSVC/" + _host;

            if (clientDomain == null)
            {
                // We use the local host name as the default client domain
                // for the client's EHLO or HELO message. This limits the 
                // information about the host that we share. Additionally, the 
                // FQDN is not available to us or useful to the server (internal
                // machine connecting to public server).

                // SMTP RFC's require ASCII only host names in the HELO/EHLO message.
                string clientDomainRaw = IPGlobalProperties.GetIPGlobalProperties().HostName;
                IdnMapping mapping = new IdnMapping();
                try
                {
                    clientDomainRaw = mapping.GetAscii(clientDomainRaw);
                }
                catch (ArgumentException) { }

                // For some inputs GetAscii may fail (bad Unicode, etc).  If that happens
                // we must strip out any non-ASCII characters.
                // If we end up with no characters left, we use the string "LocalHost".  This 
                // matches Outlook behavior.
                StringBuilder sb = new StringBuilder();
                char ch;
                for (int i = 0; i < clientDomainRaw.Length; i++)
                {
                    ch = clientDomainRaw[i];
                    if ((ushort)ch <= 0x7F)
                        sb.Append(ch);
                }
                if (sb.Length > 0)
                    clientDomain = sb.ToString();
                else
                    clientDomain = "LocalHost";
            }
        }
Example #33
0
        public void EmbeddedDomainNameConversion()
        {
            var idn = new IdnMapping();

            Assert.Equal("abc.xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 0));
            Assert.Equal("abc.xn--d9juau41awczczp", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 0, 11));
            Assert.Equal("abc.xn--d9juau41awczczp.", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 0, 12));
            Assert.Equal("abc.xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 0, 21));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 3));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 3, 8));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 3, 9));
            Assert.Equal("xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 4));
            Assert.Equal("xn--d9juau41awczczp", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 4, 7));
            Assert.Equal("xn--d9juau41awczczp.", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 4, 8));
            Assert.Equal("xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 4, 17));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 11));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 11, 10));
            Assert.Equal("xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 12));
            Assert.Equal("xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 12, 9));
        }