可能重复:
密码验证(正则表达式?)
我正在研究asp.net MVC 3应用程序,我申请了
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
Run Code Online (Sandbox Code Playgroud)
DataAnnotation到我的密码字段.我想确保密码必须至少为6个字符,不超过18个字符,并且必须至少包含一个大写字母,一个小写字母和一个数字.我是否需要添加正则表达式或DataType.password才能完成所有这些操作?
请建议
我有一个asp.net解决方案,包括
1). asp.net identity server rc 3
2). asp.net Core web api
3). asp.net webform ( not in asp.net core, client)
Run Code Online (Sandbox Code Playgroud)
我没有看到任何带有身份服务器4和Web表单客户端的示例.您能否建议如何使用具有asp.net标识的身份服务器对Web表单用户进行身份验证,然后使用访问令牌调用api?
当我看到身份服务器4的mvc客户端时,它在configure方法中有所有设置,然后像这样调用它
我将如何在webform中应用Authorize属性,以便将我重定向到身份服务器4进行登录,然后在登录后我调用api,如下所示:
如何更改webform的客户端?
new Client()
{
ClientId = "mvcClient",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
ClientSecrets = new List<Secret>()
{
new Secret("secret".Sha256())
},
RequireConsent = false;
// where to redirect to after login
RedirectUris = { "http://localhost:5002/signin-oidc" },
// where to redirect …Run Code Online (Sandbox Code Playgroud) webforms asp.net-identity identityserver3 asp.net-core identityserver4
我正在使用身份服务器4作为令牌服务的asp.net MVC应用程序.我有一个api,它有一些安全的资源.我想为api实现角色(授权).我想确保只有具有有效角色的授权资源才能访问api端点,否则会获得401(未经授权的错误).
这是我的配置:
客户
new Client()
{
ClientId = "mvcClient",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
ClientSecrets = new List<Secret>()
{
new Secret("secret".Sha256())
},
RequireConsent = false;
// where to redirect to after login
RedirectUris = { "http://localhost:5002/signin-oidc" },
// where to redirect to after logout
PostLogoutRedirectUris = { "http://localhost:5002" },
AllowedScopes =
{
StandardScopes.OpenId.Name,
StandardScopes.Profile.Name,
StandardScopes.OfflineAccess.Name,
StandardScopes.Roles.Name,
"API"
}
}
Run Code Online (Sandbox Code Playgroud)
领域
return new List<Scope>()
{
StandardScopes.OpenId, // subject id
StandardScopes.Profile, // first name, last name
StandardScopes.OfflineAccess, // requesting …Run Code Online (Sandbox Code Playgroud) 我创建了一个ASP.NET Web API并将Authorize属性应用于API控制器.现在,我想使用Postman测试它,但我收到了授权错误.
控制器代码是:
[Authorize]
[HttpPost]
public IHttpActionResult Attend([FromBody] int gigId)
{
var attendance = new Attdendance
{
GigId = gigId,
AttendeeId = User.Identity.GetUserId()
};
_context.Attdendances.Add(attendance);
_context.SaveChanges();
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
我的请求看起来像http://prntscr.com/c8wz0b
我正在使用这个先进的Postman休息客户端http://prntscr.com/c8xafd
我如何通过Postman授权?
我有 Visual Studio 2017 企业版,但缺少 asp.net Web 应用程序模板。我的机器上安装了 asp.net core 2。
这是已安装的组件
它在那里,但不知道它们是如何被移除的。
请建议我如何查看 Web 应用程序模板和 asp.net mvc 模板?
谢谢
我有asp.net核心库项目.我想在其中添加连接字符串.我没有启动类.我需要在哪里放置连接字符串以及如何获取它?
请建议.
我正在尝试在我的 Angular 13 项目中安装Angular bootstrap,如下所示:
\nng 添加@ng-bootstrap/ng-bootstrap
\n但是当我在此语句上按 Y 时,我立即收到错误
\n将安装并执行包 @ng-bootstrap/ng-bootstrap@11.0.0。\n您想继续吗?是的
\n错误如下:
\nnpm 错误!代码 ERESOLVE\nnpm 错误!ERESOLVE 无法解析依赖关系树\nnpm ERR!\nnpm ERR! 解决时:blog@0.0.0\nnpm 错误!发现:@angular/compiler@13.0.3\nnpm 错误!node_modules/@angular/compiler\nnpm 错误!来自根项目的 @angular/compiler@"~13.0.0"\nnpm ERR!\nnpm ERR! 无法解决依赖关系:\nnpm ERR!来自 @angular/localize@13.1.3\nnpm 的同行@angular/compiler@"13.1.3" 错误!node_modules/@angular/localize\nnpm 错误!来自 @ng-bootstrap/ng-bootstrap@11.0.0\nnpm 的对等 @angular/localize@"^13.0.0" 错误!node_modules/@ng-bootstrap/ng-bootstrap\nnpm 错误!来自根项目的 @ng-bootstrap/ng-bootstrap@"11.0.0"\nnpm ERR!\nnpm ERR! 修复上游依赖冲突,或重试\nnpm ERR!此命令带有 --force 或 --legacy-peer-deps\nnpm ERR!接受不正确(且可能损坏)的依赖关系解析。\nnpm ERR!\nnpm ERR! 有关完整报告,请参阅 /Users/asifhameed/.npm/eresolve-report.txt。
\nnpm 错误!可以在以下位置找到此运行的完整日志:\nnpm ERR!/Users/asifhameed/.npm/_logs/2022-01-25T04_11_31_152Z-debug.log\n\xe2\x9c\x96 软件包安装失败,请参见上文。
\n以下是我的project.json 文件中的依赖项和开发依赖项。
\n"dependencies": {\n "@angular/animations": "~13.0.0",\n "@angular/common": "~13.0.0",\n "@angular/compiler": "~13.0.0",\n "@angular/core": "~13.0.0",\n "@angular/forms": "~13.0.0",\n "@angular/platform-browser": …Run Code Online (Sandbox Code Playgroud) 我正在研究 asp.net 应用程序。我正在使用 ado.net 访问 SQL Server 数据库并执行 CRUD。我想一次性插入多条记录。为此,我在数据库中添加了一个自定义类型和一个这样的存储过程:
CREATE TYPE [dbo].[UserTableType] AS TABLE
(
[FirstName] [nvarchar](100) NULL,
[LastName] [nvarchar](100) NULL,
[UserName] [nvarchar](100) NULL,
[Password] [nvarchar](100) NULL,
[IsActive] [bit] NULL,
[IsDeleted] [bit] NULL,
[CreatedBy] [int] NULL,
[CreatedAt] [datetime] NULL,
[UpdatedBy] [int] NULL,
[UpdatedAt] [datetime] NULL,
[Email] [nvarchar](100) NULL
)
GO
Run Code Online (Sandbox Code Playgroud)
和存储过程是这样的:
CREATE PROCEDURE [dbo].[sp_InsertUser]
@UserTableType UserTableType READONLY
AS
BEGIN
INSERT INTO tblUser
SELECT * FROM UserTableType
END
Run Code Online (Sandbox Code Playgroud)
在 C# 中,我使用的是以下代码:
public void CreateMultipleUser()
{
var cs = "Server=.;Database=Clicon;Trusted_Connection=True;";
using (SqlConnection …Run Code Online (Sandbox Code Playgroud) 我是弹性搜索的新手。我将数据存储在Azure存储中,我想使用elasticsearch对其进行索引。我已经在https://cloud.elastic.co上创建了一个集群。我是否需要创建一个服务来对弹性云中的数据建立索引,然后用户可以通过弹性搜索使用/搜索该数据?如何使用asp.net MVC将数据索引到弹性云?
请提出建议。
我有以下要求:
密码必须是6-18个字符,并且至少包含一个字母和一个数字.允许使用@,%,&等#等特殊字符.
我创造了这个:
^.*(?=.{6,18})(?=.*\d)(?=.*[A-Za-z])(?=.*[@%&#]).*$
Run Code Online (Sandbox Code Playgroud)
但是它也接受像_这样的其他特殊字符,它要求@%中的一个特殊字符必须在字符串中.我想让这个可选.意味着如果用户输入其中一个特殊字符,则字符串应该有效,但如果用户没有输入这些字符,那么它不应该是无效的.如果用户输入任何其他特殊字符,则字符串应无效.
我正在研究 asp.net 应用程序。我有 4 个角色的 aspnetroles 表:
**Id Name**
1 Admin
4 Consumer
2 Provider
3 SaleUser
Run Code Online (Sandbox Code Playgroud)
在 AccountController Register Action 方法中,我添加了这个:
var user = new ApplicationUser { UserName = model.Email, Email = model.Email};
var result = await UserManager.CreateAsync(user, model.Password);
**UserManager.AddToRole(user.Id, model.UserRole);**
Run Code Online (Sandbox Code Playgroud)
现在我在登录时检查登录操作结果如下:
我看到 aspnetusers 和 aspnetuseroles 表有正确的数据。
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
if (User.IsInRole(model.UserRole))
return RedirectToLocal(returnUrl);
Run Code Online (Sandbox Code Playgroud)
但条件失败。如何检查用户是否属于特定角色。
我在 Startup.cs ConfigureAuth 方法中添加了以下行:
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
Run Code Online (Sandbox Code Playgroud)
和 identityConfig 类中的这个类:
public class ApplicationRoleManager : RoleManager<IdentityRole>
{
public ApplicationRoleManager(IRoleStore<IdentityRole, string> store) …Run Code Online (Sandbox Code Playgroud) 我正在使用 Google Places API 服务(https://developers.google.com/places/web-service/)根据位置名称获取地点 ID。用户键入一些位置名称,就会出现相关建议,用户可以从中选择并获取地点 ID。我有一个要求,我需要三个文本框和一个按钮。用户输入地名、城市名和地址,然后单击按钮获取 placeId。目前,我没有看到基于多个参数获取地点 ID 的选项。我怎样才能做到这一点?
c# ×4
asp.net ×2
asp.net-core ×2
ado.net ×1
angular ×1
api ×1
asp.net-mvc ×1
bootstrap-4 ×1
nest ×1
node.js ×1
npm ×1
postman ×1
regex ×1
sql-server ×1
webforms ×1