Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
Uri baseUri = new Uri() giving problem
Posted on: 05 Feb 2013
Uri baseUri = new Uri("http://abc.com/DELHI/CENTRAL_DELHI/A.");

i have the url ending with (.) or dot

but this class remove the (.) from the end of url.

i want that dot in url please give solution its urgent

thanks in advance


mohit
AuthorReply
Re: Uri baseUri = new Uri() giving problem
Posted on: 05 Feb 2013   Accepted Answer
Basically you have to add the below line of code to enable . when using URI

MethodInfo getSyntax = typeof(UriParser).GetMethod("GetSyntax", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
FieldInfo flagsField = typeof(UriParser).GetField("m_Flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (getSyntax != null && flagsField != null)
{
    foreach (string scheme in new[] { "http", "https" })
    {
        UriParser parser = (UriParser)getSyntax.Invoke(null, new object[] { scheme });
        if (parser != null)
        {
            int flagsValue = (int)flagsField.GetValue(parser);
            // Clear the CanonicalizeAsFilePath attribute
            if ((flagsValue & 0x1000000) != 0)
                flagsField.SetValue(parser, flagsValue & ~0x1000000);
        }
    }
}



Now add your uri in the next line
Uri baseUri = new Uri("http://abc.com/DELHI/CENTRAL_DELHI/A.");



Check this

http://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-end

Thanks & Regards,
Santhosh

Please mark this answer as accepted answer if it resolves your problem.
Re: Uri baseUri = new Uri() giving problem
Posted on: 05 Feb 2013  

As I understand RFC2396 '.' are not valid characters in a URI.

The RFC 2396 says in Chapter 2.3. Unreserved Characters:

  unreserved  = alphanum | mark

  mark        = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" 

Please refer

http://msdn.microsoft.com/en-US/library/system.uri.escapedatastring.aspx
http://www.ietf.org/rfc/rfc2396.txt

hope this will help you.


Re: Uri baseUri = new Uri() giving problem
Posted on: 05 Feb 2013  
thanks u very much
mohit

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.