我的正则表达式有问题.我已经能够确定正确的瑞典社会安全号码以符合这些标准.
但是如果用户未满18岁,我还想拒绝用户注册.我的reqular表达现在看起来像这样:有没有人遇到与年龄范围瑞典SSN相同的问题?
private const string RegExForValidation =
@"^(\d{6}|\d{8})[-|(\s)]{0,1}\d{4}$";
Run Code Online (Sandbox Code Playgroud)
UPDATE
private const string RegExForValidation = @"^(?<date>\d{6}|\d{8})[-\s]?\d{4}$";
string date = Regex.Match("19970918-1234", RegExForValidation).Groups["date"].Value;
DateTime dt;
[Required(ErrorMessage = "Du måste ange personnummer")]
[RegularExpression(RegExForValidation, ErrorMessage = "Personnummer anges med 10 siffror (yymmddnnnn)")]
public string PersonalIdentityNumber { get; set; }
Run Code Online (Sandbox Code Playgroud)
第二次更新
public class ValidateOfAge : ValidationAttribute
{
public bool IsOfAge(DateTime birthdate)
{
DateTime today = DateTime.Today;
int age = today.Year - 18;
if (birthdate.AddYears(birthdate.Year) < today.AddYears(-age))
return false;
else
return true;
} …Run Code Online (Sandbox Code Playgroud) 我在将文件从客户端上传到 Web api 时遇到问题。我收到此错误“MIME 多部分流意外结束。MIME 多部分消息不完整。” 当我试图阅读多部分内容时,在控制器中。我用 superagent 构建了一个 React JS 客户端,这是我的请求代码:
UploadFiles(files: File[]): Promise.IThenable<any> {
return this.Post("/Payment/files" , {
data: {
files: files
},
headers: {
"Content-Type": "multipart/form-data; boundary=gc0p4Jq0M2Yt08jU534c0p",
"Content-Disposition": "form-data; name=Foo",
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器代码:
[Route("files")]
[HttpPost]
public async Task<HttpResponseMessage> UploadFiles()
{
string root = Path.GetTempPath();
var provider = new MultipartFormDataStreamProvider(root);
Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
MemoryStream tempStream = new MemoryStream();
reqStream.CopyTo(tempStream);
tempStream.Seek(0, SeekOrigin.End);
StreamWriter writer = new StreamWriter(tempStream);
writer.WriteLine();
writer.Flush();
tempStream.Position = 0;
StreamContent streamContent = new StreamContent(tempStream); …Run Code Online (Sandbox Code Playgroud) 当我尝试使用我的应用程序登录时,我遇到了很大的性能问题.该应用程序是Azure中托管的Web api应用程序.我使用反应js作为我的前端.
在我的SimpleAuthorizationprovider中,我将获取用户并向ClaimsIdentity属性添加声明.如果我在本地调试它我第一次登录时只有慢速性能问题,但下次登录登录时是即时访问.当我将它上传到Azure中的测试环境时,每个请求都存在问题.
我已经在Azure中为Web应用程序启用了"Always on"属性.我有时间请求和需要花费很多时间的东西是SimpleAuthorizationprovider中的这段代码
context.Validated(ticket);
Run Code Online (Sandbox Code Playgroud)
它需要我的测试环境15 sek才能授权用户.我的前端也可能有一些延迟.在我的前端,我们使用superagent向web api发出请求.
这是我的启动类中的配置:
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
ConfigureOAuth(app);
var physicalFileSystem = new PhysicalFileSystem(@"./Html");
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = physicalFileSystem,
StaticFileOptions =
{
FileSystem = physicalFileSystem,
ServeUnknownFileTypes = true
},
DefaultFilesOptions = {DefaultFileNames = new[] {"Startup.html"}}
};
app.UseFileServer(options);
// Get your HttpConfiguration.
var config = GetInjectionConfiguration();
config.MessageHandlers.Add(new QueryStringBearerToken());
WebApiConfig.Register(config);
// Setup WebApi
app.UseWebApi(config);
SetupWebApi(config);
Application_Start(config);
config.EnsureInitialized();
}
public void ConfigureOAuth(IAppBuilder app)
{
var oAuthServerOptions = new …Run Code Online (Sandbox Code Playgroud) c# ×3
superagent ×2
.net ×1
asp.net-mvc ×1
azure ×1
file-upload ×1
owin ×1
reactjs ×1
regex ×1