Can anybody suggest a way to return the URI without the extra backslashes? I can't believe such a simple problem has consumed hours of my time trying to find an answer to this.
Thanks
public string Get()
{
// Retrieve storage account from connection-string
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
// Create the blob client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Generates a GUID to uniquely identify the container per episode
string guid = Guid.NewGuid().ToString();
// Retrieve a reference to a container
CloudBlobContainer container = blobClient.GetContainerReference(guid);
// Create the container if it doesn't already exist
container.CreateIfNotExist();
return container.Uri.AbsoluteUri;
}
This is actually a correct JSON. This is
reason why slash is escaped in JSON.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
dr1337
0 Points
1 Post
Get() return string with backslashes
Apr 07, 2012 02:23 AM|LINK
I've searched high and low and I cannot understand why my Get() method is returning a URI with backslashes.
The output I obtain from the code snippet below is:
"http:\/\/127.0.0.1:10000\/devstoreaccount1\/ba0b9ee5-235e-4833-811c-4cd71bddb786"
Can anybody suggest a way to return the URI without the extra backslashes? I can't believe such a simple problem has consumed hours of my time trying to find an answer to this.
Thanks
public string Get() { // Retrieve storage account from connection-string CloudStorageAccount storageAccount = CloudStorageAccount.Parse( RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString")); // Create the blob client CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Generates a GUID to uniquely identify the container per episode string guid = Guid.NewGuid().ToString(); // Retrieve a reference to a container CloudBlobContainer container = blobClient.GetContainerReference(guid); // Create the container if it doesn't already exist container.CreateIfNotExist(); return container.Uri.AbsoluteUri; }imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Get() return string with backslashes
Apr 07, 2012 09:55 AM|LINK
This is actually a correct JSON. This is reason why slash is escaped in JSON.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
shahed.kazi
All-Star
17953 Points
3635 Posts
Re: Get() return string with backslashes
Apr 11, 2012 02:34 AM|LINK
Further to imran_ku07 response, you can perform a string.replace(url) to replace the backslashes.
string url = "myurl\/";
url.Replace(@"\", string.Empty);
.NET World |Captcha Control
raghuramn
Member
248 Points
64 Posts
Microsoft
Re: Get() return string with backslashes
Apr 11, 2012 04:58 PM|LINK
or if you are using webapi on the client side, you could do something like
Darrel Mille...
Member
176 Points
56 Posts
Re: Get() return string with backslashes
Apr 13, 2012 01:21 PM|LINK
If you change your action method to look like this, then it will stop returning your string as application/json and return it as text/plain.
public HttpResponseMessage Get() { ... return new HttpResponseMessage() { Content = new StringContent(container.Uri.AbsoluteUri) }; }