Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string value back to GUID value

Tags:

c#

guid

i have a guid value that i store in my hidden variable. say for eg (303427ca-2a5c-df11-a391-005056b73dd7)

now how do i convert the value from this hidden field back to GUID value (because the method i would be calling expects a GUID value).

thank you.

like image 639
Shrewdroid Avatar asked May 11 '10 12:05

Shrewdroid


4 Answers

Just use the overloaded constructor:

try
{
  Guid guid = new Guid("{D843D80B-F77D-4655-8A3E-684CC35B26CB}");
}
catch (Exception ex) // There might be a more appropriate exception to catch
{
  // Do something here in case the parsing fails.
}
like image 197
ereOn Avatar answered Oct 15 '22 09:10

ereOn


You are making it pretty easy on an attacker by storing the Guid in a string. Trivial to find back in, say, the paging file. Store it in a Guid and kill two birds with one stone.

like image 25
Hans Passant Avatar answered Oct 15 '22 11:10

Hans Passant


    string strGuid;
    strGuid = (your guid here);
    Guid guid = new Guid(strGuid);

For more info, MSDN

like image 44
curtisk Avatar answered Oct 15 '22 10:10

curtisk


Guid has a constructor for string Guids.

Guid guid = new Guid(myStringGuid);
like image 29
Brian R. Bondy Avatar answered Oct 15 '22 11:10

Brian R. Bondy