Convert string value back to GUID value

I have a guid value that I store in my hidden variable. e.g. (303427ca-2a5c-df11-a391-005056b73dd7)

Now how do I convert the value from this hidden field back to the GUID value (because the method I would call expects the GUID value).

thanks.

+4
source share
7 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. } 
+14
source

You do this quite easily on an attacker by storing the guid in a string. It is trivial to find, say, a page file. Keep it in the Guide and kill two birds with one stone.

+3
source
  string strGuid; strGuid = (your guid here); Guid guid = new Guid(strGuid); 

For more information, MSDN

+2
source

Guid has a constructor for string guides.

 Guid guid = new Guid(myStringGuid); 
+2
source

new Guid (myHiddenFieldString)

+2
source

I think this can be done simply as follows:

 Guid MyGuid = new Guid(stringValue); 
+1
source

In .NET4, you can also use:

 Guid myGuid = Guid.Parse(myGuidString); 

Just a coding issue, but some people find it more intuitive.

0
source

Source: https://habr.com/ru/post/1309414/


All Articles