我正在阅读一些关于使用rest服务正确使用URI的文档,我遇到了一个基本GET .. DELETE请求的例子.
示例uri是:
获取所有用户
GET http://mydomain.org/api/users
Run Code Online (Sandbox Code Playgroud)
获取特定用户
GET http://mydomain.org/api/users/1
Run Code Online (Sandbox Code Playgroud)
更新用户
PUT http://mydomain.org/api/users/1
Run Code Online (Sandbox Code Playgroud)
删除用户
DELETE http://mydomain.org/api/users/1
Run Code Online (Sandbox Code Playgroud)
用户资源可以是以下形式的JSON或XML:
{
Id: 1,
FirstName: 'John',
LastName: 'Doe'
}
Run Code Online (Sandbox Code Playgroud)
我的问题是这个.要维护REST原则,是否需要在PUT请求的URI中包含资源的id?
可能重复:
如何配置Pex以尊重代码合同?
目前,当我运行pex探索时,我在我的类中创建的代码契约被视为pex探索结果中的错误.我想当你使用代码合同进行pex勘探时,合同失败应该被视为预期的行为.这是导致异常的代码.
测试方法:
[PexMethod]
public void TestEquality(Guid userId, string username, string password, string securityQuestion, string securityAnswer)
{
UserSecurity user = UserTools.CreateUser(Guid.NewGuid(), username, password, securityQuestion, securityAnswer);
bool passwordResult = UserTools.VerifyInput(password, user.Password, user.PasswordSalt);
bool securityAnswerResult = UserTools.VerifyInput(securityAnswer, user.SecurityAnswer, user.SecurityAnswerSalt);
Assert.IsTrue(passwordResult, "Password did not correctly re-hash");
Assert.IsTrue(securityAnswerResult, "Security Answer did not correctly re-hash");
}
Run Code Online (Sandbox Code Playgroud)
失败的方法调用:
public static UserSecurity CreateUser(Guid userId, string username, string password, string securityQuestion, string securityAnswer)
{
Contract.Requires(userId != Guid.Empty);
Contract.Requires(!string.IsNullOrWhiteSpace(username));
Contract.Requires(!string.IsNullOrWhiteSpace(password));
Contract.Requires(!string.IsNullOrWhiteSpace(securityQuestion));
Contract.Requires(!string.IsNullOrWhiteSpace(securityAnswer));
Contract.Ensures(Contract.Result<UserSecurity>() != null);
byte[] passwordSalt;
byte[] …Run Code Online (Sandbox Code Playgroud) 有没有办法在使用Get-Member时获取Method MemberType的参数?
例:
Get-Process | Get-Member -MemberType Method
Run Code Online (Sandbox Code Playgroud)
我在这个例子中需要的是列表中每个成员的参数和参数类型.
这样做的目的是获取COM +对象的成员,参数和参数类型,我必须为其创建文档.所以一个例子不能特定于.net.
我将把成员和参数信息传递到剃刀模板中以生成适当的html.
编辑:一个更好的例子就是这个......
$comObj = New-Object -ComObject COMAdmin.COMAdminCatalog
$comObj | Get-Member -MemberType Method
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我需要为返回的每个方法获取参数名称(如果有的话).
我是 Office 365 用户,正在编写使用 Azure AD 进行身份验证的应用程序。在我找到的所有示例中,他们使用的租户名称是一个友好名称,如 onmicrosoft.com 或 domain.com。我必须使用的租户名称是一个 guid。
有什么办法可以改变这种情况吗?做调用图形 api 之类的事情看起来不正确:https : //graph.windows.net/12345678-aaaa-bbbb-cccc-dddddddddddd/groups? api-version =1.6
我在新项目中使用Entity Framework 4.1和POCO实体.在我开始使用AppFabric缓存来缓存实体之前,一切正常.我开始让错误从缓存中检索与反序列化代理对象相关的错误.我通过设置ContextOptions.ProxyCreationEnabled = false来解决这个问题.现在的问题是当我从缓存中获取实体时,我必须使用ObjectSet.Attach(实体)将实体附加到当前上下文,并使用ObjectContext.ObjectStateManager.ChangeObjectState(entity,EntityState.Modified)将它们添加到状态管理器.
我的问题是有没有办法以编程方式启用/禁用一组实体的代理?或者换句话说,一种在代理对象中包装反序列化实体的方法.
如果没有一个好方法可以做到这一点,我现在正在做的方式是正确的吗?或者,还有更好的方法?
当我在同一服务上同时启用 JWT 承载身份验证和 CORS 时,我在从服务器获取适当的 Access-Control-Allow-Origin 标头时遇到问题。当我从配置中删除 UseJwtBearerAuthentication 时,一切正常。
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins", builder =>
{
builder.AllowAnyOrigin();
builder.AllowAnyHeader();
builder.AllowAnyMethod();
builder.AllowCredentials();
});
});
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseJwtBearerAuthentication(options =>
{
options.AutomaticAuthenticate = true;
options.RequireHttpsMetadata = false;
options.Audience = "c2cf422a-a432-2038-b183-cda64e16239e";
options.Authority = "domain.com";
});
app.UseCors("AllowAllOrigins");
app.UseIISPlatformHandler();
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
我试图更改配置的顺序,但似乎没有任何效果。我还尝试将 [EnableCors("AllowAllOrigins")] 添加到我正在调用的控制器中。 …
我在将属性传递到自定义组件时遇到了一些麻烦.我尝试通过以下方式声明我的组件:
<require from="../components/project-documents"></require>
<project-documents projectId="testing123"></project-documents>
<project-documents projectId.bind="project.Name"></project-documents>
Run Code Online (Sandbox Code Playgroud)
import {customElement, bindable} from "aurelia-framework";
import {autoinject} from "aurelia-dependency-injection";
@customElement("project-documents")
export class ProjectDocuments {
@bindable projectId:string;
attached() {
alert(this.projectId);
}
}
Run Code Online (Sandbox Code Playgroud)
调用警报时,undefined是我从中获取的值.另外,是否需要customElement装饰器?