我正在创建一些"记住我"功能,作为登录的一部分.
当我在登录过程中使用以下内容创建持久性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时使用的默认时间长度是多少?
当其中一个可以为空时,如何减去两个日期?
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) 我有一个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
.net-2.0 ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
cookies ×1
datetime ×1
nullable ×1
reflection ×1
remember-me ×1