草庐IT

TYPE_NULL

全部标签

c# - 是否 (HttpContext.Current.User != null) 足以假设 FormsAuthentication 已对用户进行身份验证

在ASP.NET(2.0)应用程序中,我使用FormsAuthentication。在Global.asax/Application_AuthenticateRequest方法中,我检查HttpContext.Current.User是否为空。这是否足以了解表单例份验证cookie是否存在、票证是否过期以及表单例份验证机制是否已完成验证用户的工作?我需要这个,因为我在该应用程序中有某些页面,有时不需要访问身份验证(基于某些条件),我将它们放在web.config中的单独“位置”指令中,以便将它们从“捕获所有”表单例份验证中排除。即我正在尝试检查Application_Authentic

c# - 没有无参数构造函数的类型的 Activator.CreateInstance(Type)

这个问题在这里已经有了答案:CreatinginstanceoftypewithoutdefaultconstructorinC#usingreflection(4个答案)关闭9年前。阅读工作中的现有代码,我想知道这怎么能行得通。我在程序集中定义了一个类:[Serializable]publicclassA{privatereadonlystring_name;privateA(stringname){_name=name;}}在另一个程序集中:publicvoidf(Typet){objecto=Activator.CreateInstance(t);}和那个简单的调用f(typeo

C# DateTime - 如何检查时间部分是否为 NULL?

除了检查小时为0、分钟为0和秒为0之外,是否有任何简单的方法来检查DateTime值的时间部分是否为NULL?谢谢。 最佳答案 我发现这非常可读:varisTimeNull=(myDateTime.TimeOfDay==TimeSpan.Zero); 关于C#DateTime-如何检查时间部分是否为NULL?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7360750/

c# - 如何解决错误 :the type does not appear to implement microsoft. practices.servicelocation.iservicelocator?

我是MVC的新手,我正在关注“AdamFreeman的PROASP.NETMVC4”。我目前正在研究它的第6章。我正在学习如何使用MVC4中的Ninject进行依赖注入(inject)。我已经按照书中的描述创建了应用程序。现在我不明白为什么会出现以下错误:该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator这是我的Controller代码:publicclassHomeController:Controller{privateProduct[]products={newProduct{Name="Kayak",Cate

c# - 错误 : Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

我正在尝试使用该控件从.ascx设置我的.ascx控件的属性。所以在我的一个包含此控件的.aspx中,我有以下代码试图设置我的嵌入式.ascx的ItemsList属性:Itemitem=GetItem(itemID);myUsercontrol.ItemList=newList().Add(item);我尝试设置的.ascx中的属性如下所示:publicListItemsList{get{returnthis.itemsList;}set{this.itemsList=value;}}错误:无法将类型“void”隐式转换为“System.Collections.Generic.List

c# - x :Type not found in user control library

我正在尝试在WPF用户控件库项目中创建一个ResourceDictionary。当我添加以下样式时:我收到一条错误消息:Thetype'x:Type'wasnotfound.Verifythatyouarenotmissinganassemblyreferenceandthatallreferencedassemblieshavebeenbuilt.我将x声明为:xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"当我在WPF应用程序项目中而不是在UserControl库项目中创建资源字典时,这会起作用。知道为什么吗?

c# - jQuery 将 null 而不是 JSON 发送到 ASP.NET Web API

我似乎无法让它工作...我在客户端上有一些像这样的jQuery:$.ajax({type:"POST",url:"api/report/reportexists/",data:JSON.stringify({"report":reportpath}),success:function(exists){if(exists){fileExists=true;}else{fileExists=false;}}});在我的Web.APIController中,我有一个这样的方法:[HttpPost]publicboolReportExists([FromBody]stringreport){b

c# - .Trim() 当字符串为空或 null 时

我正在以json的形式从客户端接收一些数据。我正在写这个:stringTheText;//orwhoulditbebetterstringTheText="";?TheText=((serializer.ConvertToType(dictionary["TheText"])).Trim());如果从json解析的变量返回为空,当我调用.Trim()方法时这段代码会崩溃吗?谢谢。 最佳答案 您可以使用elvis运算符,也称为“空条件运算符”:GetNullableString()?.Trim();//returnsNULLortri

C# 泛型 : Simplify type signature

这个问题在这里已经有了答案:GenericswithGenericParametersandAbstractclass(4个答案)关闭9年前。如果我有一个看起来像这样的通用Item类:abstractclassItem{}还有一个看起来像这样的项目容器:classContainerwhereTItem:Item{}既然TItem依赖于T,是否可以简化Container的类型签名,使其只接受一个类型参数?我真正想要的是这样的:classContainerwhereTItem:Item//thisdoesn'tactuallywork,becauseItemtakesatypeparame

c# - 为什么 WCF/JSON 不为 null 返回值返回 `null`?

根据JSONspec,表示空值的正确方法是文字null。如果是这样,为什么WCF返回空响应而不是null?这是错误还是在某处记录了此行为?完整的重现示例:usingSystem;usingSystem.ServiceModel;usingSystem.ServiceModel.Web;[ServiceContract()]publicclassService1{[OperationContract(),WebGet(ResponseFormat=WebMessageFormat.Json)]publicstringGetSomeString(){return"SomeString";}