如何以声明方式将当前用户传递给Web控件

时间:2022-05-21 15:47:35

I'm creating a control and need to pass it the current logon user as a parameter (declaratively)

我正在创建一个控件,需要将当前登录用户作为参数传递(声明性地)

I tried this but didn't work (I got "<%= User.Identity.Name %>" as value):

我尝试了这个但是没有用(我将“<%= User.Identity.Name%>”作为值):

<cc1:MyControl id="myid" runat="server" User="<%= User.Identity.Name %>" />

Is there a way to do it?

有办法吗?

5 个解决方案

#1


2  

Why do you need to pass it at all?. The user control can access the User.Identity.Name property directly.

为什么你需要通过它?用户控件可以直接访问User.Identity.Name属性。

#2


1  

Inside that control, you will have access to this.Page.User, so that's one way. Another is to use HttpContext.Current.User.

在该控件内,您将可以访问this.Page.User,这是一种方式。另一种是使用HttpContext.Current.User。

#3


1  

You can do this in the codebehind:

您可以在代码隐藏中执行此操作:

myid.User = User.Identity.Name

#4


0  

Try using:

User="<%= User.Identity.Name %>"

%= is for output

%=用于输出

%# is for databinding.

%#用于数据绑定。

#5


0  

Try changing the double quotes in the User attribute to single quotes. I've seen that work in the past...

尝试将“用户”属性中的双引号更改为单引号。我过去见过这个作品......

#1


2  

Why do you need to pass it at all?. The user control can access the User.Identity.Name property directly.

为什么你需要通过它?用户控件可以直接访问User.Identity.Name属性。

#2


1  

Inside that control, you will have access to this.Page.User, so that's one way. Another is to use HttpContext.Current.User.

在该控件内,您将可以访问this.Page.User,这是一种方式。另一种是使用HttpContext.Current.User。

#3


1  

You can do this in the codebehind:

您可以在代码隐藏中执行此操作:

myid.User = User.Identity.Name

#4


0  

Try using:

User="<%= User.Identity.Name %>"

%= is for output

%=用于输出

%# is for databinding.

%#用于数据绑定。

#5


0  

Try changing the double quotes in the User attribute to single quotes. I've seen that work in the past...

尝试将“用户”属性中的双引号更改为单引号。我过去见过这个作品......