在我的WebAPI项目中,我Owin.Security.OAuth用来添加JWT身份验证.GrantResourceOwnerCredentials我的OAuthProvider 内部使用以下行设置错误:
context.SetError("invalid_grant", "Account locked.");
Run Code Online (Sandbox Code Playgroud)
这将返回给客户:
{
"error": "invalid_grant",
"error_description": "Account locked."
}
Run Code Online (Sandbox Code Playgroud)
在用户获得身份验证并且他尝试向我的某个控制器执行"正常"请求后,当模型无效时,他会得到以下响应(使用FluentValidation):
{
"message": "The request is invalid.",
"modelState": {
"client.Email": [
"Email is not valid."
],
"client.Password": [
"Password is required."
]
}
}
Run Code Online (Sandbox Code Playgroud)
这两个请求都在返回400 Bad Request,但有时您必须查找error_description字段,有时候还要查找message
我能够创建自定义响应消息,但这仅适用于我返回的结果.
我的问题是:是否有可能取代message与error响应由返回ModelValidatorProviders,并在其他地方?
我读过ExceptionFilterAttribute但我不知道这是不是一个好的起点.FluentValidation应该不是问题,因为它只是添加错误ModelState.
编辑:
我正在尝试解决的下一件事是WebApi中返回的数据中的命名约定不一致 - 当OAuthProvider我们返回错误error_details时,但是当我们返回BadRequest时ModelState(从ApiController)返回错误modelState.正如你可以看到第一次使用snake_case …
我有另一个与Bootstrap相关的问题.我想在我的表单中添加收音机和复选框,我希望它们也可以采用100%宽度的表单元素.
我添加了按钮组,如下所示:
<div class="form-group">
<label class="col-sm-3 control-label">Subscribe</label>
<div class="col-sm-9">
<div class="btn-group input-group" data-toggle="buttons">
<label class="btn btn-success">
<input type="radio" name="options" id="option1" />Yes</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2" />Maybe</label>
<label class="btn btn-danger">
<input type="radio" name="options" id="option3" />No</label>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这给了我很好的收音机按钮:

但正如你可以看到他们有固定的宽度.这可以用bootstrap类修复吗?这里是我的示例代码:http://jsfiddle.net/Misiu/yy5HZ/5/
为了在我当前的项目中使用,我创建了一个允许我调用SQL Server异步的类.
我的代码看起来像这样:
internal class CommandAndCallback<TCallback, TError>
{
public SqlCommand Sql { get; set; }
public TCallback Callback { get; set; }
public TError Error { get; set; }
}
class MyCodes:SingletonBase<MyCodes>
{
private static string _connString = @"Data Source=MyDB;Initial Catalog=ED;Integrated Security=True;Asynchronous Processing=true;Connection Timeout=0;Application Name=TEST";
private MyCodes() { }
public void SetSystem(bool production)
{
_connString =
string.Format(@"Data Source=MyDB;Initial Catalog={0};Integrated Security=True;Asynchronous Processing=true;Connection Timeout=0;Application Name=TEST", production ? "ED" : "TEST_ED");
}
public void Add(string newCode, Action<int> callback, Action<string> error)
{
var conn …Run Code Online (Sandbox Code Playgroud) 我有部署到我的本地IIS服务器的Web应用程序Sites\Default,它工作正常,现在我想让它更安全 - 我想加密连接字符串和appSettings.
在pubxml文件中我添加了这一行:
<MSDeployEnableWebConfigEncryptRule>true</MSDeployEnableWebConfigEncryptRule>
Run Code Online (Sandbox Code Playgroud)
但这只加密连接字符串.我知道我可以手动打电话:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pe "appSettings" -site Default -app "/"
Run Code Online (Sandbox Code Playgroud)
在部署之后在我的服务器上加密包含appSettings的外部文件,但我必须手动执行此操作.
我的问题是我如何从Visual Studio(Build> Publish)部署网站,并aspnet_regiis在发布成功后自动执行该命令.
我找到了可以使用的信息runcommand和其他有关bat文件的信息,但我没有从命令行调用MSDeploy.
我还发现了我应该构建自定义提供程序并从MSDeploy调用它的信息.
我应该如何编辑我的pubxml文件以获得此行为?
EDIT1:
我设法After Deploy使用以下方法挂钩Target:
<Target Name="EncryptAppSettings" AfterTargets="MSDeployPublish" >
<Message Text="Encrypting appSettings" />
<Exec Command="aspnet_regiis -pe "appSettings" -site Default -app "/"" />
<Message Text="AppPath: $(DeployIisAppPath)" />
</Target>
Run Code Online (Sandbox Code Playgroud)
但是现在我收到了这个错误:
命令"aspnet_regiis -pe"appSettings"-site Default -app"/""退出,代码为9009.
EDIT2:
我尝试过像这样使用runCommand:
<ItemGroup>
<MsDeploySourceManifest Include="runCommand">
<path>aspnet_regiis -pe "appSettings" -site Default -app "/"</path>
<waitInterval>10000</waitInterval>
<AdditionalProviderSettings>waitInterval</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
但我没有运气.我发现了 …
asp.net encryption visual-studio microsoft-web-deploy visual-studio-2013
我在 VS2019 中构建了一个示例 .NET 5 Web API 应用程序,我有默认模板(带有WeatherForecastController)。我已将 Quartz.net (版本 3.3.3)添加到项目中,并在Startup课堂上添加了:
public void ConfigureServices(IServiceCollection services)
{
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
q.AddJobAndTrigger<HelloWorldJob>(Configuration);
});
// ASP.NET Core hosting
services.AddQuartzServer(options =>
{
// when shutting down we want jobs to complete gracefully
options.WaitForJobsToComplete = true;
});
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "QuartzTest", Version = "v1" });
});
}
Run Code Online (Sandbox Code Playgroud)
并创建了一个示例作业。
代码AddJobAndTrigger取自https://andrewlock.net/using-quartz-net-with-asp-net-core-and-worker-services/
该部分工作完美,但现在我想让最终用户能够通过 REST API 手动触发特定作业。
我创建了一个简单的控制器,应该能够使用以下命令手动触发作业:
scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"));
Run Code Online (Sandbox Code Playgroud)
(参考:Quartz.Net 按需触发预定作业) …
我正在尝试在桌面应用程序中使用C#来使用Java Web Service.
我的第一次尝试是使用WebServicesClientProtocol,但我无法添加所需的必要属性WSSE Username and Token Security Spec 1.1
我需要创建具有此结构的请求:
<soap:Envelope xmlns:dz="http://dom.query.api.com" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://dz.api.swd.zbp.pl/xsd">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-E94CEB6F4708FB7C23148611494797612">
<wsse:Username>my_login</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">XqEwZ/CxaBfFvh487TjvN8qD63c=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JzURe0CxvzRjmEcH/ndldw==</wsse:Nonce>
<wsu:Created>2017-02-09T09:42:27.976Z</wsu:Created>
</wsse:UsernameToken>
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" wsu:Id="X509-E94CEB6F4708FB7C2314861149479517">MIIKnDCCB.........nmIngeg6d6TNI=</wsse:BinarySecurityToken>
<ds:Signature Id="SIG-E94CEB6F4708FB7C23148611494795311" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="dz soap xsd" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#id-E94CEB6F4708FB7C23148611494795310">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="dz xsd" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>mlABQuNUFOmLqsDswxXxQ6XnjpQ=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>lYhBHSQ/L...XL1HEbMQjJ/Q2Rvg==</ds:SignatureValue>
<ds:KeyInfo Id="KI-E94CEB6F4708FB7C2314861149479518">
<wsse:SecurityTokenReference wsse11:TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" wsu:Id="STR-E94CEB6F4708FB7C2314861149479519" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
<wsse:Reference URI="#X509-E94CEB6F4708FB7C2314861149479517" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
</soap:Header>
<soap:Body …Run Code Online (Sandbox Code Playgroud) 我正在使用WPF开始我的冒险,在创建我的第一个应用程序后,我想要设置它的样式.我找到了UI模板并使用Blend for VS2013我将PSD导入到我的项目中.
这是代码:
<Canvas x:Name="Progress1" ClipToBounds="True" HorizontalAlignment="Left" Height="52" UseLayoutRounding="False" VerticalAlignment="Top" Width="493" Margin="0,307.5,0,-53.5">
<Canvas x:Name="Loading" Height="52" Canvas.Left="0" Canvas.Top="0" Width="493">
<Path x:Name="Base2" Data="F1M22.086,3C22.086,3 63.118,4.562 125.833,3 199.069,1.175 294.072,5.645 370.146,4.333 430.323,3.294 474,3 474,3 479.523,3 487.826,8.208 489.687,15.098 491.864,23.156 491.191,28.867 489.081,37.118 487.415,43.637 479.856,47.999 474.333,47.999 474.333,47.999 368.324,50.176 252.792,47.999 135.568,45.792 42.104,49.541 23.518,47.999 12.306,47.07 6.028,45.811 4.028,37.787 3.199,34.461 1.441,23.222 7.178,11.906 10.179,5.987 16.563,3 22.086,3z" Height="52" Canvas.Left="0" Canvas.Top="0" Width="493" StrokeThickness="2">
<Path.Stroke>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFC18A13" Offset="1"/>
<GradientStop Color="#FFDC9A0C" Offset="0.339"/>
</LinearGradientBrush>
</Path.Stroke>
<Path.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop …Run Code Online (Sandbox Code Playgroud) 在我的ASP.NET MVC4应用程序中,我有这样定义的模型:
public class Employee : BaseObject
{
[JsonIgnore]
public string FirstName { get; set; }
[JsonIgnore]
public string LastName { get; set; }
[JsonIgnore]
public string Manager { get; set; }
public string Login { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
当我使用ApiController返回此对象时,我得到没有具有JsonIgnore属性的字段的正确对象,但是当我尝试使用下面的代码在cshtml文件中添加相同的对象时,我得到所有字段.
<script type="text/javascript">
window.parameters = @Html.Raw(@Json.Encode(Model));
</script>
Run Code Online (Sandbox Code Playgroud)
看起来@Json.Encode忽略了这些属性.
怎么解决这个问题?
我正在尝试构建自定义指令,以便我在调查中显示问题.因为我有多种类型的问题,所以我考虑创建单个指令并根据问题类型更改它的模板.
我的指示:
directive('question', function($compile) {
var combo = '<div>COMBO - {{content.text}}</div>';
var radio = [
'<div>RADIO - {{content.text}}<br/>',
'<md-radio-group layout="row" ng-model="content.answer">',
'<md-radio-button ng-repeat="a in content.answers track by $index" ng-value="a.text" class="md-primary">{{a.text}}</md-radio-button>',
'</md-radio-group>',
'</div>'
].join('');
var input = [
'<div>INPUT - {{content.text}}<br/>',
'<md-input-container>',
'<input type="text" ng-model="content.answer" aria-label="{{content.text}}" required md-maxlength="10">',
'</md-input-container>',
'</div>'
].join('');
var getTemplate = function(contentType) {
var template = '';
switch (contentType) {
case 'combo':
template = combo;
break;
case 'radio':
template = radio;
break;
case 'input':
template = input;
break; …Run Code Online (Sandbox Code Playgroud) 在@Taiseer Joudeh之后,我能够创建简单的Web API POC.我能够创建新帐户,然后登录并在向标头添加JWT令牌时调用安全Web API.
我想修改负责创建帐户的方法.
现在我正在返回带有新用户对象的Create(201)代码,但我想返回访问令牌.
我发现了类似的问题,但它需要创建HttpClient并向OAuthAuthorizatioServer TokenEndpointPath发出请求.
我发现的第二个问题需要生成返回到前端的临时令牌,但是前端必须向服务器发出额外请求以获得"真实"令牌.
我想做的是在创建用户帐户时返回登录响应(access_token,token_type和expires_in).我希望用户在创建帐户时进行身份验证.
我只使用Web API和JWT而没有任何cookie.
编辑:我的临时解决方案:
创建用户后我正在这样做:
var validTime = new TimeSpan(0, 0, 0, 10);
var identity = await UserManager.CreateIdentityAsync(user, "JWT");
var jwtFormat = new CustomJwtFormat(ApplicationConfiguration.Issuer);
var authenticationProperties = new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow, ExpiresUtc = DateTimeOffset.UtcNow.Add(validTime) };
var authenticationTicket = new AuthenticationTicket(identity, authenticationProperties);
var token = jwtFormat.Protect(authenticationTicket);
var response = new
{
access_token = token,
token_type = "bearer",
expires_in = validTime.TotalSeconds.ToInt()
};
return …Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×3
.net ×1
.net-3.5 ×1
.net-4.5 ×1
.net-5 ×1
angularjs ×1
asp.net-core ×1
asp.net-mvc ×1
asynchronous ×1
css ×1
css3 ×1
encryption ×1
javascript ×1
json ×1
owin ×1
quartz.net ×1
security ×1
sql-server ×1
transactions ×1
wcf ×1
wcf-security ×1
wpf ×1
wpf-controls ×1