Tag: asp.net core

持久保存到Azure表存储时使用POCO

我打算在我的ASP.NET 5(MVC 6)应用程序中使用Azure表存储,并添加了WindowsAzure.Storage NuGet包,但当我注意到所有我需要的模型都需要从Microsoft.WindowsAzure.Storage.Table.TableEntityinheritance时,我感到非常失望.WindowsAzure Microsoft.WindowsAzure.Storage.Table.TableEntity 。 现在我认为最好的解决方案是拥有两组实体并在我的主域对象和用于持久存储到表存储的实体对象之间创建映射。 我不想将WindowsAzure.Storage包添加到我的所有项目中。 弃用的azure-sdk-for-net在某一点上得到了对POCO的支持,但我在目前的WindowsAzure.Storage中没有看到这一点。 这里的最佳做法是什么?

正则表达式默认ASP.NET核心标识密码

注意 :我相信这个问题不是这个问题的重复。 我的问题是处理asp.net核心身份用于密码validation的默认validation规则以及如何制作正则表达式,而链接的问题正在讨论,一般是关于validation密码的行为(这不能解决我的问题) ASP.NET Core启用默认的密码validation 最少8个字符 至少应该有一个号码 至少应该有一个大写字母 至少应该有一个小写字母 应该至少有一个特殊字符(允许哪些特殊字符?) 记住这些条件我尝试制作以下正则表达式,但它不起作用。 ^((?=.*?[AZ])(?=.*?[az])(?=.*?[0-9])|(?=.*?[AZ])(?=.*?[az])(?=.*?[^a-zA-Z0-9])|(?=.*?[AZ])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[az])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$ 即使当点2,3,4,5中的三个条件中的任何一个匹配时,该正则表达式也接受字符串。 但我希望所有条件都应该满足。 我在这做错了什么?

如何在ASP.NET Core 1.0中配置身份validation

我正在尝试向我的应用程序添加身份validation,我已经运行entity framework,但现在我想validation用户,但我遇到了很多问题,在配置构造函数中配置它。 例如,在许多教程中,他们提供的代码不再像我那样工作 // Configure ASP.NET Identity to use our Identity-based application context services.AddAuthentication() .AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); 它告诉我,我需要明确指定类型参数,但这是教程中的内容吗? https://shellmonger.com/2015/05/29/asp-net-mvc5-identity-part-1-the-database/ 我很难理解这样做的正确方法,我想要做的就是在用户登录时对用户进行身份validation。 这是我的project.json “dependencies”: { “EntityFramework.Commands”: “7.0.0-rc1-final”, “EntityFramework.MicrosoftSqlServer”: “7.0.0-rc1-final”, “EntityFramework.Core”: “7.0.0-rc1-final”, “Microsoft.AspNet.Diagnostics”: “1.0.0-rc1-final”, “Microsoft.AspNet.Diagnostics.Entity”: “7.0.0-rc1-final”, “Microsoft.AspNet.Identity”: “3.0.0-rc1-final”, “Microsoft.AspNet.Identity.EntityFramework”: “3.0.0-rc1-final”, “Microsoft.AspNet.Authentication”: “1.0.0-rc1-final”, “Microsoft.AspNet.Authorization”: “1.0.0-rc1-final”, “Microsoft.AspNet.IISPlatformHandler”: “1.0.0-rc1-final”, “Microsoft.AspNet.Mvc”: “6.0.0-rc1-final”, “Microsoft.AspNet.Server.Kestrel”: “1.0.0-rc1-final”, “Microsoft.AspNet.Server.WebListener”: “1.0.0-rc1-final”, “Microsoft.AspNet.StaticFiles”: “1.0.0-rc1-final”, “Microsoft.Framework.CodeGenerators.Mvc”: “1.0.0-beta5”, “Microsoft.Framework.ConfigurationModel.Json”: “1.0.0-beta4”, […]

如何在ASP.NET Core 2.1中获取客户端IP地址

我正在使用Microsoft Visual Studio 2017提供的Angular模板开发ASP.Net Core 2.1。我的客户端应用程序工作正常。 在用户身份validation的竞争之后,我想启动用户会话管理,其中我存储客户端用户IP地址。 我已经在互联网上搜索过这个,但到目前为止还没有找到任何解决方案。 以下是我访问过的一些参考链接: 如何在ASP.NET CORE中获取客户端IP地址? 在ASP.NET Core 2.0中获取客户端IP地址 在ASP.Net Core中获取用户远程IP地址 在我的ValuesController.cs中,我也试过下面的代码: private IHttpContextAccessor _accessor; public ValuesController(IHttpContextAccessor accessor) { _accessor = accessor; } public IEnumerable Get() { var ip = Request.HttpContext.Connection.RemoteIpAddress.ToString(); return new string[] { ip, “value2” }; } 其中ip变量我得到空值并得到此错误 Request.HttpContext.Connection.RemoteIpAddress.Address引发了Type’System.Net.Sockets.SocketException’的exception 你能告诉我如何在ASP.NET Core 2.1中获取客户端IP地址吗?

ASP.NET核心中的FromUriAttribute替换 – 专门用于参数别名?

我有一个带有以下API的MVC控制器: public CustomObject Get([FromUri] float lat, [FromUri(Name=”long”)] float longitude, string userKey = null) 这可以,但需要兼容性垫片,因为不推荐使用FromUri。 如何使用适当的ASP.NET Core API复制longitude参数的“别名”行为?

在ASP.NET Core中使用DirectoryServices

我正在将我的ASP.NET Core RC1应用程序升级到RC2。 我在一些* .cs文件中有一些对System.DirectoryServices和System.DirectoryServices.AccountManagement引用,以便我可以查询LDAP。 但我不知道如何在Project.json文件中的RC2中添加对它的引用。 我尝试的所有东西都给了我更多的错误。 任何帮助表示赞赏。 { “version”: “1.0.0-*”, “buildOptions”: { “emitEntryPoint”: true, “preserveCompilationContext”: true }, “dependencies”: { “Microsoft.NETCore.App”: { “version”: “1.0.0-rc2-3002702”, “type”: “default” }, “Microsoft.AspNetCore.Diagnostics”: “1.0.0-rc2-final”, “Microsoft.AspNetCore.Server.IISIntegration”: “1.0.0-rc2-final”, “Microsoft.AspNetCore.Mvc”: “1.0.0-rc2-final”, “Microsoft.AspNetCore.Mvc.TagHelpers”: “1.0.0-rc2-final”, “Microsoft.AspNetCore.Server.Kestrel”: “1.0.0-rc2-final”, “Microsoft.AspNetCore.StaticFiles”: “1.0.0-rc2-final”, “Microsoft.AspNetCore.Razor.Tools”: “1.0.0-preview1-final”, “Microsoft.EntityFrameworkCore”: “1.0.0-rc2-final”, “Microsoft.EntityFrameworkCore.SqlServer”: “1.0.0-rc2-final”, “Microsoft.EntityFrameworkCore.Tools”: “1.0.0-preview1-final”, “Microsoft.EntityFrameworkCore.SqlServer.Design”: “1.0.0-rc2-final”, “Microsoft.Extensions.Configuration.FileExtensions”: “1.0.0-rc2-final”, “Microsoft.Extensions.Configuration.EnvironmentVariables”: “1.0.0-rc2-final”, “Microsoft.Extensions.Configuration.Json”: “1.0.0-rc2-final”, […]

ServiceFilter和TypeFilter – 注入这些filter有什么区别?

ServiceFilter我们必须在Startup.cs中注册。 TypeFilter是由Microsoft.Extensions.DependencyInjection.ObjectFactory注入的,我们不需要注册那个filter。 那么当我们应该使用ServiceFilter和TypeFilter时?

使用asp-for作为参数的自定义ViewComponent

我想包装这个: 到可重用的ViewComponent,其中属性将是参数: 我能够将asp-for参数传递给viewcomponent: public class EditorViewComponent : ViewComponent { public IViewComponentResult Invoke(ModelExpression aspFor = null) { //when debugging, aspFor has correct value return View(aspFor); } } 但我无法在组件的视图中评估它。 这不起作用: @model Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression 有任何想法吗?

由于缺少定义,在.net Core应用程序上构建失败

我正在尝试使用dotnet build从CLI构建我的.NET Core应用程序,但每次我都会收到此错误: ‘IConfigurationBuilder’不包含’AddEnvironmentVariables’的定义,并且没有可以找到接受类型’IConfigurationBuilder’的第一个参数的扩展方法’AddEnvironmentVariables’(你是否缺少using指令或汇编引用?) 这是Startup.cs中我发生问题的ConfigureServices方法: public void ConfigureServices(IServiceCollection services) { var builder = new ConfigurationBuilder() .AddJsonFile(“config.json”) .AddEnvironmentVariables() .Build(); services.AddEntityFrameworkSqlServer() .AddDbContext(options => options.UseSqlServer(builder[“Data:MyContext:ConnectionString”])); services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders() .AddOpenIddictCore(config => config.UseEntityFramework()); services.AddMvc(); services.AddScoped<OpenIddictManager, CustomOpenIddictManager>(); } 看看这个例子,我发现我的Startup.cs没有明显的错误。 更新我的project.json文件: { “compilationOptions”: { “debugType”: “portable”, “emitEntryPoint”: true, “preserveCompilationContext”: true }, “dependencies”: { “AspNet.Security.OAuth.Validation”: “1.0.0-alpha1-*”, “Microsoft.AspNetCore.Authentication.Cookies”: “1.0.0-rc2-*”, “Microsoft.AspNetCore.Authentication.JwtBearer”: “1.0.0-rc2-*”, “Microsoft.AspNetCore.Diagnostics”: “1.0.0-rc2-*”, “Microsoft.AspNetCore.Hosting”: […]

entity framework核心忽略.Include(..)而没有.ToList(..)间接

如EF Core Documentation中的“加载相关数据”中所述,我们可以使用.Include(..)来急剧地从DbSet加载导航属性(或通用IQueryable链接回EF上下文)。 这意味着,给定以下模型: public class TestEntityA { public int Id { get; set; } public int TestEntityBId { get; set; } public TestEntityB TestEntityB { get; set; } public string BProperty { get { return TestEntityB.Property; } } } public class TestEntityB { public int Id { get; set; } public string Property { […]