asp.net mvc session, filter 应用研究
2011-08-17 15:39 CuiWenKe 阅读(818) 评论(0) 编辑 收藏 举报参考:
- http://api.jquery.com/ajaxError/
- http://stackoverflow.com/questions/123726/401-response-code-for-json-requests-with-asp-net-mvc
- http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages
- http://archive.cnblogs.com/a/1814714/
- http://www.open-china.net/blog/87546.html
- http://blog.bandao.cn/archive/28359/index.aspx?tags=filter
- http://msdn.microsoft.com/zh-cn/library/h6bb9cz9(v=vs.80).aspx
- http://blog.csdn.net/y_h_t/article/details/6086573
- http://stackoverflow.com/questions/859309/session-end-in-asp-net-mvc
- http://stackoverflow.com/questions/2373209/when-is-session-end-called-in-asp-net-mvc
- http://hi.baidu.com/chen_claire/blog/item/c29cbbeedf2c2b1cfdfa3cf9.html
Jquery handleSuccess handleError
方式名称
存储方式
性能
Off
设置为不使用Session功能
无
InProc
设置为将Session存储在进程内,就是ASP中的存储方式,这是默认值。
性能最高
StateServer
设置为将Session存储在独立的状态服务中。通常是aspnet_state.exe进程.
性能损失10-15%
SQLServer
设置将Session存储在SQL Server中。
性能损失10-20%
Customer
自定制的存储方案
由实现方式确定
private const string AjaxTempKey = "__isAjax";
public bool IsAjax { get { return Request.IsAjaxRequest() || (TempData.ContainsKey(AjaxTempKey)); } }
protected override RedirectResult Redirect(string url)
{
ensureAjaxFlag();
return base.Redirect(url);
}
protected override RedirectToRouteResult RedirectToAction(string actionName, string controllerName, System.Web.Routing.RouteValueDictionary routeValues)
{
ensureAjaxFlag();
return base.RedirectToAction(actionName, controllerName, routeValues);
}
protected override RedirectToRouteResult RedirectToRoute(string routeName, System.Web.Routing.RouteValueDictionary routeValues)
{
ensureAjaxFlag();
return base.RedirectToRoute(routeName, routeValues);
}
private void ensureAjaxFlag()
{
if (IsAjax)
TempData[AjaxTempKey] = true;
else if (TempData.ContainsKey(AjaxTempKey))
TempData.Remove(AjaxTempKey);
}
$(document).ready(function(){
var currentUrl = (location.href).replace("http://", "");
var currentUrlArr = currentUrl.split("/");
var folderLen = currentUrlArr.length - 3;
var urlRightStr = "";
//这里用来处理getSessionValueAJAX.asp文件的相对路径
for (var i = 0; i < folderLen; i++){
urlRightStr += "../";
}
$.ajax({
type:"POST",
async:false,
url:urlRightStr+"getSessionValueAJAX.asp?r="+getRandom(),
success: function(data){
if (data == "out"){
window.parent.location = urlRightStr+"login.asp";
}
}
});
});
<% if (session("login_name") = "" ) then
response.Write("out")
else
response.Write("on")
end if
%>