Click here to Skip to main content
15,936,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please i need help on this c# code.I am trying to convert it to but it is giving error.Please help a noob out.

public const string CartId = "TailSpinSpyWorks_CartID";

public String GetShoppingCartId()
if (Session[CartId] == null)
Session[CartId] = System.Web.HttpContext.Current.Request.IsAuthenticated ?
User.Identity.Name : Guid.NewGuid().ToString();
return Session[CartId].ToString();
[no name] 3-May-13 7:45am    
And we are supposed to guess which error you are getting out of the hundreds that it could be?
CPallini 3-May-13 7:51am    
Not exactly: we are also supposed to guess his conversion code.
[no name] 3-May-13 7:55am    
Or both.

1 solution

I Generally use DeveloperFusion to do small converts like that:[^]
It suggests
Public Const CartId As String = "TailSpinSpyWorks_CartID"
Public Function GetShoppingCartId() As [String]
	If Session(CartId) Is Nothing Then
		Session(CartId) = If(System.Web.HttpContext.Current.Request.IsAuthenticated, User.Identity.Name, Guid.NewGuid().ToString())
	End If
	Return Session(CartId).ToString()
End Function
Which look pretty reasonable.
Share this answer
jamiebones 3-May-13 7:59am    
The error is it underlined the comma after isAuthenticated saying ')' expected.Don't know what that means
OriginalGriff 3-May-13 8:13am    
It means "Developerfusion missed an 'I':
Session(CartId) = IIf(System.Web.HttpContext.Current.Request.IsAuthenticated,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900