我在IIS 6.0中运行ASP.NET 2.0应用程序.我希望会话超时为60分钟,而不是默认的20分钟.我做了以下事情
我仍然在20分钟时获得会话超时.还有什么我需要做的吗?
我在Windows Server 2012 R2上的IIS 8.5中,我想看看会话超时是什么.
在"功能视图"下,我看到一个会话类别,所以我打开它.会话状态设置为进程中.在窗口的下方,我看到了设置超时的选项,但它们是用于cookie的.我查看了应用程序池,看到空闲超时设置为20分钟:这是会话超时吗?我已经习惯了IIS 7,点击"ASP"功能并将其设置在那里.
我们正在整个应用程序中使用Ajax调用 - 尝试在尝试执行任何Ajax请求时,如果会话已经过期,则尝试找到重定向到登录页面的全局解决方案.我编写了以下解决方案,从这篇文章中获取帮助 - 在ajax调用中处理会话超时
不确定为什么在我关心的事件中"HandleUnauthorizedRequest"没有被解雇.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CheckSessionExpireAttribute :AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
var url = new UrlHelper(filterContext.RequestContext);
var loginUrl = url.Content("/Default.aspx");
filterContext.HttpContext.Session.RemoveAll();
filterContext.HttpContext.Response.StatusCode = 403;
filterContext.HttpContext.Response.Redirect(loginUrl, false);
filterContext.Result = new EmptyResult();
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器操作中使用Above自定义属性如下:
[NoCache]
[CheckSessionExpire]
public ActionResult GetSomething()
{
}
Run Code Online (Sandbox Code Playgroud)
AJAX Call(JS部分):
function GetSomething()
{
$.ajax({
cache: false,
type: "GET",
async: true,
url: "/Customer/GetSomething",
success: function (data) {
},
error: function (xhr, …Run Code Online (Sandbox Code Playgroud) 应用程序在几秒钟后自动注销,我想将其增加到30分钟.
我在web.config文件中完成了一些代码,但它不起作用.我已经研究了很多文章,但我无法解决它.
Web.config代码:
<sessionState mode="InProc" timeout="1800"></sessionState>
<authentication mode="Forms">
<forms loginUrl="~/Login" timeout="1800">
</forms>
</authentication>
Run Code Online (Sandbox Code Playgroud) 我已经尝试使用web.config和UseCookieAuthentication()方法上的所有设置,如下面列出的许多Web主题所示:
但是,尝试将这些配置或方法中所有选项的会话超时更改为1分钟(用于测试)没有任何意义,我不确定错误在哪里。以下是我更改的配置。有解决问题的主意吗?我还需要弄清楚在MVC应用程序中设置会话超时的最佳方法是什么:在web.config或Auth类中?
web.config:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" executionTimeout="60" />
<sessionState mode="InProc" timeout="1" />
<!-- For LDAP -->
<httpCookies httpOnlyCookies="true" />
<authentication mode="Forms">
<!-- Note: I also remove this part and try with only "sessionState" -->
<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="1"
slidingExpiration="false" protection="All" />
</authentication>
</system.web>
Run Code Online (Sandbox Code Playgroud)
Startup.Auth.cs:
public void ConfigureAuth(IAppBuilder app)
{
// Code removed for brevity.
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = …Run Code Online (Sandbox Code Playgroud) authentication asp.net-mvc session session-state session-cookies
我需要在.net MVC中创建类似会话变量的东西.我正在使用ViewData.首先我在Controller Index中设置它:
public ActionResult Index(int id)
{
ViewData["myID"] = id;
}
Run Code Online (Sandbox Code Playgroud)
然后,我需要在同一控制器的另一个功能中使用它.但是,我必须把它发送给我.将数据存储到.然后再读一遍.视图:
<input type="hidden" id="myID" name="myID" value='@ViewData["myID"]' />
Run Code Online (Sandbox Code Playgroud)
我得到id的控制器的其他功能:
[HttpPost, ValidateInput(false)]
public ActionResult Test(FormCollection form)
{
var pId = form["myID"];
}
Run Code Online (Sandbox Code Playgroud)
它有效,但看起来不对(我是.net mvc中的新手).有没有办法我可以在我的控制器中设置此ID一次,然后在需要时读取/获取它?
谢谢