iiswindows-identity

Get logged-in user in html page with C# code and without opening in VS?


We have a pure html page running in our IIS, and we would like to know what logged-in users are accessing the page. By "logged-in" users I mean a user that looged on to our intranet in their Windows machine.

It seems that I can't retrieve this information with javascript or html, so I was considering using .net for this, something like the following:

System.Security.Principal.WindowsIdentity.GetCurrent().Name

Is it possible to add server-side code to this HTML page without having to go to Visual Studio to create a solution or project?

I just don't want to have to "convert" this .HTML into an .ASPX just for one line of code. These html pages have tons of javascript charts, and I know something will break if I open it in VS.


Solution

  • No, you can't run server code in HTML.

    You can do the following:

    1. Create ASPX file which runs on the server.

    currentcontext.aspx

    <%@ Page language="c#" %>
    <script language="CS" runat="server">
        void Page_Load(object sender, System.EventArgs e) 
        {
          Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
        } 
    </script>
    
    1. Add iframe to the html page which needs to show the current context.

    yourfile.html

    <iframe src="currentcontext.aspx"></iframe>