Tag: c#

更改ASP.NET的会话状态cookie的到期日期

我正在使用ASP.NET会话状态来跟踪我的网站上登录的用户。 但是,我遇到的一个问题是,默认情况下,ASP.NET会话cookie在浏览器关闭时设置为过期。 http://ahb.me/43e 我尝试使用类似于以下代码的东西设置我自己的ASP.NET_SessionId cookie并修改cookie的到期时间: Response.Cookies[“ASP.NET_SessionId”].Expires = DateTime.Now.AddMonths(1); 这些方法都不起作用,它们都设置了第二个具有相同名称的cookie。 有没有办法改变会话cookie的到期日期?

在web.config中放置连接字符串的位置

我的web.config看起来像这样: 当我在下面添加我的连接字符串时,我得到一个错误,说只允许一个元素。 我应该把我的连接字符串放在哪里?

比较实现IComparable的项目的问题

我正在研究一种扩展方法,它通过特定的选择器找到最小项目。 代码下面 public static T MinBy(this IEnumerable src, Func selector) where K : struct, IComparable, IConvertible { var min = default(K); T minItem = default(T); foreach (var item in src) { var current = selector(item); if (current < min) { min = current; minItem = item; } } return minItem; } 它给出错误Error Operator ‘<' cannot […]

找不到方法:’System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)’

我花了很多时间在我的开发盒上编写这个程序,把它移到我们的生产盒后我得到了下面的错误。 仅仅是一个FYI我无法控制已安装的内容和可安装的内容,我该如何使其工作? 在两台计算机的两个框架下,我们都有v1.0.3705,v1.1.4322,v2.0.50727,v3.0,v3.5,4.0.30319。 我用来创建应用程序的程序也是Visual Studio 2013 Pro。 谢谢 有关调用实时(JIT)调试而不是此对话框的详细信息,请参阅此消息的结尾。 ** * ** exception文本 ** * **** System.MissingMethodException:找不到方法:’System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)’。 at C_Sharp_version.Form1.button4_Click(Object sender,EventArgs e) 在System.Windows.Forms.Forn.En上的System.Windows.Forms.Button.OnClick(EventArgs e)中的System.Windows.Forms.Control.OnClick(EventArgs e)处于System.Windows.Forms.Control的System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) System.Windows.Forms.Button.WndProc上System.Windows.Forms.ButtonBase.WndProc(Message&m)的System.Windows.Forms.Control.WndProc(Message&m)处的.WmMouseUp(Message&m,MouseButtons按钮,Int32单击) (Message&m)System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,IntPtr wparam,IntPtr lparam) ** * ** 已加载的程序集 ** * **** mscorlib程序集版本:4.0.0.0 Win32版本:4.0.30319.239(RTMGDR.030319-2300)CodeBase:file:/// C:/Windows/Microsoft.NET/ Framework / v4.0.30319 / mscorlib.dll —————————————- C夏普版程序集版本:1.0.0.0 Win32版本:1.0.0.0 CodeBase:file:/// gordonc […]

C#中的多重inheritance

当我作为C#开发人员工作时,我知道我们可以通过使用Interface实现multiple inheritance 。 任何人都可以提供链接或代码,了解如何使用C#实现multiple inheritance 。 我想要使​​用Interface在C#实现多重inheritance的代码。 提前致谢。

使用“is”关键字和“null”关键字c#7.0

最近我发现,以下代码在VS2017中编译并按预期工作。 但我找不到任何关于此的主题/文档。 所以我很好奇使用这种语法是否合法: class Program { static void Main(string[] args) { var o = new object(); Console.WriteLine(o is null); o = null; Console.WriteLine(o is null); Console.ReadLine(); } } 顺便说一句,这在VS2015中无效

如果当前副本正在使用,则打开文件的卷影副本

我正在尝试在服务器上备份文件,但其中一些正在使用中,无法打开。 相反,如果当前副本正在使用中,我想打开它们的卷影副本。 我怎样才能做到这一点? 作为参考,我使用的是C#.net 3.5。

在CommandBar的SecondaryCommand上设置图标

我有一个命令栏宽度辅助命令: 为什么不显示喜欢和不喜欢的图标?

Asp.net MVC – 从区域渲染局部视图

我创建了一个区域,可以处理我们所有开发产品中的一些通用的东西,就像登录,HTML助手等。在该区域内,我有一个局部视图,我试图在该区域之外引用。 我已经注册了该地区 public class Routes : AreaRegistration { public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( “Common_default”, “Common/{controller}/{action}/{id}”, new { controller = “Account”, action = “Index”, id = UrlParameter.Optional }); } public override string AreaName { get { return “MvcCommons”; } } } 而现在在常规项目中,我正在尝试引用MvcCommons领域中的一个视图…… TestGrid 但我一直认为没有找到视图。 之前,在创建MVC Commons项目时,我收到了查看错误,但错误告诉我它在区域文件夹和默认视图文件夹中都有查看。 这次,我只获取默认文件夹。 有没有办法实现这个目标? 感谢大家!

如何获取配置元素

直升机 谁能解释我如何从.config文件中获取配置元素。 我知道如何处理属性而不是元素。 例如,我想解析以下内容: <![CDATA[ …. ]]> …. 到目前为止,我的c#代码看起来像这样: public class MyConfiguration : ConfigurationSection { [ConfigurationProperty(“enabled”, DefaultValue = “true”)] public bool Enabled { get { return this[“enabled”].ToString().ToLower() == “true” ? true : false; } } [ConfigurationProperty(“header”)] public string header { ??? } } 它适用于属性,如何处理元素(上面代码中的标题属性)?