请检查下面的代码。这是我的ASP.NET Core 2.1 MVC应用程序的控制器。
问题是我已经在使用经过cookie身份验证的用户,但是 <script type="text/javascript">
$(function () {
$(document).scroll(function () {
var $nav = $(".navbar-fixed-top");
$nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
});
$('.count').each(function () {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 7000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
$(document).ready(function () {
var $form = $('.newsletter');
if ($form.length > 0) {
$('form input[type="submit"]').bind('click', function (event) {
if (event) event.preventDefault();
register($form);
});
}
});
function register($form) {
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
cache: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
error: function (err) {
alert(
"Could not connect to the registration server. Please try again later."
);
},
success: function (data) {
if (data.result != "success") {
// Something went wrong, do something to notify the user. maybe alert(data.msg);
} else {
// It worked, carry on...
}
}
});
}
$(document).ready(function () {
$('.customer-logos').slick({
slidesToShow: 4,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 1500,
arrows: false,
dots: false,
pauseOnHover: false,
responsive: [{
breakpoint: 768,
settings: {
slidesToShow: 4
}
}, {
breakpoint: 520,
settings: {
slidesToShow: 3
}
}]
});
});
});
})
</script>
</head>
<body>
<div class="top-bg" style="position:relative;">
<p class="text-uppercase-1" data-aos="fade-down" data-aos-duration="900" data-aos-delay="100" data-aos-once="true"
data-aos-easing="ease-in-out" id="top-banner-text-1" style="font-family:Karla, sans-serif;">AIRBNB CARES</p>
<form class="newsletter" action="https://airbnbcares.us19.list-manage.com/subscribe/post" method="POST"
autocomplete="off">
<input type="hidden" name="u" value="88baf6d86f9a8faebb5c5ec99">
<input type="hidden" name="id" value="774141a683">
<input type="email" name="MERGE0" id="MERGE0" placeholder="Enter your email address to subscribe!" tabindex="1"
class="newsletter-email" required>
<input type="submit" class="newsletter-submit" name="submit" value="OK">
</form>
</div>
返回null。那我如何才能在.NET Core上获取当前的身份验证用户?
User.Identity.Name
谢谢。
答案 0 :(得分:1)
只需使用它-
var val = User.FindFirst(ClaimTypes.Email).Value;
如果您的声明NameIdentifier是Email,请执行上述操作。这应该工作。更多信息found here