Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the user's username in my intranet web application in a windows network
    text
    copied!<p>I have a simple HTML page internally which just displays a form and asks the user to fill it out. I want to automatically capture the windows domain username and machine name to submit it together with the data collected in the form.</p> <p>Can I do that on the client side? HTML? JavaScript? Or am I forced to do it on the server side (which I don't know how to do... yet)</p> <p>Users have XP and 7 machines and IE7,8.</p> <p>BTW, I found <a href="https://stackoverflow.com/questions/342088/getting-domain-username-for-web-app-on-intranet-without-loggin-in">this article</a> but I have to confess I don't know where in the page you would enter that "code".</p> <p>Here's the code I'm using that is not working. It calls the JavaScript function, and displays <code>"Username="</code> and in the next line <code>"Done."</code>, but doesn't display the username.</p> <p>And if using Chrome, it displays <code>&lt;%HttpContext.Current.User.Identity.Name%&gt;</code>.</p> <pre><code>&lt;html lang="en"&gt; &lt;head&gt; &lt;script&gt; function get_user_Name() { var username = '&lt;%HttpContext.Current.User.Identity.Name%&gt;'; document.write("Username="); document.write(username); document.write(" &lt;br&gt; Done."); } &lt;/script&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;Training and Development Site&lt;/title&gt; &lt;link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="add-number-to-dnc.html"&gt;Add Phone Number to Dialer Do Not Call list&lt;/a&gt; &lt;br&gt;&lt;br&gt; &lt;button type="button" onclick="get_user_Name()"&gt;Display User Name&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Also - <strong>I'm using WebMatrix / IIS7 Express</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload