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 中可以直接使用.本文旨在提供可参考的代码,不会涉及这方面太多理论的知识. 本 ...
随机推荐
- 再往DjVu鼓吹者的头上敲一棒子
最近在某论坛又看到有人在鼓吹DjVu,甚至声称拿到PDG就转成DjVu,忍不住想再敲打敲打. 早几年前就已经有人举出过实例,证明PDG.TIFF转DjVu会因为有损压缩而产生错别字,似乎时间长了一堆新 ...
- 重写原生alert,弹出层过一会就消失
window.alert = function(str) { if(document.querySelectorAll("div.shieldClass").length!=0){ ...
- [fw]LINUX中断描述符初始化
LINUX中断描述符初始化 @CopyLeft by ICANTH,I Can do ANy THing that I CAN THink!~ Author: WenHui, WuHan Univer ...
- Linux操作练习
打印显示当前时间,格式是:20181209211008 [root@Centos7 ~]#date "+%Y%m%d%H%M%S" 实现晚上20:30自动关机 [root@Cent ...
- 【串线篇】SpringMvc框架乱码
提交的数据可能有乱码: * 请求乱码: * GET请求:改server.xml:在8080端口处URIEncoding="UTF-8" * POST请求: * ...
- 割边的tarjan算法
与割点唯一一点不同是low[v]>=dfn[u]变为low[v]>dfn[u] 代码如下: bool vis[maxn]; int dfn[maxn],low[maxn]; int cnt ...
- nodejs npm 常用配置
npm install moduleNames : 安装 Node 模块.node安装分为全局模式和本地模式. npm install -g moduleName.npm install expres ...
- linux安装apue.3e
(1)下载源代码,可以去官网下载:http://apuebook.com/code3e.html (2)解压缩源代码文件:tar -zxvf src.3e.tar.gz (3) 安装静态链接库:sud ...
- shell 读取文件的每一行
1.使用while #!/bin/bash while read line do echo $line done < file.txt #!/bin/bash cat file.txt | wh ...
- Least Common Ancestors
/* Least Common Ancestors * Au: Small_Ash */ #include <bits/stdc++.h> using namespace std; con ...
