473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

HttpContext.Current.User.Identity.Name

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
Oct 11 '06 #1
2 7067
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" <br******@hotmail.comwrote in message
news:ee***************@TK2MSFTNGP05.phx.gbl...
| 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
|
|
Oct 11 '06 #2
>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" <br******@hotmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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" <br******@hotmail.comwrote in message
news:ee***************@TK2MSFTNGP05.phx.gbl...
| 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
|
|


Oct 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Giovanni Bassi | last post by:
Hello Group, I using impersonation on my web app. I am explicitely setting the User with the identity element in the web.config like this: <identity impersonate="true" userName="MyUsr"...
4
by: Dan Bart | last post by:
I am using an application which is a modification of IBuySpy Portal. It is using Forms authentication. Users login and their name is added to Context Then I use: ...
10
by: kiran_s_rao | last post by:
I have a serious issue that seems to be intermittent with User.Identity.Name. In an environment where about 100+ users are logging on to a site with forms authentication, calling ...
1
by: vvenk | last post by:
Hello: I am trying to initialize a User object at application start: Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started Dim loOutcome...
2
by: nalbayo | last post by:
what's the difference between HttpContext.Current.User.Identity.Name; and Context.User.Identity.Name; thanks!
6
by: Sjaakie | last post by:
Hi, Is HttpContext.Current.User unique for each visitor or is it shared across an application? Have some problems that might have to do with this and found contradictory answers on this...
0
by: D-Someone | last post by:
We have an active directory user that just had her username renamed. When the user is running an application that calls our CurrentUser web service method (which returns the value of...
4
by: Doogie | last post by:
Hi, I am using HttpContext.Current.User.Identity.Name to get a user id from a web application. I then use that as part of a name of a cookie I'm writing. 30 minutes later I do a refresh of this...
0
by: =?Utf-8?B?QW50b25pbyBPJydOZWFs?= | last post by:
We changed a username in AD. The user now logs on to a computer on our network using the new username without any problems. They can not logon using the old username. However, when they access a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.