我已经使用 ASP.NET Identity 2.2.1 成功构建了简单的注册系统。
我只需要 API,所以我构建了允许使用 route 创建帐户的简单控制器account/create,当创建帐户时,用户会收到带有确认电话所需的令牌的 SMS 消息,同时我生成验证电子邮件地址所需的链接,我正在将其发送到用户电子邮件地址。然后用户需要从 SMS 输入令牌(向 请求account/confirm_phone)并单击他收到的电子邮件中的链接。
激活账户需要这两个操作,这部分工作正常。
我需要将电子邮件链接更改为电子邮件令牌,类似于用于确认电话号码的令牌,因此用户不必单击链接,而是必须输入该令牌(请求到account/confirm_email)
方法GenerateEmailConfirmationTokenAsync返回很长的代码,成为电子邮件中发送的链接的一部分,我希望它返回 6 位令牌。
我无法重用,GeneratePhoneConfirmationTokenAsync因为这将生成与通过 SMS 发送相同的令牌。
我在互联网上搜索过,但找不到任何关于如何自定义GenerateEmailConfirmationTokenAsync方法生成的令牌的信息。
是否可以配置该令牌生成器,以便它返回 6(或任何可配置长度)数字代码,我可以用它来确认用户电子邮件地址。
我知道将链接发送给用户是更好的选择,但正如我写的那样,这是我得到的要求,我无法改变它。
我正在尝试为我的(.NET 4.6)项目添加服务引用.
当我选择Add Service Reference并添加WSDL的URL时,我可以看到它被正确发现:

我已取消选中Reuse types in all referenced assemblies,如下所示:

但是当我点击时,我OK在错误列表窗口中收到三个警告:
警告1自定义工具警告:无法导入wsdl:portType详细信息:运行WSDL导入扩展时引发异常:System.ServiceModel.Description.XmlSerializerMessageContractImporter错误:无法将类型为"System.Xml.Serialization.StructMapping"的对象强制转换为类型'System.Xml.Serialization.MembersMapping'.XPath到错误源:// wsdl:definitions [@ targetNamespace =' http ://bik.pl/cc/big']/wsdl:portType [@ name ='BIG']
警告3自定义工具警告:无法导入wsdl:port详细信息:导入wsdl:port依赖的wsdl:binding时出错.XPath to wsdl:binding:// wsdl:definitions [@ targetNamespace =' http ://bik.pl/cc/big']/wsdl:binding [@ name ='BIGBinding'] XPath to Error Source:// wsdl:定义[@ targetNamespace =' http : //bik.pl/cc/big ']/wsdl:service [@ name ='BIG']/wsdl:port [@ name ='BIG']
警告2自定义工具警告:无法导入wsdl:binding详细信息:导入wsdl:binding依赖的wsdl:portType时出错.XPath to wsdl:portType:// wsdl:definitions [@ targetNamespace =' http ://bik.pl/cc/big']/wsdl:portType [@ name ='BIG'] XPath to Error Source:// wsdl:定义[@ targetNamespace =' http ://bik.pl/cc/big']/wsdl:binding [@ name …
可以说我有一个包含许多行的表,如下所示:
ID Range Range_begining Profit
----------------------------------------------------
1 (100-150) 100 -20
2 (200-250) 200 40.2
3 (100-150) 100 100
4 (450-500) 450 -90
...
Run Code Online (Sandbox Code Playgroud)
我正在做一个像这样的简单查询:
SELECT max([Range]) AS 'Range'
, count(ID) AS 'Count'
, round(avg([Profit]), 2) AS 'AVG Profit'
FROM
Orders
GROUP BY
Range_begining
Run Code Online (Sandbox Code Playgroud)
运行此查询后,我得到如下结果:
Range Count AVG Profit
------------------------------------
(100-150) 2 40
(200-250) 1 40.2
(450-500) 1 -90
...
Run Code Online (Sandbox Code Playgroud)
非常简单 :)
我现在需要做的是选择具有最小和最大利润的行,其中count大于10(这是一个参数)
我能够获得最低价值:
SELECT TOP 1 [Range], [AVG Profit] FROM (
SELECT max([Range]) AS 'Range'
, count(ID) AS 'Count'
, …Run Code Online (Sandbox Code Playgroud) 我有很长的数组包含数字.我需要从该数组中删除尾随零.
如果我的数组看起来像这样:
var arr = [1,2,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
Run Code Online (Sandbox Code Playgroud)
我想删除除了之外的所有内容[1, 2, 0, 1, 0, 1].
我已经创建了正在做的事情的功能,但我想知道是否有我可以使用的功能构建.
var arr = [1,2,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
for(i=arr.length-1;i>=0;i--)
{
if(arr[i]==0)
{
arr.pop();
} else {
break;
}
}
console.log(arr);
Run Code Online (Sandbox Code Playgroud)
这可以做得更好/更快吗?
我正在为我的表单构建步骤指示器。
我在 codepen 上找到了很好的例子,我正在尝试根据我的需要定制它。
HTML 结构如下所示:
<div class="progress">
<div class="circle done">
<span class="label">1</span>
<span class="title">Order informations</span>
</div>
<span class="bar done"></span>
<div class="circle">
<span class="label">4</span>
<span class="title">Order review</span>
</div>
<span class="bar"></span>
<div class="circle">
<span class="label">5</span>
<span class="title">Finish</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和CSS:
*, *:after, *:before {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family:"Open Sans";
}
/* Form Progress */
.progress {
width: 1000px;
margin: 20px auto;
text-align: center;
padding-bottom: 80px;
}
.progress .circle, .progress .bar {
display: inline-block;
background: #fff;
width: 40px;
height: …Run Code Online (Sandbox Code Playgroud) 这个问题是我上一个问题的延续:使用SMS中的密码登录ASP.Net Identity 2-不使用两因素身份验证
我已经构建了自定义OAuthAuthorizationServerProvider以支持自定义grant_type。
我的想法是创建一个grant_type sms,允许用户生成一次性访问代码,该代码将发送到他的手机,然后在发送带有password_grant_type的请求时作为密码作为用户。
现在,通过SMS生成,存储和发送该密码后,我想返回自定义响应,而不是我的GrantCustomExtension中的令牌。
public override async Task GrantCustomExtension(OAuthGrantCustomExtensionContext context)
{
const string allowedOrigin = "*";
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {allowedOrigin});
if (context.GrantType != "sms")
{
context.SetError("invalid_grant", "unsupported grant_type");
return;
}
var userName = context.Parameters.Get("username");
if (userName == null)
{
context.SetError("invalid_grant", "username is required");
return;
}
var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
ApplicationUser user = await userManager.FindByNameAsync(userName);
if (user == null)
{
context.SetError("invalid_grant", "user not found");
return;
}
var generator = new TotpSecurityStampBasedTokenProvider<ApplicationUser, string>();
await userManager.UpdateSecurityStampAsync(user.Id);
var accessCode = …Run Code Online (Sandbox Code Playgroud) 在 SQL 中,我有主键为 binary(8) 的表。当我使用该表将该表添加到我的模型时,Update Model from Database我可以看到该列具有 type=Binary
在 C# 中,我将该列作为byte[].
我可以将该列映射到 int 吗?
我知道我可以CAST在 SQL 中创建一个视图:
SELECT
Client_Id,
CAST(Client_Id AS INT) AS NewClient_Id,
* /*other columns*/
FROM
dbo.Clients
Run Code Online (Sandbox Code Playgroud)
但这不是解决方案,因为我必须能够写入,而不仅仅是从该表中读取。我知道我可以为插入创建存储过程,但我想避免这种情况。
我使用的是 EntityFramewor 6.1.3。
我正在通过扩展来构建自定义控件ScrollableControl.
问题是我的自定义控件充当容器 - 我可以将控件拖入其中:

我的问题是如何在扩展的类中禁用容器功能 ScrollableControl
下面是两个测试控件,一个扩展Control,第二个ScrollableControl
public class ControlBasedControl : Control
{
protected override Size DefaultSize
{
get { return new Size(100, 100); }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.LightCoral, ClientRectangle);
}
}
public class ScrollableControlBasedControl : ScrollableControl
{
public ScrollableControlBasedControl()
{
AutoScrollMinSize = new Size(200, 200);
}
protected override Size DefaultSize
{
get { return new Size(100, 100); }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.LawnGreen, ClientRectangle);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试在PostMan中重新创建C#DelegatingHandler。
我创建了用于计算auth标头值的请求前脚本。
目前,我的脚本如下所示:
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function GetNonce() {
return (S4() + S4() + S4()+ S4() + S4() + S4() + S4()+ S4()).toLowerCase();
}
function GetTimeStamp() {
var d = new Date();
return Math.round(d.getTime() / 1000);
}
function getAuthHeader(httpMethod, requestUrl, requestBody) {
var CLIENT_KEY = postman.getEnvironmentVariable('hmac_user');
var SECRET_KEY = postman.getEnvironmentVariable('hmac_key');
var AUTH_TYPE = 'HMAC';
requestUrl = requestUrl.replace(/{{(\w*)}}/g,function(str,key) {return environment[key]});
requestUrl = requestUrl.toLowerCase();
var requestTimeStamp = GetTimeStamp();
var nonce = GetNonce();
var bodyHash="";
if (httpMethod == 'GET' || …Run Code Online (Sandbox Code Playgroud) 我有一个 .NET 6 REST API,其方法有两个参数:
public async Task<object> CreateSingleEntity([FromRoute] string entity, [FromBody] IDictionary<string, object> model)
{
//process data
}
Run Code Online (Sandbox Code Playgroud)
当我执行此请求时,这效果很好:
curl --location --request POST 'https://localhost:7299/api/data/cars' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": 1,
"name": "Ford",
"id":"a47d52de-fcd1-48e7-8656-7edb84dc78bd",
"is_created": true,
"date":"2022-09-23",
"datetime":"2022-09-23 13:10"
}'
Run Code Online (Sandbox Code Playgroud)
但因为我正在使用 MediatR,所以我想使用模型。
public class CreateSingleRecord : ICommand<object>
{
[FromRoute(Name ="entity")]
public string Entity { get; init; }
[FromBody]
public IDictionary<string, object> Record { get; init; }
}
Run Code Online (Sandbox Code Playgroud)
可悲的是,每次我尝试用以下方法替换以前的方法时:
public async Task<object> CreateSingleEntity([FromHybrid] CreateSingleRecord …Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×3
javascript ×2
.net ×1
.net-6.0 ×1
asp.net-core ×1
css ×1
css-position ×1
html ×1
jquery ×1
postman ×1
security ×1
soap ×1
sql ×1
t-sql ×1
web-services ×1
winforms ×1
wsdl ×1