Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HttpContext.Current.User.Identity.Name

Reply
Thread Tools

HttpContext.Current.User.Identity.Name

 
 
Abraham Andres Luna
Guest
Posts: n/a
 
      10-11-2006
hello everyone,

does anyone know why i can't access the
HttpContext.Current.User.Identity.Name property in a .cs file?
this is the index.aspx page:

<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(Object Sender, EventArgs E)
{
FormsAuthentication.SetAuthCookie("abe", false);
lblError.Text = IS.Data.GetUSRNA();
}
</script>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:Label ID="lblError" runat="server" />
</form>
</body>
</html>

and this is the .cs file located in the app_code directory:

using System;
using System.Web;
namespace IS
{
public class Data
{
public static string GetUSRNA()
{
return HttpContext.Current.User.Identity.Name;
}
}
}

it doesn't make sense why i wouldn't be able to retreive the user name this
way. maybe i'm missing something.

thank you for your help


 
Reply With Quote
 
 
 
 
Abraham Andres Luna
Guest
Posts: n/a
 
      10-11-2006
i did some searching and read that even if i called
FormsAuthentication.SetAuthCookie("abe", false) to set the user, the
User.Identity.Name property will not be available until the next request. is
there any way to force that property to be populated. otherwise, i'm going
to have to call the setauthcookie, then redirect the page to access the
user.identity.name property.

thank you for your help

"Abraham Andres Luna" <(E-Mail Removed)> wrote in message
news:ee%(E-Mail Removed)...
| hello everyone,
|
| does anyone know why i can't access the
| HttpContext.Current.User.Identity.Name property in a .cs file?
| this is the index.aspx page:
|
| <%@ Page Language="C#" %>
| <script runat="server">
| void Page_Load(Object Sender, EventArgs E)
| {
| FormsAuthentication.SetAuthCookie("abe", false);
| lblError.Text = IS.Data.GetUSRNA();
| }
| </script>
| <html>
| <head runat="server">
| <title>Untitled Page</title>
| </head>
| <body>
| <form runat="server">
| <asp:Label ID="lblError" runat="server" />
| </form>
| </body>
| </html>
|
| and this is the .cs file located in the app_code directory:
|
| using System;
| using System.Web;
| namespace IS
| {
| public class Data
| {
| public static string GetUSRNA()
| {
| return HttpContext.Current.User.Identity.Name;
| }
| }
| }
|
| it doesn't make sense why i wouldn't be able to retreive the user name
this
| way. maybe i'm missing something.
|
| thank you for your help
|
|


 
Reply With Quote
 
 
 
 
Edwin Knoppert
Guest
Posts: n/a
 
      10-12-2006
>the User.Identity.Name property will not be available until the next
>request


Hmm, i use a custom method and i set the identity right after
authentication, that might help you as well.
This is similar (ticket)code as on each request on global.asax.





"Abraham Andres Luna" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
>i did some searching and read that even if i called
> FormsAuthentication.SetAuthCookie("abe", false) to set the user, the
> User.Identity.Name property will not be available until the next request.
> is
> there any way to force that property to be populated. otherwise, i'm going
> to have to call the setauthcookie, then redirect the page to access the
> user.identity.name property.
>
> thank you for your help
>
> "Abraham Andres Luna" <(E-Mail Removed)> wrote in message
> news:ee%(E-Mail Removed)...
> | hello everyone,
> |
> | does anyone know why i can't access the
> | HttpContext.Current.User.Identity.Name property in a .cs file?
> | this is the index.aspx page:
> |
> | <%@ Page Language="C#" %>
> | <script runat="server">
> | void Page_Load(Object Sender, EventArgs E)
> | {
> | FormsAuthentication.SetAuthCookie("abe", false);
> | lblError.Text = IS.Data.GetUSRNA();
> | }
> | </script>
> | <html>
> | <head runat="server">
> | <title>Untitled Page</title>
> | </head>
> | <body>
> | <form runat="server">
> | <asp:Label ID="lblError" runat="server" />
> | </form>
> | </body>
> | </html>
> |
> | and this is the .cs file located in the app_code directory:
> |
> | using System;
> | using System.Web;
> | namespace IS
> | {
> | public class Data
> | {
> | public static string GetUSRNA()
> | {
> | return HttpContext.Current.User.Identity.Name;
> | }
> | }
> | }
> |
> | it doesn't make sense why i wouldn't be able to retreive the user name
> this
> | way. maybe i'm missing something.
> |
> | thank you for your help
> |
> |
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments