小编cda*_*a01的帖子

使用FormsAuthentication持久cookie超时

我正在创建一些"记住我"功能,作为登录的一部分.

当我在登录过程中使用以下内容创建持久性cookie时:

FormsAuthentication.SetAuthCookie("someusername", true);
Run Code Online (Sandbox Code Playgroud)

我的Web.Config看起来如下:

<authentication mode="Forms">
  <forms loginUrl="~/sign-in" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

在要求用户再次提供其登录详细信息之前,cookie有效期为多久?此外,是否/设置持久性cookie时使用的默认时间长度是多少?

asp.net cookies forms-authentication remember-me

13
推荐指数
1
解决办法
2万
查看次数

TimeSpan使用可以为空的日期

当其中一个可以为空时,如何减去两个日期?

public static int NumberOfWeeksOnPlan(User user)
{
    DateTime? planStartDate = user.PlanStartDate; // user.PlanStartDate is: DateTime?

    TimeSpan weeksOnPlanSpan;

    if (planStartDate.HasValue)
        weeksOnPlanSpan = DateTime.Now.Subtract(planStartDate); // This line is the problem.

    return weeksOnPlanSpan == null ? 0 : weeksOnPlanSpan.Days / 7;
}
Run Code Online (Sandbox Code Playgroud)

c# datetime nullable .net-2.0

10
推荐指数
2
解决办法
1万
查看次数

如何使用refection获取动作的http动词属性 - ASP.NET Web API

我有一个ASP.NET Web API项目.使用反射,我如何获得[HttpGet]装饰我的动作方法的Http动词(在下面的例子中)属性?

[HttpGet]
public ActionResult Index(int id) { ... }
Run Code Online (Sandbox Code Playgroud)

假设我的控制器中有上述操作方法.到目前为止,通过使用反射,我已经能够获得Index动作方法的MethodInfo对象,该对象存储在一个名为的变量中methodInfo

我尝试使用以下内容获取http动词,但它不起作用 - 返回null:

var httpVerb = methodInfo.GetCustomAttributes(typeof (AcceptVerbsAttribute), false).Cast<AcceptVerbsAttribute>().SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)

我发现的东西:

我上面的例子来自我正在研究的ASP.NET Web API项目.

看来这[HttpGet]是一个System.Web.Http.HttpGetAttribute

但在常规的ASP.NET MVC项目中,它[HttpGet]是一个System.Web.Mvc.HttpGetAttribute

reflection asp.net-mvc custom-attributes asp.net-web-api

7
推荐指数
1
解决办法
2793
查看次数