I have an ASP script that checks the username of the authenticated user, now I want to pass the username of the authenticated user into a javascript variable/string
ASP:
<%
Function isAuthorized()
Dim ipos
Dim ustring
Dim uname
Dim ilngth
ustring = Request.ServerVariables("AUTH_USER")
ipos = Instr(ustring, "\") + 1
ilngth = Len(ustring) + 1
uname = Trim(Mid(ustring, ipos, ilngth - ipos))
End Function
%>
Javascript:
<script>
var chk = <%uname%>;
alert(chk);
</script>
How can I make this work correctly and where in my code exactly do these elements go?
Set a property to get the username: eg in c# Public string Username{ get { return Page.User.Identity.Name;} }
Call this in JavaScript using <%=Username%>
Try this:
<script>
var chk = "<%= uname %>";
alert(chk);
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.