我想做一些简单的调试,Azure WebJobs 似乎不再支持 Console.Writeline。
我知道使用 TextWriter 类就是答案,我只是将它注入到我的方法中。我不明白的是我如何调用该方法。我无法使我的 Main 方法签名无效并将其注入那里。
请问我错过了什么?
public static void Main(TextWriter log)
{
//This is is not valid
}
Run Code Online (Sandbox Code Playgroud) 我希望在MVC4中实现自定义客户端验证。我目前使用标准属性(例如在我的模型中)
public class UploadedFiles
{
[StringLength(255, ErrorMessage = "Path is too long.")]
[Required(ErrorMessage = "Path cannot be empty.")]
[ValidPath]
public string SourceDirectory { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
因此,StringLength和Required都自动转换为某些JQuery客户端验证。当前,“有效路径”仅在服务器端起作用。始终需要在服务器端进行验证,因为只有服务器才能验证路径是否有效,而您无法在客户端进行验证。
服务器端代码看起来像
public class ValidPathAttribute : ValidationAttribute, IClientValidatable
{
public string SourceDirectory;
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
string path = value.ToString();
string message = string.Empty;
var fileSystemSupport = new FileSystemSupport(Settings, new WrappedFileSystem(new FileSystem()));
if (fileSystemSupport.ValidateNetworkPath(path, out message))
{
return ValidationResult.Success;
}
return new ValidationResult(message);
}
}
Run Code Online (Sandbox Code Playgroud)
这很好。现在,我希望通过ajax调用来实现,进入“ IClientValidatable”和“ GetClientValidationRules”。我写完书之后
public …Run Code Online (Sandbox Code Playgroud)