【发布时间】:2015-01-16 10:39:09
【问题描述】:
我目前正在构建一个 asp.net 网络应用程序。我想创建一些静态方法作为辅助方法。这是一个好主意还是我以后会遇到问题?没有字段或属性。只是方法,有些有返回类型,有些没有返回类型。
静态方法是在字段和属性等所有用户之间共享还是唯一?
private static string userName;
public static string UserName
{
get
{
if (User.Identity.IsAuthenticated)
{
if (userName == "" || userName == null)
{
userName = User.Identity.Name;
}
return userName;
}
else
{
throw new ArgumentNullException("Illegal Access", "You're not login or authorize to perform such task");
}
}
}
【问题讨论】:
标签: c# asp.net static-methods