0

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.

3
  • you could use iis request logging. Commented Sep 7, 2018 at 14:08
  • Why was it downvoted? Commented Sep 7, 2018 at 14:11
  • A .html file is not going to be touched by your server. It's just a file and it will be served to the browser as such. Putting any code in it that is meant to be executed server-side will fail because the server won't even bother parsing it. You'll have to name the file with an .aspx extension in order for the server to take a look at it. Consider checking out this tutorial which has a bare bones aspx page. Commented Sep 7, 2018 at 14:18

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, never thought of that. Worked well.
It is recommended to use Page.User. WindowsIdentity.GetCurrent is something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.