登录后如何在Logo下添加“用户名”

时间:2021-10-05 19:21:24

I’m trying to add a “Username” under the image logo of my webpage after User login. I want to add Session variable here to capture the username and after that want to call the “Session” value in the html code under the logo of my webpage.

用户登录后,我正在尝试在我的网页的图像徽标下添加“用户名”。我想在这里添加Session变量来捕获用户名,之后想要在我的网页标识下的html代码中调用“Session”值。

My C# file code (Main.cs) file name :

我的C#文件代码(Main.cs)文件名:

[ModuleMethodAttribute(Require_Post = true)]
public string Auth(string Username, string Password, string CompanyRpt)
{
    AuthenticationRequest Login = new AuthenticationRequest();

    Login.Username = Username;
    Login.Password = Password;

    //Login.Username = "dev1";
    //Login.Password = "password";

    AuthenticationResult Result = Login.Execute();

    if (Result.Authenticated)
    {
        Result.Commit();
        Instance.Session.Add("CompanyRpt", CompanyRpt);

        HttpContext.Current.Response.Redirect("/index.html");
        return "";
    }
    else
    {
        return "login failure - " + Result.Message;
    }
}

My Navigation HTML file code:

我的导航HTML文件代码:

<nav class="sidenav left hidden-print" role="navigation">
<ul class="menu">
    <li class="user">
        <div class="content">
            Logo will appear here
        </div>

The username should appear under the image that has been called here.

用户名应显示在此处调用的图像下方。

3 个解决方案

#1


1  

If you are using asp.net mvc you can simply do this:

如果你使用的是asp.net mvc,你可以这样做:

<div class="content">
  Logo will appear here
  @if(User.Identity.IsAuthenticated)
  {
    <span class="logo">@User.Identity.Name</span>
  }
</div>

EDIT: as it turns out from the comments, OP is not using ASP.NET (despite having asp.net tags in his/her question at the time of me answering), thus this answer is invalid.

编辑:从评论中看出,OP不使用ASP.NET(尽管在我回答时他/她的问题中有asp.net标签),因此这个答案无效。

#2


0  

If this is ASP.Net form use protected variable in code behind and use it in html inside <%= %>.

如果这是ASP.Net表单,请在后面的代码中使用受保护的变量,并在<%=%>内的html中使用它。

Ex:

// in C# inside your

//在你的C#里面

 protected string _UserName = String.Empty;

 ...

public string Auth(string Username, string Password, string CompanyRpt)
{
  --- 
  _UserName  = "nam---";
 }

In Html

   <div class="content">
        Logo will appear here
     <%=_UserName  %>
    </div>

#3


0  

Thank U all for trying to help me.

感谢大家试图帮助我。

Have figured out the solution for my case.

已经为我的案例找到了解决方案。

I had to "tmc.Add("UserName", Authentication.Contact_First + " " + Authentication.Contact_Last);" to my default.cs file that was invoking the Navigation HTML file.

我不得不“tmc.Add(”UserName“,Authentication.Contact_First +”“+ Authentication.Contact_Last);”到我调用导航HTML文件的default.cs文件。

Then in the Navigation HTML file I had to add this under the code that calls the logo Welcome: {UserName}

然后在导航HTML文件中,我不得不在调用徽标欢迎的代码下添加它:{UserName}

That is it! Now I'm all set to see my name after login!

这就对了!现在我已经准备好登录后看到我的名字了!

#1


1  

If you are using asp.net mvc you can simply do this:

如果你使用的是asp.net mvc,你可以这样做:

<div class="content">
  Logo will appear here
  @if(User.Identity.IsAuthenticated)
  {
    <span class="logo">@User.Identity.Name</span>
  }
</div>

EDIT: as it turns out from the comments, OP is not using ASP.NET (despite having asp.net tags in his/her question at the time of me answering), thus this answer is invalid.

编辑:从评论中看出,OP不使用ASP.NET(尽管在我回答时他/她的问题中有asp.net标签),因此这个答案无效。

#2


0  

If this is ASP.Net form use protected variable in code behind and use it in html inside <%= %>.

如果这是ASP.Net表单,请在后面的代码中使用受保护的变量,并在<%=%>内的html中使用它。

Ex:

// in C# inside your

//在你的C#里面

 protected string _UserName = String.Empty;

 ...

public string Auth(string Username, string Password, string CompanyRpt)
{
  --- 
  _UserName  = "nam---";
 }

In Html

   <div class="content">
        Logo will appear here
     <%=_UserName  %>
    </div>

#3


0  

Thank U all for trying to help me.

感谢大家试图帮助我。

Have figured out the solution for my case.

已经为我的案例找到了解决方案。

I had to "tmc.Add("UserName", Authentication.Contact_First + " " + Authentication.Contact_Last);" to my default.cs file that was invoking the Navigation HTML file.

我不得不“tmc.Add(”UserName“,Authentication.Contact_First +”“+ Authentication.Contact_Last);”到我调用导航HTML文件的default.cs文件。

Then in the Navigation HTML file I had to add this under the code that calls the logo Welcome: {UserName}

然后在导航HTML文件中,我不得不在调用徽标欢迎的代码下添加它:{UserName}

That is it! Now I'm all set to see my name after login!

这就对了!现在我已经准备好登录后看到我的名字了!