Click to See Complete Forum and Search --> : Empty String?


jpfo
December 9th, 2002, 11:15 AM
Sorry for this question, but i'am a newbie, and i cant get this anwsered on the pages i've consulted.


private void Page_Load(object sender, System.EventArgs e)
{
lblUserName.Text= User.Identity.Name.ToString();
}


Why the lblUserName returns a empty value?

Another question :D , can i have a global string (for the username), that i can call from any place? I've read about using classes, but i had make the NEW "thing" every time i wanted to call it, dont seems very pratical.

Tks in advance.

JP- The VB programmer that wants to progress ;)

MartinL
December 9th, 2002, 11:38 AM
1.)
Are you talking about WebServices???

If so, did you enable windows authentication??? If you didn't you cannot use User property on WebService class.

You can enable windows authentication by inserting these lines in the web.config file:

<security>
<authentication mode="Windows"></authentication>
</security>


2.)
There are nothing as global variables in c#. However you can define class which holds public static variables. Then you don't need to instantiate that class when you want to use those variables:

public class MyVariables
{
public MyVariables() {}

static public string userName = "";
static public int nSomeOtherKvaziGlobalVariable = 0;
}

// Anywhere in your code
public void MethodInSomeClass()
{
string userName = MyVariables.userName;
}


Martin

jpfo
December 10th, 2002, 03:48 AM
Tks Martin for your help in the global string issue.

About the Empty String, i haven't a web service but i want a Win autentication, and i already add the

<authentication mode="Windows" />

in the webconfig file.

But my problem is very simple i have a label 'lblUserName' and when i do:

lblUserName.Text = User.Identity.Name.ToString();

Return=""

but if i do:

lblUserName.Text ="Something else..."

Return="Something else..."

I dont know why this happens since i'am declaring

using System.Security.Principal;


Can you help me figuring this out?
Tks in advance.