我有一个 ASP MVC 页面,当会话过期时需要重定向到登录页面。如果用户位于页面中且会话过期,并且用户刷新页面,则用户将被重定向到登录页面。但是,如果用户单击按钮,页面永远不会重定向到登录页面。我在每个控制器操作方法中都有一个自定义 ActionFilter 来检查会话,并且我使用“RedirectToRouteResult”对象来重定向页面,但是它似乎仅在用户刷新页面时才起作用,而不是在单击按钮时起作用。
这是我的自定义操作过滤器:
public class CustomCheckSessionOutAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string actionName = filterContext.ActionDescriptor.ActionName.ToLower().Trim();
//Check Start with
if (!actionName.StartsWith("Login") && !actionName.StartsWith("LogOff"))
{
var session = HttpContext.Current.Session["LoggedInUserInfo"];
//Redirects user to login screen if session has timed out
if (session == null)
{
base.OnActionExecuting(filterContext);
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
{
controller = "Account",
action = "Login",
returnUrl = ((HttpRequestWrapper)((HttpContextWrapper)filterContext.HttpContext).Request).Url
}));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是控制器中操作方法的示例:
[Authorize(Roles = "Client")]
[CustomCheckSessionOut]
public ActionResult GetOrders([DataSourceRequest] DataSourceRequest …
Run Code Online (Sandbox Code Playgroud) 我有一个存储过程.我在哪里传递一个布尔值,例如IS_ELIGIBLE.现在我希望能够编写如下的查询:
SELECT col1,
CASE
WHEN IS_ELIGIBLE THEN col2 * 100
ELSE
col2 * 50
END
INTO OUT_COL1, OUT_SCORE
FROM TABLE_NAME
Run Code Online (Sandbox Code Playgroud)
问题是因为IS_ELIGIBLE不是TABLE_NAME中的列之一,查询错误输出.我可以使用if..else ie编写相同的查询.
IF IS_ELIGIBLE
SELECT col1, col2 * 100
ELSE
SELECT col1, col2 * 50
END
Run Code Online (Sandbox Code Playgroud)
但我会重复两次选择声明.我知道我可以创建具有select语句的函数,这样我就不必重复两次了.但我只是好奇是否可以在不执行if..else或创建新功能的情况下完成?谢谢.
如何使用SQL Server Management Studio查看SQL Server数据库中的所有功能(内置)?
我试图在我的代码中使用扩展名(例如Employee.cs或Employee.aspx.cs)获取类名.我能够获得没有扩展名的类的名称,但是有人知道我怎么能得到类的扩展?
这就是我为了获得类名而做的事情:
var frame = new StackFrame(1);
string className = frame.GetMethod().ReflectedType.Name;
Run Code Online (Sandbox Code Playgroud) 无论如何,我们可以通过时间戳找出谁在Sitecore CMS中登录和注销?
谢谢.
Sanjeev
假设我有一个Employee
班级:
public class Employee
{
public string Name { get; set;}
public string Address { get; set ;
}
Run Code Online (Sandbox Code Playgroud)
现在我想用Employee
类'属性名创建一个数组,即:
string[] employeeArray = { "Name", "Address" };
Run Code Online (Sandbox Code Playgroud)
有没有办法在没有硬编码属性名称的情况下实现这一目标?
c# ×3
.net ×2
reflection ×2
sql ×2
sql-server ×2
asp.net-mvc ×1
class ×1
function ×1
kendo-ui ×1
oracle ×1
plsql ×1
properties ×1
redirect ×1
session ×1
sitecore ×1
sitecore6 ×1
stack-frame ×1