我正在为我的ASP.NET 3.5 MVC 2项目编写一个Session过期的逻辑片段来注销用户并将它们重定向到AccountController LogOn操作.
我对所有关心会话状态的操作都有以下属性,这段代码适用于IE 8,但不适用于Firefox 4或Google Chrome 10.症状是当我尝试导航到由操作表示的视图时我的[SessionExpireFilter]属性,下面代码中的ctx.Session.IsNewSession属性每次都评估为"true",即使我在30分钟的会话中只有几秒钟.
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
// check if session is supported
if (ctx.Session != null && ctx.Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out
string sessionCookie = ctx.Request.Headers["Cookie"];
if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
{
FormsAuthentication.SignOut();
ctx.Response.Redirect("~/Account/LogOn");
}
}
base.OnActionExecuting(filterContext);
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个 VS2010 解决方案,其中包含一个“hello world”WPF 应用程序和一个类库项目。在我的类库中,我在名为 ReportImageMerge.Core 的命名空间中定义了一个类。我的 WPF 应用程序项目引用了该项目,但是当我运行构建时,出现了几个错误。其余是对我的自定义命名空间中的对象的引用的父错误是这样的:
Error 3 The type or namespace name 'Core' does not exist
in the namespace 'ReportImageMerge' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我删除项目引用并将其添加回来,我的错误与所有红色波浪线一起消失。只有当我重建时,我才会重新看到错误。命名空间和类定义如下:
namespace ReportImageMerge.Core.Business
{
public class ReportHelper
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
类和名称引用如下:
using ReportImageMerge.Core.Business;
namespace ReportImageMerge.Reporter
{
public partial class MainWindow : Window
{
public ReportHelper ReportHelper { get; set; }
...
}
}
Run Code Online (Sandbox Code Playgroud)
我发现的与我的问题相关的唯一信息似乎以目标框架为中心。WPF 应用程序默认设置为“.NET Framework 4 Client Profile”,类库设置为“.NET Framework 4”。对于使用 Silverlight 项目引用类库的人,大多数建议是使用特定于 Silverlight 的类库。WPF 应用程序项目似乎并不相同。
我已经看到了将引用项目的目标框架更改为与引用的应用程序相同的建议,但如果我这样做,我会收到未指定的运行时错误。
构建解决方案后,如何识别类库命名空间?