Session WebMatrix WebSecurity:保持用户随机注销
我正在使用WebMatrix并在我的网站上应用了登录系统。我遇到了一个奇怪的问题。我的网站一直在随机注销用户。意外发生。不仅在我的代码中,而且在WebMatrix示例项目中也会发生 我的Web.Config文件是:Session WebMatrix WebSecurity:保持用户随机注销,session,authentication,security,webmatrix,Session,Authentication,Security,Webmatrix,我正在使用WebMatrix并在我的网站上应用了登录系统。我遇到了一个奇怪的问题。我的网站一直在随机注销用户。意外发生。不仅在我的代码中,而且在WebMatrix示例项目中也会发生 我的Web.Config文件是: <?xml version="1.0" encoding="UTF-8"?> <configuration> <appSettings> <add key="loginUrl" value="~/login" /> &l
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="loginUrl" value="~/login" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<sessionState timeout="20" />
<!-- This is for links with incorrect file extensions -->
<!-- This only handles .NET based errors, not classic web like HTML or ASP based extensions -->
<customErrors mode="Off">
<error statusCode="403" redirect="/Shared/Error404.cshtml" />
<error statusCode="404" redirect="/Shared/Error404.cshtml" />
<error statusCode="500" redirect="/Shared/Error500.cshtml" />
</customErrors>
</system.web>
<system.webServer>
<!-- This handles all other types of link errors -->
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/Shared/Error404.cshtml" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
</configuration>
这就是我检查用户是否在安全页面中登录的方式:
if (!WebSecurity.IsAuthenticated) {
Response.Redirect("~/login", true);
}
我在谷歌上搜索了一下,很少有人抱怨WebMatrix WebSecurity会随机注销用户。有时在执行活动时,例如表单提交,有时是简单的url单击
有什么想法或建议吗?有人甚至建议我扔掉Razor,转到MVC,它没有这个问题。我不确定那是不是真的
更新
我的所有安全页面(需要用户登录)顶部都有以下代码。有人认为这会导致问题吗
// Ensure this page is not cached
Response.Expires = -1;
Response.Cache.SetNoServerCaching();
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
谢谢
-法拉兹·阿扎尔(Faraz Azhar)我必须进一步检查,我记得一些古怪的设置增加了cookie的登录时间。以下是我的配置中的内容,我没有看到任何其他有时间的内容:
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="~/error/"></customErrors>
<compilation debug="true" targetFramework="4.0" />
<authentication>
<forms timeout="10080" />
</authentication>
我正在生产环境中使用webMatrix。目前有60个用户登录,因此这不是WebMatrix问题。您使用的是会话过期还是无服务器缓存?请再看一次我的帖子,我已经写了更新。我的绝大多数页面都没有任何回复。根本不打电话。我只在需要安全的页面顶部检查WebSecurity.IsAuthenticated。我也已经尝试过了。毫无疑问,这似乎是一些饼干问题。会话有点过期了之类的。有时几秒钟后,有时几分钟后。它只是随机的,与会话超时无关。Knox是对的-您需要增加表单超时值。这是每个人都在说的。我已经将会话超时设置为20分钟,并将超时设置为10080。没什么区别。
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="~/error/"></customErrors>
<compilation debug="true" targetFramework="4.0" />
<authentication>
<forms timeout="10080" />
</authentication>