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 中可以直接使用.本文旨在提供可参考的代码,不会涉及这方面太多理论的知识. 本 ...
随机推荐
- 50.Maximal Square(最大正方形)
Level Medium 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square conta ...
- SpringBoot2.x整合定时任务和异步任务处理
SpringBoot2.x整合定时任务和异步任务处理 一.项目环境 springboot2.x本身已经集成了定时任务模块和异步任务,可以直接使用 二.springboot常用定时任务配置 1.在启动类 ...
- windows server 2012 R2修改默认远程端口
因客户现场网络复杂,将windows系统的默认远程端口3389归入安全策略中,所以服务器需要修改此端口,配置如下: 首先:登录操作系统,win+R调出运行菜单后输入regedit, 进入注册表编辑相关 ...
- 创建Uboot 环境变量 bin 文件
As we know, the bootloader stores its configuration into an area of the flash called the environment ...
- springmvc.xml标配配置
这里提供配置模板[绝不会多余]: <context:component-scan base-package="com.atguigu"></context:com ...
- 如何给 List 集合排序
一,List<Integer>的排序示例代码:List<Integer> list = new ArrayList<Integer>();list.add(6);l ...
- 理解Java的Class类、"this."关键字、Constructor构造器(一)
import java.util.*; public class BookTest { public static void main(String[] args) { //Book book = n ...
- Java排序算法 [选择、冒泡、快排]
选择排序: 简述:从数组的第一个元素开始,依次与其他所有的元素对比,如果比自身大或小(取决于升序或降序)交换位置. package com.sort; import java.util.Arrays; ...
- boost scope exit
Boost.ScopeExit provides the macro BOOST_SCOPE_EXIT, which can be used to define something that look ...
- php floor()函数 语法
php floor()函数 语法 floor函数是什么意思? php floor()函数用来向下舍入为最接近的整数.语法是floor(number),表示返回不大于参数number的下一个整数,有小数 ...
