我有许多ajax动作的应用程序(使用JQuery.ajax实现),它返回JSON ot html.其中一些应该只有授权用户才能访问,我用[Authorize]
属性修饰它们.对于非ajax操作,如果用户未被授权 - 系统将其重定向到登录页面(在web.config中配置).
但是这不适用于ajax操作,因为如果用户被授权 - 他加载页面,在cookie过期后他没有被授权,而不是html块,它应该替换旧的,他在块内得到我的登录页面.
我知道我可以手动解决这个问题,例如删除[Authorize]属性,如果用户没有授权,则返回特殊的json/empty html.但我不喜欢这个解决方案,因为我需要重写我的所有动作和ajax函数.我想要全局解决方案,允许我不要重写我的操作(可能是自定义授权属性,或某些http未经授权的结果自定义处理).
我想返回状态代码,如果请求是ajax,并且重定向到登录页面,如果请求不是ajax.
asp.net-mvc jquery unauthorized http-status-code-401 asp.net-mvc-3
我在SQL Server 2008 R2中有一个Oracle链接服务器.我需要执行Oracle存储过程(首先使用输出参数,然后在第二个过程中使用输入参数):
CREATE OR REPLACE PROCEDURE my1.spGetDate(CurrentDate OUT VARCHAR2)
IS
BEGIN
-- set output parameter, no select statements
END;
CREATE OR REPLACE PROCEDURE my1.spDeleteOldRecords(CurrentDate IN VARCHAR2)
IS
BEGIN
-- conditional delete from oracle table, no select statements
END;
Run Code Online (Sandbox Code Playgroud)
我没有找到关于这个问题的任何完整文档,只有简单的例子与无参数选择/非选择程序,并想知道,如何调用这些程序,程序选择内部,多参数程序与基本参数类型.
我的global.axax中有代码:
protected void Application_Start()
{
WindsorContainer = new WindsorContainer();
WindsorContainer.Install(FromAssembly.InDirectory(new AssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath)));
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(WindsorContainer.Kernel));
//...
}
Run Code Online (Sandbox Code Playgroud)
当我调试global.asax时,代码FromAssembly.InDirectory(newAssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath))
找到我的所有项目dll(有7个dll).其中3个包含IWindsorInstaller
接口的实现,例如:
class WindsorInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
var services = AllTypes.FromThisAssembly().Where(type => type.Name.EndsWith("Service"));
container.Register(services
.WithService.DefaultInterfaces()
.Configure(c => c.LifestyleTransient()));
container.Register(Component.For<ISession>().ImplementedBy<AspnetSession>().
LifeStyle.Transient);
container.Register(Component.For<ICache>().ImplementedBy<AspnetCache>().
LifeStyle.Transient);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我设置断点时,只有一个安装程序被调用,另外两个被跳过.这很有趣,但我有另一个工作项目,我复制代码.
我有模特:
[Validator(typeof(RegisterValidator))]
public class RegisterModel
{
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string ListOfCategoriess { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和模型验证器:
public class RegisterValidator:AbstractValidator<RegisterModel>
{
public RegisterValidator(IUserService userService)
{
RuleFor(x => x.Name).NotEmpty().WithMessage("User name is required.");
RuleFor(x => x.Email).NotEmpty().WithMessage("Email is required.");
RuleFor(x => x.Email).EmailAddress().WithMessage("Invalid email format.");
RuleFor(x => x.Password).NotEmpty().WithMessage("Password is required.");
RuleFor(x => x.ConfirmPassword).NotEmpty().WithMessage("Please confirm your password.");
}
}
Run Code Online (Sandbox Code Playgroud)
我有验证工厂,应该解决依赖:
public class WindsorValidatorFactory : ValidatorFactoryBase
{ …
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我希望允许用户以2种格式输入双值:使用','或'.' 作为分隔符(我对指数形式不感兴趣).默认值为分隔符'.' 不工作.我希望这种行为适用于复杂模型对象中的所有双属性(目前我使用的是包含标识符和值的对象集合).
我应该使用什么:价值提供商或模型粘合剂?请显示解决我的问题的代码示例.
asp.net-mvc custom-model-binder value-provider asp.net-mvc-3
我正在尝试创建验证,它可以有两个组并在第一次失败时阻止第二次验证(它包含许多规则).
现在我确实在内部和'main validator'中创建了一个私有的"BasicValidation"类,如下所示:
RuleFor(m => m).SetValidator(new BasicValidation()).DependentRules(() => {
//Complex validation
RuleFor(m => m.IdOfSthInDb)
.MustAsync(ItemMustExists)
.WithMessage("Item does not exist.");
});
Run Code Online (Sandbox Code Playgroud)
这样做但我想避免为每个模型创建'BasicValidation'.
我有我的SharePoint页面生成的HTML(剪辑):
<body scroll="yes" onload="if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();" class="v4master" style="overflow: scroll" spellcheck="false">
<form name="aspnetForm" method="post" action="/Lists/List/EditNewForm.aspx?ID=2&Source=https%3A%2F%2Fsp2010-test%2Eatwss%2Ecom%2FLists%2FList%2FAllItems%2Easpx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" style="overflow: scroll">
// some html here
<div id="competenceTotalSum" style="position: absolute; left: 500px; top: 400px; width: 100px; height: 50px; background-color:gray" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("form#aspnetForm").bind("scroll", function(e){
alert("scroll");
$("#competenceTotalSum").css("top", $(this).scrollTop() + 400);
});
});
</script>
// some html here
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
事件scroll
没有解雇.我改变scroll
的属性body
,溢出特性body
和form
,试图结合scroll
事件,以不同的对象(window
,body
,form
).将 …
在我的ASP.NET MVC 4项目中,我有一个我的视图模型的验证器,它包含RuleSets的规则定义.Edit
当所有客户端验证通过时,在Post操作中使用的规则集.Url
和Email
规则集规则集中使用的Edit
规则(您可以在下面看到)和特殊的ajax操作,它们仅相应地验证电子邮件和仅验证Url.
我的问题是视图不知道它应该使用Edit
规则集来生成客户端html属性,并使用default
规则集,它是空的.如何判断视图使用Edit
规则集进行输入属性生成?
模型:
public class ShopInfoViewModel
{
public long ShopId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public string Email { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
验证器:
public class ShopInfoViewModelValidator : AbstractValidator<ShopInfoViewModel>
{
public ShopInfoViewModelValidator()
{
var shopManagementService = ServiceLocator.Instance.GetService<IShopService>();
RuleSet("Edit", () =>
{
RuleFor(x => …
Run Code Online (Sandbox Code Playgroud) validation asp.net-mvc fluentvalidation unobtrusive-validation asp.net-mvc-4
这是我的验证类之一:
public class StocksValidator : AbstractValidator<Stocks>
{
public StocksValidator()
{
RuleFor(x => x.SellerId).GreaterThan(1).WithMessage("SellerId should be greater than 1")
.LessThan(100).WithMessage("SellerId should be less than 100");
RuleFor(x => x.SellerType).GreaterThan(101).WithMessage("SellerType should be greater than 101")
.LessThan(200).WithMessage("SellerType should be less than 200");
RuleFor(x => x.SourceId).GreaterThan(201).WithMessage("SourceId should be greater than 201")
.LessThan(300).WithMessage("SourceId should be less than 300");
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这些消息,例如{field}应该少于{x}应该位于公共位置,而不是这里。但是我不知道如何集中他们?
一种方法是使用所有这些常量字符串创建新的c#文件。这很简单。
在Web API中使用本地化和流畅的验证。这有什么好处。我在哪里可以找到好的教程?
我有太多的文字实用的方法,如MakeShortText(string text, int length)
,RemoveTags(string text)
,TimeAgo(DateTime date)
等.我想从单独的帮助器访问它们,如下例所示:
@Text().MakeShortText(Model.Text, 10)
Run Code Online (Sandbox Code Playgroud)
是否可以创建此类扩展?或者我必须像这样为HtmlHelper做扩展:
@Html.Text().MaksShortText(Model.Text, 10)
Run Code Online (Sandbox Code Playgroud)
?
asp.net-mvc ×6
c# ×4
jquery ×2
.net ×1
asp.net ×1
html ×1
javascript ×1
localization ×1
oracle ×1
razor ×1
scroll ×1
sharepoint ×1
sql ×1
sql-server ×1
unauthorized ×1
validation ×1
view-helpers ×1
windsor-3.0 ×1