Why Context.User.Identity.Name returns blank ?

One of my friends mailed on our INETA User Group mailing list asking that he is unable to recieve the name associated with Windows Identity object in his asp.net web application. He further claimed that he had set “authentication mode” to “windows authentication”.

Following was my response to that:


check that if the current user is authenticated or not. u may try this if block:

if(this.Context.User.Identity.IsAuthenticated)


and if u come to know that the user is not authenticated (which i am sure u will find) then this means that like most of us u have enabled anonymous access. try disabling it and then run ur code by selecting windows authentication mode in your directory security settings in IIS.

 

Enabling Sessions for ASP.NET Web Parts in Sharepoint Portal 2003

To Enable Session State in Sharepoint Portal 2003 you will need to do couple of amendments in the “Web.Config“ placed at the root of your virtual server. (usually available at C:\Inetpub\wwwroot ).

 

Edit your web config file using any editor. (I use Ultra Edit).

 

1) Enabling SessionStateModule:
Find this tage and enable it: (It is disabled/commented by default) 

         

 

2) Enable SessionState:

Enable session state (Set to true):
        


Programmatically check if the session has been enabled on Sharepoint Server or not:
Develop a Web Part and place the following code to test if the session has been enabled or not. Place the following code in your protected override void RenderWebPart(HtmlTextWriter output) method:
 
output.Write(“”);

output.Write(“”);

output.Write(”

“);

output.Write(“

“);

output.Write(“

“);

output.Write(“

“);

output.Write(“

“);

try

{

if( this.Page.Session != null && this.Page.Session.Count > 0)

{

if( this.Page.Session[“UserPass”] == null)

{

output.Write(SPEncode.HtmlEncode(“I dont have the passport for you … “));

this._linkButton.RenderControl(output);

}

else

{

output.Write(SPEncode.HtmlEncode(“Thanks GOD “+this.Page.Session[“UserPass”].ToString()+”! you are logged in ..”));

}

}

else

{

output.Write(SPEncode.HtmlEncode(“I dont have the passport for you … “));

this._linkButton.RenderControl(output);

}

}

catch(System.Exception exp)

{

output.Write(SPEncode.HtmlEncode(“ERROR OCCURED “+exp.Message) );

this._linkButton.RenderControl(output);

}

finally

{

output.Write(“

“);

output.Write(“”);

output.Write(“”);

}

thats it for now.
stay tuned for more!



Hammad Rajjoub,
MVP (Windows Server System – XML Web Services),

User Group Leader – Dot Net Wizards (http://dotnetwizards.blogspot.com),
Chariman UG Relations Committee (
http://inetapakistan.org),
Member Speakers Bureau (
http://mea.ineta.org)

Hello MS MVP Blogs!

Hello Every One,


This is my first blog at MS MVPS.com. I will be sharing my experiences with .NET in general and C#,ASP.NET,XML Web Services, and .Net Servers in particular.


So stay tuned!


 




Hammad Rajjoub,
MVP (Windows Server System – XML Web Services),

User Group Leader – Dot Net Wizards (http://dotnetwizards.blogspot.com),
Chariman UG Relations Committee (
http://inetapakistan.org),
Member Speakers Bureau (
http://mea.ineta.org)