if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?
if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?
0
悬赏园豆:5
[已解决问题]
浏览: 229次
解决于 2018-05-16 13:27

var user = HttpContext.User;
if (user?.Identity?.IsAuthenticated ?? false)
{ }
else
{ }

如题,求解。
显示帮助
1
? 如果不为null,执行其后的方法;?? 如果为null,返回其后的值。
<div id="answer_option_226950">
<div class="qclear">
<div class="lf green">
收获园豆:<span class="red">5</span>
</div>
<div class="answer_author">
<a class="bluelink linkanswercommenttiny" aid="226950" id="link_answercomment_226950" onclick="showCommentMarkdownEditor('link_answercomment_226950', 0)" href="javascript:void(0);">回复</a>
<span class="v-split">|</span>
<a href="/u/dudu/" class="bluelink">dudu</a>
<span class="v-split">|</span>
<a class="graylink" href="/q/faq#qt">高人七级</a>
<span class="v-split">|</span>园豆:41494
<span class="v-split">|</span>
2018-05-16 10:32
</div>
</div>
</div>
<div class="q_answercomm" id="q_answercomm_226950">
</div>
0
等价于
bool isNull;
if (user != null)
{
if (user.Identity != null)
{
if (user.Identity.IsAuthenticated != null)
{
isNull = user.Identity.IsAuthenticated;
}
}
}
isNull = false;
if (isNull)
{} </span></pre>
<div id="answer_option_226955">
清除回答草稿
<div id="google_ad_bottom">
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function () {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type="text/javascript">
googletag.cmd.push(function () {
googletag.defineSlot('/1090369/cnblogs_question_Q2', [728, 90], 'div-gpt-ad-1436511848662-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
<!-- /1090369/cnblogs_question_Q2 -->
<div id="div-gpt-ad-1436511848662-0" style="height:90px; width:728px;" data-google-query-id="CPeVmvWlrOMCFQcaKgodbM8C7w">
<div id="google_ads_iframe_/1090369/cnblogs_question_Q2_0__container__" style="border: 0pt none;"><iframe id="google_ads_iframe_/1090369/cnblogs_question_Q2_0" title="3rd party ad content" name="google_ads_iframe_/1090369/cnblogs_question_Q2_0" width="728" height="90" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="1" data-load-complete="true"></iframe></div></div>
</div>
</div>
if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?的更多相关文章
- HttpContext.Current.User.Identity.IsAuthenticated
HttpContext.Current.User.Identity.IsAuthenticated=false; HttpContext.Current.User.Identity.Name==&qu ...
- 如何手动让HttpRequestBase.IsAuthenticated 和 HttpContext.User.Identity.IsAuthenticated 为true.
今天为了重写权限验证这块需要重写AuthorizeAttribute 这个属性,看了官方文档:HttpContextBase.User.Identity.IsAuthenticated 这个必须是tr ...
- [Asp.Net] Form验证中 user.identity为false
这个方法可以是user.identity设置为true FormsAuthentication.SetAuthCookie(Username, true); 但是要开启form验证, 在配置文件中 & ...
- httpContext.User.Identity.IsAuthenticated 总是为fasle
验证一直通不过,不知道问题在哪里.这个坑应该只有我自己遇到,记录一下,问题在使用swagger验证的时候出现的(说的很轻松) 如图所示,在swaager文档中,添加认证功能,此时只要我们填下登陆时获取 ...
- if (HttpContext.Current.User.Identity.IsAuthenticated) 权限验证总是true
将浏览器关闭重启. 注:该语句是判断用户是否经过验证.
- ASP.NET Core Identity 实战(4)授权过程
这篇文章我们将一起来学习 Asp.Net Core 中的(注:这样描述不准确,稍后你会明白)授权过程 前情提要 在之前的文章里,我们有提到认证和授权是两个分开的过程,而且认证过程不属于Identity ...
- ASP.NET Core实现OAuth2.0的AuthorizationCode模式
前言 在上一篇中实现了resource owner password credentials和client credentials模式:http://www.cnblogs.com/skig/p/60 ...
- ASP.NET Web API 全局权限和全局异常处理
在开发中,我使用json格式序列化,所以将默认的xml序列化移除 public static class WebApiConfig { public static void Register(Http ...
- ASP.NET MVC:窗体身份验证及角色权限管理示例
ASP.NET MVC 建立 ASP.NET 基础之上,很多 ASP.NET 的特性(如窗体身份验证.成员资格)在 MVC 中可以直接使用.本文旨在提供可参考的代码,不会涉及这方面太多理论的知识. 本 ...
随机推荐
- go 学习之字符串
字符串 字符串是不可变值类型,内部⽤用指针指向 UTF-8 字节数组.默认值是空字符串 "".用索引号访问某字节,如 s[i], i不能是负数.不能⽤用序号获取字节元素指针,&am ...
- db2备份与恢复
备份数据库: 离线备份 1.连接至数据库: db2 connect to test user db2admin using db2admin 2.显示数据库应用状态 db2 list applicat ...
- config maven in intellij IDEA
Config maven in IDEA File ->Settings->Build,Execution.Deployment->build Too ...
- 容器改变/窗口改变重新渲染echarts
是否遇见使用侧边栏菜单收缩/展开,echarts容器大小变化,但是echarts不重新自适应容器.或者,window窗口改变但是echarts不随着改变,针对这两种echarts不自适应的情况,分享下 ...
- JS面向对象——组合使用构造函数模型与原型模型中的隐患
组合使用构造函数模型和原型模型中的问题,使用对象字面量重写原型模型会有隐患(涉及到原型的动态性),如下例: <!DOCTYPE html> <html> <head> ...
- 2018-8-10-git-push-错误-hook-declined-
title author date CreateTime categories git push 错误 hook declined lindexi 2018-08-10 19:16:52 +0800 ...
- H3C F100-S-G2接口配置
网络环境简单一台F100-S-G2(192.168.1.197),一台S3600,三台服务器(同一网段192.168.1~3),实现互通. 其他都不用说了配置成同一网段地址就行,主要说一下F100配置 ...
- Jquery的idTabs使用
http://www.sunsean.com/idTabs/jquery.idTabs.min.js idTabs使用基本介绍如下: 通常的使用方法如下: <div id="usual ...
- docker 运行jenkins及vue项目与springboot项目(二.docker运行jenkins为自动打包运行做准备)
docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...
- 【leetcode】996. Number of Squareful Arrays
题目如下: Given an array A of non-negative integers, the array is squareful if for every pair of adjacen ...
