草庐IT

User_type

全部标签

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# - 如何解决错误 :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# - 如何从 AD DirectoryEntry 获取 DOMAIN\USER?

如何从ActiveDirectoryDirectoryEntry(SchemaClassName="user")对象获取Windows用户和域?用户名在sAMAccountName属性中,但我可以在哪里查找域名?(我不能假设一个固定的域名,因为用户来自不同的子域。) 最佳答案 这假定results是从DirectorySearcher获得的SearchResultCollection,但您应该能够直接从DirectoryEntry获得objectsid。SearchResultresult=results[0];varpropert

C# 泛型 : Simplify type signature

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

c# - Entity Framework 表拆分 : not in the same type hierarchy/do not have a valid one to one foreign key relationship

我正在使用EntityFramework6和代码优先方法,我希望将两个实体放在同一个表中。我做错了什么?[Table("Review")]publicclassReview{publicintId{get;set;}publicPictureInfoPictureInfo{get;set;}publicintPictureInfoId{get;set;}}[Table("Review")]publicclassPictureInfo{[Key,ForeignKey("Review")]publicintReviewId{get;set;}publicReviewReview{get;s

c# - 为什么 ReSharper 告诉我 "User.Identity == null"总是错误的?

我的一个ASP.NETMVC中有一个简单的属性Controller类。我以前见过很多次,所以理解消息的意思,但通常它是完全有道理的。然而,事实并非如此。要获取带下划线的语句,User必须NOT为null,因此检查User.Identity没问题。Identity属性是IPrincipalinterface的一部分,并返回一个继承IIdentity的对象.要继承此接口(interface)或与此相关的任何接口(interface),此属性必须是引用类型,因此可能为null,对吗?那么,为什么我心爱的ReSharper会发出呻吟声? 最佳答案

c# - 是否可以将 Type.GetType 与动态加载的程序集一起使用?

假设我有这么一小段代码:publicstaticvoidLoadSomething(Typet){vart1=Type.GetType(t.AssemblyQualifiedName);vart2=t.Assembly.GetTypes().First(ta=>ta.AssemblyQualifiedName==t.AssemblyQualifiedName);}发生的情况是t1为null而t2为notnull。我很困惑,因为如果我这样调用它......LoadSomething(typeof(SomeObject));然后两者都为空,但我实际做的更像是这样(不是真的,这被大大简化了,