默认情况下,add-migration命令尝试在其中创建迁移.cs文件
我想将我的迁移以及其余的EF相关代码存储在我项目的\ Data文件夹中:
有了这个结构,当我执行时
PM> add-migration Migration1
Run Code Online (Sandbox Code Playgroud)
在NuGet控制台中,我收到以下错误:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\MyProjectRoot\Migrations\201112171635110_Migration1.cs'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) … 我安装了EntityFramework.SqlMigrations NuGet Package,我收到此错误.它在过去和某种程度上对我有用,现在它不起作用.
PM> update-database
The term 'update-database' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:16
+ update-database <<<<
+ CategoryInfo : ObjectNotFound: (update-database:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud) 查看使用新的Mediatr 3.0功能管道行为进行身份验证/授权.
您通常会根据消息或处理程序进行身份验证吗?我问的原因是我在处理程序上进行身份验证(与MVC中的控制器相同)但是行为似乎没有关于处理程序的知识,因此我不确定这是否可行/适合.
我可以为每条消息添加一个IAuthorisationRequired标记接口,但如果消息是通知/事件并且有多个处理程序,那么可能有些应该运行而不是其他运行.真的感觉更好地检查执行实际工作的处理程序代码的auth.
希望能够在处理程序上放置[Authorize]属性并使用一个行为来检查它(我目前正是这样做但是使用基类而不是行为).
public class AuthenticationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next)
{
//Can't access handler class here, so how do I know the action requires authentication/authorization?
return next();
}
}
[Authorize]
public class ChangePasswordRequestHandler : IAsyncRequestHandler<ChangePassword, ReponseType>
{
protected override async Task<ReponseType> Handle(AsyncRequestBase<ChangePassword> message)
{
//change users password here
}
}
Run Code Online (Sandbox Code Playgroud) 我需要一些关于如何诊断悬挂构建的建议.这只是在过去一两周内发生的,我有充分的理由怀疑这是我最近所做的事,而不仅仅是巧合
建立
症状
近期变动
我试过的
Team Foundation服务主机请求监视器检测到以下情况:日期(UTC):3/02/2014 12:54:06 am机器:CODEBASE应用程序域:/ LM/W3SVC/1/ROOT/tfs-1-130357641583538280程序集:Microsoft.TeamFoundation.Framework.Server,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a; v4.0.30319服务主机:0dc282b5-59a8-4941-b541-a4f7d314cd0f进程细节:进程名称:w3wp进程ID:2508线程ID:2504
详细消息:服务主机XXXX的请求已执行37秒,超过警告阈值30.请求详细信息:请求上下文详细信息URL:/ tfs/XXXX/XXXX/_api/_build/stop?__ v = 4方法:ApiBuild .stop参数:uri = vstfs:/// Build/Build/34064用户代理:Mozilla/5.0(Windows NT 6.2; WOW64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/32.0.1700.102 Safari/537.36唯一ID:00000000 -0000-0000-0000-000000000000
Team Foundation服务主机请求监视器检测到以下情况:日期(UTC):30/01/2014 11:10:01 pm机器:CODEBASE应用程序域:/ LM/W3SVC/1/ROOT/tfs-1-130355232548668648程序集:Microsoft.TeamFoundation.Framework.Server,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a; v4.0.30319服务主机:0dc282b5-59a8-4941-b541-a4f7d314cd0f进程内容:进程名称:w3wp进程ID:70320线程ID:14540
详细消息:服务主机XXXX的请求已执行37秒,超过警告阈值30.请求详细信息:请求上下文详细信息URL:/tfs/XXXX/Build/v4.0/BuildService.asmx方法:StopBuilds参数: uris [0] = …
我正在尝试编写一个小脚本来将所有用户图像设置为他们的AD图像,我在ILSpy中做了一些跳转并找到了使用TFS服务器API设置的内容,但是代码需要有点不同,因为我' m而是使用客户端API.
我下面的代码可以成功遍历tfs中的所有用户,在AD中查找它们,获取缩略图,在TFS标识上设置属性.但我不能为我的生活图获得扩展属性以保存回TFS.
代码没有异常,但是当我下次运行应用程序时,属性未设置为我设置的值.
有谁知道通过客户端api保存扩展属性的方法?
Microsoft.TeamFoundation.Client.TeamFoundationServer teamFoundationServer = new Microsoft.TeamFoundation.Client.TeamFoundationServer("{URL TO TFS}");
FilteredIdentityService service = teamFoundationServer.GetService<FilteredIdentityService>(); ;
IIdentityManagementService2 service2 = teamFoundationServer.GetService<IIdentityManagementService2>();
foreach (var identity in service.SearchForUsers(""))
{
var user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain), identity.UniqueName);
if (user == null) continue;
var de = new System.DirectoryServices.DirectoryEntry("LDAP://" + user.DistinguishedName);
var thumbNail = de.Properties["thumbnailPhoto"].Value as byte[];
identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", thumbNail);
identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", DateTime.UtcNow);
service2.UpdateExtendedProperties(identity);
}
Run Code Online (Sandbox Code Playgroud) 只是一个小小的想法,我正在玩,不知道它是否可行或有多大用处.
我正在尝试使用Roslyn CTP生成一个非常基本的EF Code First数据库.
码:
var scriptEngine = new ScriptEngine(new[] { "System", "System.Core", typeof(DbContext).Assembly.Location });
var session = Roslyn.Scripting.Session.Create();
var t = scriptEngine.CompileSubmission<DbContext>(@"
using System.Data.Entity;
public class Car {
public int Id {get; set;}
public string Name {get; set; }
}
public class Context : DbContext {
public DbSet<Car> Cars {get; set; }
}
new Context();
", session);
t.Execute();
Run Code Online (Sandbox Code Playgroud)
执行时,我得到以下异常
例外:
未映射"提交#0 + Car"类型.使用Ignore方法或NotMappedAttribute数据批注检查未明确排除类型.验证类型是否已定义为类,不是原始类,嵌套类还是通用类,并且不从EntityObject继承.
通过查看可能出现的问题列表,我猜测Roslyn正在将嵌套类作为代码生成的一部分.这有意义,否则"新的Context();" 调用需要包装到某种类/方法中.我可以发出一个程序集,这将确认上述内容,但可能没有任何关于如何正确编写它的线索.
我也走了Syntax.ClassDeclaration的路线,但最终得到了几百行代码,只是为了创建一个具有1个属性的类,并且没有明显的方法来实例化该类.
题
是否有一种简单的方法可以在Roslyn中创建一个可公开访问的类(例如,不嵌套在另一个类中)?
我正在使用azure函数来托管react应用程序的API,但是我也在使用相同的azure函数来托管应用程序的html / js / css(通过代理函数对Blob存储上的静态文件进行托管)。
我一直在使用EasyAuth为它提供身份验证,该身份一直很好地工作,但是我需要支持EasyAuth中没有内置的身份提供程序(它根本不支持自定义身份提供程序)。这意味着我回退到使用Microsoft.AspNetCore.Authentication.OpenIdConnect程序包。
我已经在启动文件中注册了身份验证
builder.Services
.AddAuthentication()
.AddCookie("WebJobsAuthLevel") //errors without this, although I suspect it's wrong
.AddCookie("Bearer") //errors without this, although I suspect it's wrong
.AddOpenIdConnect("custom", o =>
{
o.MetadataAddress = "https://localhost:44320/.well-known/openid-configuration";
o.ClientId = "clientid";
o.ClientSecret = "secret";
o.ResponseMode = OpenIdConnectResponseType.Code;
o.SignInScheme = "Cookies";
o.GetClaimsFromUserInfoEndpoint = true;
});
Run Code Online (Sandbox Code Playgroud)
以及让我触发挑战的功能
[FunctionName("CustomAuth")]
public async Task<IActionResult?> Challenge([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = ".auth/login/custom")]HttpRequest req, ILogger log)
{
return new ChallengeResult("custom");
}
Run Code Online (Sandbox Code Playgroud)
如果我按下此功能,则效果很好,可以重定向到身份验证提供程序进行登录。
但是,一旦我登录,它就会重定向回我的功能应用,其中404
http:// localhost:7071 / signin-oidc?
在这个阶段,我猜测AddAuthentication不能像在asp.net mvc核心中使用它时那样,可以挂接到传入的Web请求中。想知道我是否可以通过较低级别或通过自定义Azure函数将其连接起来
我是EF和MVC3的新手.我正在运行以下MVC3 SQL迁移教程(下面的链接),当我从带有VS2010的cmd窗口运行以下命令时,我收到以下错误:
更新数据库
命令"update"无效
我在这里错过了什么?谢谢!
教程链接:
http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx
将 Azure Functions 2.0 与 EasyAuth 结合使用(Azure 一键选项以启用针对 azure 广告的身份验证)。
这允许我在函数定义中得到一个 ClaimsPrincipal
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, ClaimsPrincipal principal)
Run Code Online (Sandbox Code Playgroud)
这很棒,但我希望能够访问 DbContext 中的当前 userId,以便我可以使用 EFCore HasQueryFilter 功能进行安全调整。
我的 DbContext 被注入到我的 azure 函数端点类中,我更愿意保持这种方式,而不是在端点中手动创建它。
虽然我可能可以在每个请求的上下文中设置一个属性,但我更希望能够通过依赖项注入将 ClaimsPrincipal 或其部分注入到 DbContext 中,这样我就不需要在每个函数中手动执行此操作。
ClaimsPrincipal 默认情况下似乎没有连接用于注入,我也没有找到可以注入的另一个可以访问它的类。