how can i add the invalid url (but its valid as it is internal URL) as a valid URL, i am getting an error when i am passing it to System.Uri();
Here is my Uri Code
new System.Uri("mailto:DFO%20ABNS%20Techn/DD-DWA/IND#ADW-NGP", true)
According to this http://www.ietf.org/rfc/rfc6068.txt / should be %-encoded in mailto 'address-part'. .Net will happily take:
new System.Uri("mailto:DFOTechn/DD-DWA/IND#ADW-NGP");
But it is all considered as part of the host.
encoding the '/' characters gives:
new System.Uri("mailto:DFO%20ABNS%20Techn%2FDD-DWA%2FIND#ADW-NGP")
Which .Net correctly parses with ADW-NGP as the host.
Related
My URL is: http://localhost/myApp/app/job/7#/Nmbr
When I tried to get the URL from HttpContext.Request or HttpContext.Current.Request,
the given url is : /myApp/app/job/7
# and everything after this letter are missing? Why? How can I get the real current url?
Http requests do not include anything after # (The browser does not send it with the request.)
# Is intended to allow for parameters to be specified for the browser only (Anchor target location, or with often with web 2.0 JavaScript parameters)
In order to pass parameters to the server use ? that appears before the #
Here is some information regarding fragments (The part of the URL after #)
The Fragment property gets any text following a fragment marker (#) in the URI, including the fragment marker itself. Given the URI http://www.contoso.com/index.htm#main, the Fragment property would return #main.
https://msdn.microsoft.com/en-us/library/system.uri.fragment(v=vs.110).aspx
i like to "open" a (local) customized URI witch is already registered in Windows 8.1.
I can open it, if the Link is embedded in a HTML Mail.
<a href="cobra://goto/addresses/ID=5545">
and it works in Windows Explorer:
cobra://goto/addresses/ID=5545
The ID is sent to the Cobra Application.
I tried to send this URI to the Cobra Application with a WebRequest / FileWebRequest / HttpWebRequest without any Success.
string uriToLaunch = #"cobra://goto/addresses/ID=" + ID;
Uri uri = new Uri(uriToLaunch);
FileWebRequest WebReq = (FileWebRequest)WebRequest.Create(uri);
WebReq.GetResponse();
Error: System.NotSupportedException: "URI prefix is not recognized."
Second try, after I recognized that the URI work with Windows Explorer:
File.Open(uriToLaunch, FileMode.Open);
Error: System.NotSupportedException: "The given path's format is not supported."
Any Suggestions how to do it? I don´t want to build my own URI Parser because Windows knows how to handle it.
you can run a custom URI from C# by calling Process.Start()
eg
System.Diagnostics.Process.Start("uri://here");
The exception is occurring because your uri string is not formatted correctly (you have two prefixes - url: and cobra:)
Try the following:
string uriToLaunch = #"cobra://goto/addresses/ID=" + ID;
I am trying to pass a Uri of new Uri(".example.com")
Invalid URI: The format of the URI could not be determined.
or new Uri("http://.example.com")
Invalid URI: The hostname could not be parsed.
I need to be able to use the CookieContainer.SetCookies function which only has one overload taking a Uri.
According to this page, .NET 4.0 should support dot prefixed cookies now, but it seems the Uri class does not?
In this case, you need to pass a proper uri to the function, and the Uri parser is correctly rejecting the malformed string you are trying to use.
I would advise using the Cookie Constructor that takes 4 parameters - allowing you to set the domain to a dot-prefixed one.
Cookie(string name, string value, string path, string domain);
I'm creating HttpWebRequest with a dynamic URL that can sometimes contain Russian symbols.
And sometimes I'm encounter an issue I not sure how to deal with: While encoding to URL each of RU characters has been converted into URL character-entity equivalents (%20...). Apparently after such conversion URL is becoming too long so HttpWebRequest truncating few last characters so instead of proper HTTP result I'm getting 404 error.
Is there any way to bypass this limitation?
My URL looks like this:
http:\\1.1.1.1\some?page=2&var=тестовое значение строки (this part can be very long)
I'm sending this as a GET since web-app I'm working with is expecting GET request at this point.
The only answer to this is you have to send it in any other way as there is a limit for the length of a query string.
The error 404 or "HTTP Error 414. The request URL is too long." you'll get only because of the length of the query string as the data you are sending is longer than the limit.
refer this: http://forums.asp.net/t/1139751.aspx
I am having a URL in below format
abcd.com/xyz/pqr%2Fss/abc
I want this to be send to server as it is.
When I build Uri using System.Uri it converts it to abcd.com/xyz/pqr/ss/abc
and it fails as I don't have a URL with the specified path.
When I tried with double encoding
(abcd.com/xyz/pqr%252Fss/abc) it send the Uri as it is but it fails as server side it is converted to (abcd.com/xyz/pqr%2Fss/abc)
If you construct your uri as such:
Uri u = new Uri("http://abcd.com/xyz/pqr%2Fss/abc")
Access the encoded string like this:
u.OriginalString
I had this problem too, but I found the solution: when you use HttpUtility.UrlEncode to be sure that the application will read the url right you have to construct the link this way:
http://www.abcd.com/xyz?val=pqr%2Fss
and not like this
http://www.abcd.com/xyz/pqr%2Fss
where pqr%2Fss is the result of the HttpUtility.UrlEncode("SOME STRING")