string.IsNullOrEmpty[
^] tests strings. It checks for string references that are null, or empty strings. Strings are reference types and can be equal to null like any other reference type.
It is equivalent to
result = SomeString == null || SomeString == String.Empty
.
Since your code
Quote:
if (!String.IsNullOrEmpty(Session["userName"].ToString()))
Here you are already converting the Session["userName"] to string using ToString() function. In this case if the session is null it'll give NullReferanceException, because a null value cannot converted to string.
Try this:
if (Session["UserName"] != null)
{
string s = "Welcome" + Session["userName"].ToString();
}
else
{
Response.Redirect("Login.aspx");
}
--Amit