super 简单。我发现的唯一问题是人们变得空了。我显然已经修复了。但是反斜杠在哪里???!!
params.me = '@HttpContext.Current.User.Identity.Name';
这会返回
"domainUserName" <- Browser
"domain\\UserName" <- Debugging
我期望的是
"domain\UserName" <- Browser
有什么想法吗?
最佳答案
根据您的评论,您使用以下代码来显示用户名:
alert('@HttpContext.Current.User.Identity.Name');
@HttpContext.Current.User.Identity.Name
是一个可以包含“\”反斜杠字符的字符串。该字符在 javascript 中被视为转义字符,在 C# 中也是如此。
在将字符串传递给 Javascript 之前,您需要转义字符串中的“\”字符:
alert('@HttpContext.Current.User.Identity.Name.Replace("\\", "\\\\")')
关于asp.net-mvc - @HttpContext.Current.User.Identity.Name 不显示反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35232712/