小编Ste*_*eve的帖子

OWIN SignOut不会删除cookie

我在外部身份验证服务器中使用OWIN中间件,我的应用程序使用OAuth授权代码授权流进行身份验证.

我可以重定向到身份验证服务器,针对外部提供商(Google)进行身份验证,并使用已登录的用户和应用程序Cookie设置重定向回我的客户端应用程序,但是当我尝试在我调用该AuthenticationManager.SignOut方法后注销cookie时.

我的cookie选项Startup.Auth.cs是:

var cookieOptions = new CookieAuthenticationOptions
                    {
                        Provider = cookieProvider,
                        AuthenticationType = "Application",
                        AuthenticationMode = AuthenticationMode.Passive,
                        LoginPath = new PathString("/Account/Index"),
                        LogoutPath = new PathString("/Account/Logout"),
                        SlidingExpiration = true,
                        ExpireTimeSpan = TimeSpan.FromMinutes(30),
                    };
app.UseCookieAuthentication(cookieOptions);
app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ExternalCookie);
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
Run Code Online (Sandbox Code Playgroud)

我的登录方式:

var loginInfo = await AuthManager.GetExternalLoginInfoAsync();
SignInManager.ExternalSignInAsync(loginInfo, true);
var identity = AuthManager.AuthenticateAsync(DefaultAuthenticationTypes.ExternalCookie).Result.Identity;

if (identity != null)
{
    AuthManager.SignIn(
                  new AuthenticationProperties {IsPersistent = true},
                  new ClaimsIdentity(identity.Claims, "Application", identity.NameClaimType, identity.RoleClaimType));

        var ticket = AuthManager.AuthenticateAsync("Application").Result;
        var identity = ticket != null ? ticket.Identity …
Run Code Online (Sandbox Code Playgroud)

c# authentication cookies owin asp.net-identity

19
推荐指数
1
解决办法
3434
查看次数

Xamarin Android链接无法访问文件

我有一个Xamarin Android项目,我试图使用Sdk和用户程序集链接.

如果我将Android项目设置为仅限Sdk Assembly Linking,则会成功创建并部署APK并且可以正常工作.

但是,当我设置Sdk和用户程序集链接时,没有其他更改,我在部署时收到以下错误.该解决方案成功构建.

The "LinkAssemblies" task failed unexpectedly.    
System.IO.IOException: The process cannot access the file '<path-to-project>\AppName\AppName.Android\obj\Release\android\assets\AppName.Core.dll' because it is being used by another process.
    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, Boolean checkHost)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
    at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory) …
Run Code Online (Sandbox Code Playgroud)

c# android visual-studio xamarin xamarin.forms

18
推荐指数
1
解决办法
585
查看次数

Azure AD联合注销不会重定向到客户端应用程序

我正在使用Identity Server 3作为我正在构建的.Net MVC Web应用程序的中央身份验证服务器.

我已将身份验证服务器配置为使用Open ID Connect身份提供程序,以允许用户使用混合流程对多租户Azure Active Directory帐户进行身份验证.

目前,登录按预期工作,我的客户端应用程序重定向到身份验证服务器,然后身份验证服务器重定向到Microsoft进行登录,然后返回到具有正确填充的访问令牌的客户端应用程序.

但是,当我尝试注销时,我被正确地重定向到Microsoft,但页面在返回到身份验证服务器时停止,而不是继续返回到我的客户端应用程序.

我相信我已按照此处的说明正确设置了帖子注销重定向,我认为我的所有设置都可以.

当我下载Identity Server 3代码并对其进行调试时,它正确设置signOutMessageId到查询字符串上,但在UseAutofacMiddleware尝试重定向到我的映射signoutcallback位置时,在方法内部遇到以下错误:

抛出异常:mscorlib.dll中的"System.InvalidOperationException"

附加信息:已发送标头

我的验证服务器设置:

app.Map("identity", idsrvApp => {
    var idSvrFactory = new IdentityServerServiceFactory();

    var options = new IdentityServerOptions
    {                
        SiteName = "Site Name",
        SigningCertificate = <Certificate>,
        Factory = idSvrFactory,
        AuthenticationOptions = new AuthenticationOptions
        {
            IdentityProviders = ConfigureIdentityProviders,
            EnablePostSignOutAutoRedirect = true,
            PostSignOutAutoRedirectDelay = 3
        }
    };
    idsrvApp.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    idsrvApp.UseIdentityServer(options);

    idsrvApp.Map("/signoutcallback", cb => { …
Run Code Online (Sandbox Code Playgroud)

c# azure logout thinktecture-ident-server identityserver3

7
推荐指数
1
解决办法
1177
查看次数

MVC 6中的GetOwinContext

我在我的Asp.Net5 MVC 6 Web应用程序中使用Membership Reboot来管理我的身份,登录等.

我正在尝试让MR的OwinAuthenticationService作为IAuthenticationService接口的实现工作,我依赖注入我的控制器.

此示例涉及IAuthenticationService使用以下Autofac注册注入依赖项:

builder.Register(ctx=>HttpContext.Current.GetOwinContext()).As<IOwinContext>();
builder.Register<IAuthenticationService>(ctx =>
{
    var owin = ctx.Resolve<IOwinContext>();
    return new OwinAuthenticationService(
        MembershipRebootOwinConstants.AuthenticationType,
        ctx.Resolve<IUserAccountService>(),
        owin.Environment);
}).InstancePerLifetimeScope();
Run Code Online (Sandbox Code Playgroud)

在MVC5中,这可以HttpContext.Current.GetOwinContext()像程序集中的扩展方法一样好Microsoft.Owin.Host.SystemWeb.但是,此程序集不再用于MVC6,因此HttpContext.Current无法解决.

我已经看到新的访问方式HttpContext是使用新IHttpContextAccessor界面,但这并没有解决获取Owin上下文的问题.

有没有办法在MVC6中获取当前的Owin上下文,或者当前的Owin环境字典(因为这是OwinAuthenticationService该类使用的)?

c# asp.net httpcontext owin asp.net-core-mvc

6
推荐指数
1
解决办法
2570
查看次数

对 xUnit Theory 的多次运行使用相同的测试数据

我正在使用 xUnit 对我的应用程序进行单元测试,并且目前正在设置一个测试以使用该[Theory]属性来测试几个不同的数据输入。

为此,我需要在我之前模拟的数据上下文中创建测试数据。这有效,但是当我在测试本身中添加数据时,每次运行最终都会再次添加相同的数据。

我目前的测试:

[Theory]
[InlineData(null, 2)]
[InlineData("en-AU", 1)]
public void Test1(string term, int expectedCount)
{
    Fixture.DbContext.Culture.Add(new Culture { Name = "English (Australia)", CultureCode = "en-AU", NativeName = "English (Australia)"});
    Fixture.DbContext.Culture.Add(new Culture { Name = "English (United States)", CultureCode = "en-US", NativeName = "English (United States)" });
    Fixture.DbContext.Culture.Add(new Culture { Name = "English", CultureCode = "en", NativeName = "English", NeutralCultureFlag = true });

    var result = controller.GetRegions(term);

    Assert.IsType(typeof (JsonResult), result);
    var jsonResult = (JsonResult)result;

    Assert.Equal(expectedCount, jsonResult.Data);
} …
Run Code Online (Sandbox Code Playgroud)

unit-testing xunit xunit.net

5
推荐指数
1
解决办法
1614
查看次数

Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。错误?

我需要将这六个字段保存在同一列中,但不能保存在同一行和同一单元格中。每个字段都有默认的 GUID。所以我决定将该默认 GUID 放入一个列表中,将字段放入一个列表中,并在我们想要的位置调用该特定列表的该对象。

       ArrayList Alist = new ArrayList();
        {
            Alist.Add("FD713788-B5AE-49FF-8B2C-F311B9CB0CC4");
            Alist.Add("64B512E7-46AE-4989-A049-A446118099C4");
            Alist.Add("376D45C8-659D-4ACE-B249-CFBF4F231915");
            Alist.Add("59A2449A-C5C6-45B5-AA00-F535D83AD48B");
            Alist.Add("03ADA903-D09A-4F53-8B67-7347A08EDAB1");
            Alist.Add("2F405521-06A0-427C-B9A3-56B8931CFC57");
        }

        ArrayList objValue = new ArrayList();
        {
            objValue.Add(viewmodel.TinNo);
            objValue.Add(viewmodel.CstNo);
            objValue.Add(viewmodel.PanNo);
            objValue.Add(viewmodel.CinNo);
            objValue.Add(viewmodel.ExciseRegNo);
            objValue.Add(viewmodel.ServiceTaxNo);
        }

   var TaxInfoTaxFiledclassobj = new TaxInfoTaxFiled()
        {

            TaxInfoTaxFieldID = TaxInfoTaxFieldObj,
            TaxFieldID = new Guid(Alist .ToString ()),
            FieldValue = objValue.ToString(),
        };
Run Code Online (Sandbox Code Playgroud)

一切都工作正常,但在 TaxFieldID 中,它显示从列表计算的计数,但在保存时显示以下错误

在此输入图像描述

我该怎么办?

c# collections asp.net-mvc-4

5
推荐指数
1
解决办法
8万
查看次数

AspNetCompiler - 尝试使用不正确的格式加载程序

我正在构建一个仅64位的Web应用程序(AssemblyA)并引用我已经构建的另一个应用程序,它也是64位(AssemblyB).

当我添加AssemblyB作为引用时AssemblyA,我在Visual Studio中得到以下编译错误:

ASPNETCOMPILER无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.

我的应用程序的平台目标设置都设置为x64,两个Target Framework设置都是.Net Framework 4.6Prefer 32bit is unchecked.

我尝试引用AssemblyBin的每个依赖引用AssemblyA,确保所有依赖引用的版本相同.

我使用过这个问题:如何确定.NET程序集是为x86还是x64构建的?确认所有引用的程序集是MSILAMD64.

我使用了aspnet_compiler.exe命令行工具并errorstack启用了选项,并获得了以下堆栈跟踪:

[BadImageFormatException]:无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.

at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntro spection,Boolean suppressSecurityChecks)

在System.Reflection.RuntimeAssembly.nLoad(的AssemblyName文件名,字符串的代码库,证据assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&S tackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntros pection,布尔suppressSecurityChecks)

在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)

在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean forIntrospection)

在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark&stackMark,Boolean forIntrospection)

在System.Reflection.Assembly.Load(String assemblyString)

在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective)

[ConfigurationErrorsException]:无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.

在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective)

在System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomain …

.net c# compiler-errors compilation badimageformatexception

5
推荐指数
1
解决办法
647
查看次数

针对测试数据库集成测试Web服务

我目前正在构建一个使用WCF Web服务的.net Web应用程序,以允许Flex前端访问数据库.

我正在为Web服务设置一些单元/集成样式测试,并且正在尝试找出允许测试在单独的测试数据库中访问和修改数据的最佳方法.

目前,我的单元测试项目中的连接字符串指向我的测试数据库,我的Web服务项目中的连接字符串指向我的开发数据库.但是,当我使用Linq时,似乎当我从我的测试类调用Web服务方法时,它使用开发数据库连接字符串.

我已经研究过创建模拟对象或内存数据库,但我相信会出现同样的问题.

有没有办法让这个工作,或者我的想法是我想要的不正确,在哪种情况下有更好的方法来设置它?我在项目中的时间还早,我不会对显着改变解决方案的体系结构产生负面影响.

linq asp.net wcf unit-testing linq-to-sql

4
推荐指数
1
解决办法
1872
查看次数

CodeBuild 不报告失败的测试

我正在使用 CodeBuild 构建我的 NPM 项目。我的构建规范中有一个特定的报告组,我正在使用 Jest 和npm test命令运行单元测试。

当所有测试通过后,成功上报到 CodeBuild 报告组。但是,如果其中一项测试失败,我会收到错误消息:

[Container] 2020/08/24 01:41:18 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm test -- --silent. Reason: exit status 1`
Run Code Online (Sandbox Code Playgroud)

并且构建停止(通常很好)但未报告失败的测试,因此测试通过率保持在 100%,这意味着我看不到测试趋势或其他详细信息。

我的 buildspec.yml 的相关部分:

version: 0.2
phases:
  install:
    commands:  
      - npm install
  pre_build:
    commands:
      - npm test -- --silent    
reports:
  jest_reports:
    files:
      - 'test-results.xml'
    file-format: JunitXml
    base-directory: "reports/results"
Run Code Online (Sandbox Code Playgroud)

我的 package.json 中的 Jest 配置:

"jest": {
    "reporters": [
        "default",
        [
            "jest-junit",
            {
                "outputDirectory": "reports/results",
                "outputName": "test-results.xml" …
Run Code Online (Sandbox Code Playgroud)

unit-testing amazon-web-services jestjs aws-codebuild

3
推荐指数
1
解决办法
982
查看次数

使用.runsettings文件时,代码覆盖率中不包含异步方法

每当我在我的解决方案上运行Visual Studio 2015代码覆盖率而不指定测试设置文件时,我测试的所有Async方法都包含在覆盖结果中并且适当地着色:

在此输入图像描述

但是,当我包含.runsettings文件时,异步方法不再包含在Coverage结果中并保持未着色:

在此输入图像描述

据我所知,.runsettings文件中没有任何内容可以忽略异步方法:

<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>

            <!-- Match assembly file paths: -->
            <ModulePaths>
              <Exclude>
                <ModulePath>.*xunit.*</ModulePath>
              </Exclude>
            </ModulePaths>
            <!-- Match attributes on any code element: -->
            <Attributes>
              <Exclude>
                <!-- Don't forget "Attribute" at the end of the name -->

                <Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
                <Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
                <Attribute>^System\.Runtime\.CompilerServices.CompilerGeneratedAttribute$</Attribute>
                <Attribute>^System\.CodeDom\.Compiler.GeneratedCodeAttribute$</Attribute>
                <Attribute>^System\.Diagnostics\.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
              </Exclude>
            </Attributes>

            <!-- We recommend you do not change the following values: -->
            <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
            <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
            <CollectFromChildProcesses>True</CollectFromChildProcesses>
            <CollectAspDotNet>False</CollectAspDotNet>

          </CodeCoverage> …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing asynchronous code-coverage

2
推荐指数
1
解决办法
600
查看次数

实体框架核心很慢 - 我如何让它更快?

从数据库中检索记录并将其分配给对象.

private readonly ApplicationDbContext _context;
var itemsData = _context.Items;

for (int i = 0; i < itemsData.Count(); i++)
{
    _Response.Items.Add(new Models.Items
        {
            Name = itemsData.ToList()[i].Name,
            ....
            Created = (DateTime)itemsData.ToList()[i].Created,
            Updated = (DateTime)itemsData.ToList()[i].Updated
        });
}
Run Code Online (Sandbox Code Playgroud)

注意:记录少于1000条,并且已经显而易见.

c# database postgresql entity-framework-core

2
推荐指数
1
解决办法
2538
查看次数

如何在另一个数字的末尾添加数字

我想将一个数字加入另一个数字而不是添加它.

例如:而不是1 + 1决策2,我想它做11.

我认为我能做的唯一事情就是+ 1,但这就是它2,我想让它成为11.

.net c#

1
推荐指数
1
解决办法
113
查看次数

我创建对象时出现System.NullReferenceException消息?

它突出显示了我的对象c并说它是null,即使我在前一行创建了对象.我指的是下面的这一行.

c.wm.Add(new Dictionary<string, string>());
Run Code Online (Sandbox Code Playgroud)

这是整个事情:

public class dict
{
    public List<Dictionary<string, string>> wm;
    public dict()
    {
        List<Dictionary<string, string>> wm = new List<Dictionary<string, string>>();
    }
}    

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dict c = new dict();    
            c.wm.Add(new Dictionary<string, string>());    
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

-1
推荐指数
1
解决办法
36
查看次数