Reputation: 3449
How could I get a default depending if the user is logged in or not?
public class ShippingDetails {
public ShippingDetails() {
if (HttpContext.Current.User.Identity.Name != "") {
Name = "";
}
}
public string Name { get; set; }
}
Upvotes: 0
Views: 80
Reputation: 3191
You can also check
if (HttpContext.Current.User.Identity.IsAuthenticated) {
Name = HttpContext.Current.User.Identity.Name;
}
else
{
Name = "Anonymous"
}
Upvotes: 0
Reputation: 69983
You mean get the users login name, otherwise just give them a dummy name? Check if they're logged in using Request.IsAuthenticated
. If they are, grab the username, if not just set it.
if (HttpContext.Current.Request.IsAuthenticated)
Name = HttpContext.Current.User.Identity.Name;
else
Name = "User";
Upvotes: 2