在后面的aspx页面函数的返回值打印code [英] Print code behind function return value in aspx page

查看:161
本文介绍了在后面的aspx页面函数的返回值打印code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这是微不足道的,但为什么不是在我的ASP.NET页面中内嵌的Windows身份验证用户打印?

背后的功能code:

 公共字符串GetCurrentUserWindowsLogin()
{
    字符串windowsLogin = Page.User.Identity.Name;
    INT hasDomain = windowsLogin.IndexOf(@\\);
    如果(hasDomain大于0)
    {
        windowsLogin = windowsLogin.Remove(0,hasDomain + 1);
    }
    返回windowsLogin;
}

在线code:

 < D​​IV CLASS =loginDisplay><%#GetCurrentUserWindowsLogin()%GT; < / DIV>


<格CLASS =h2_lin>解决方案

的<$ C C>和LT;%#......%&GT; 用于的绑定前pressions 的如评估绑定

所以,如果你叫的Page.DataBind()的Page_Load 它应该工作。

这应该工作的另一种方法是使用 code呈现块这正常运行code:

&LT;%GetCurrentUserWindowsLogin()%GT;

&LT; %=%&GT; 结构中使用的信息小块:

&LT;%= GetCurrentUserWindowsLogin()%GT;

I'm sure this is trivial, but why isn't the Windows Authentication user printing in my ASP.NET page inline?

Code behind function:

public string GetCurrentUserWindowsLogin()
{
    string windowsLogin = Page.User.Identity.Name;
    int hasDomain = windowsLogin.IndexOf(@"\");
    if (hasDomain > 0)
    {
        windowsLogin = windowsLogin.Remove(0, hasDomain + 1);
    }
    return windowsLogin;
}

Inline code:

<div class="loginDisplay">[ <%#GetCurrentUserWindowsLogin() %> ]</div>

解决方案

The <%#... %> is used for Binding Expressions like Eval and Bind.

So if you call Page.DataBind() in page_load it should work.

Another way that should work is to use code render blocks which run normal code:

<% GetCurrentUserWindowsLogin() %>

or the <%= %> construct used for small chunks of information:

<%= GetCurrentUserWindowsLogin() %>

这篇关于在后面的aspx页面函数的返回值打印code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆