我正在使用VS2010并创建了一个简单的asp.Web表单应用程序,使用Development Server对其进行测试.
我尝试在会话中存储用户数据 - 从sql server查询 - 因为我不想在每个请求中访问数据库.我正在使用'Application_AuthenticateRequest'和'Session_Start'方法.
第一轮:调用AuthenticateRequest.运行以下代码:
public static void Initialize(string login_name, bool force_refresh)
{
HttpSessionState Session = HttpContext.Current.Session;
object o = Session == null ? null : Session["EMPLOYEE_DATA"];
if (force_refresh || o == null || o.GetType() != typeof(Employee) || (o as Employee).login_name!= login_name)
{
_current = UIManager.GetEmployee(login_name);
if (Session != null)
{
Session["EMPLOYEE_DATA"] = _current;
}
}
else
{
_current = (Employee)o;
}
}
Run Code Online (Sandbox Code Playgroud)
_current变量是通过静态属性发布的私有静态字段.在第一轮中,Session是null,我认为没关系,因为Session_Start尚未调用.Session_Start看起来像这样:
protected void Session_Start(object sender, EventArgs e)
{
Session["EMPLOYEE_DATA"] = EmployeeFactory.Current;
}
Run Code Online (Sandbox Code Playgroud)
在下一轮中,当然没有调用Session_Start,但在AuthenticateRequest中我无法访问会话.HttpContext.Current.Session为null,this.Session引用抛出HttpException,表示"会话状态在此上下文中不可用". …
我想显示一个具有以下限制的div:
activeDiv应该删除该类我在codepen上有一个虚拟的例子
因此出现以下问题:
display: initialdisplaydiv 的默认值是block,但这个css不仅适用于div我尝试使用的标签initial.所以我有一个对象层次结构来在asp.net mvc中生成ui控件并尝试获得流畅的api.我做了一些虚拟课,专注于当前的问题.
所以这是"错误的"代码库:
public abstract class HtmlElement { /* ... */ }
public abstract class UIElement : HtmlElement { /* ... */ }
public abstract class ButtonBase : UIElement { /* ... */ }
public class LinkButton : ButtonBase { /* ... */ }
public class ActionButton : ButtonBase { /* ... */ }
public static class HtmlElementExtensions
{
public static T Id<T>(this T item, string id) where T : HtmlElement
{
/* set the id */
return item;
} …Run Code Online (Sandbox Code Playgroud) First I try to explain the circumstances. I store the the filter expression in one column separated by line breaks. The base idea was this:
SELECT
'SELECT ''' + REPLACE(topic_filter,CHAR(10),''' UNION ALL SELECT ''') + ''''
FROM dbo.topic_filter T
WHERE
T.id = @id
FOR XML PATH('')
Run Code Online (Sandbox Code Playgroud)
在此之后,我只需执行此字符串即可将数据放入临时表中.我的问题从这里开始.该片段位于存储过程中,并由多个存储过程使用以生成要填充的基本源.
方法1:
从另一个SP调用此sp以填充临时表.
结果1:
无法嵌套INSERT EXEC语句.(如果我只是用exec dbo调用...样式代码正在工作.如果我尝试在存储过程中调用,我只会收到错误)
方法2:
我把上面的代码放到表值函数中.
结果2:
在函数内无效使用副作用运算符'INSERT EXEC'.(函数本身不编译)
谢谢,
Péter
我想在我的mvc网站上实现流畅的api.我得到了基础知识.所以实现对象库如:
public class UIElement{/*...*/}
public class ButtonBase : UIElement{/*...*/}
public class LinkButton : ButtonBase {/*...*/}
public static class Extensions
{
public static T UIElementMethod<T>(this T element, string title)
where T : UIElement
{
return element;
}
public static T ButtonBaseMethod<T>(this T element, string title)
where T : ButtonBase
{
return element;
}
public static T LinkButtonMethod<T>(this T element, string title)
where T : LinkButton
{
return element;
}
}
Run Code Online (Sandbox Code Playgroud)
但是如何在没有一些flush方法调用的剃刀视图中使用它.
@Html.UIproject().LinkButton()
.UIElementMethod("asd")
.ButtonBaseMethod("asd")
.LinkButtonMethod("asd")
Run Code Online (Sandbox Code Playgroud)
但它返回类的名称.我试图为MvcHtmlString创建一个隐式运算符,但它没有被调用.任何想法如何实现这一点.如何知道它是链和链.我喜欢 Kendo UI的工作方式.
谢谢,
Péter
所以我有一个自定义通用模型绑定器,它同时处理T和Nullable <T>.
但我通过反射自动创建bindigs.我搜索整个应用程序域以查找标记有特定属性的枚举,并且我想要像这样绑定theese枚举:
AppDomain
.CurrentDomain
.GetAssemblies()
.SelectMany(asm => asm.GetTypes())
.Where(
t =>
t.IsEnum &&
t.IsDefined(commandAttributeType, true) &&
!ModelBinders.Binders.ContainsKey(t))
.ToList()
.ForEach(t =>
{
ModelBinders.Binders.Add(t, new CommandModelBinder(t));
//the nullable version should go here
});
Run Code Online (Sandbox Code Playgroud)
但这是抓住了.我无法将Nullable <T>绑定到CommandModelBinder.
我正在考虑运行时代码的生成,但我从来没有这样做,也许市场上还有其他选择.任何想法实现这一目标?
谢谢,
Péter