小编Dan*_*ola的帖子

ASP.NET_SessionId + OWIN Cookies不会发送到浏览器

使用Owin cookie身份验证时遇到一个奇怪的问题.

当我启动我的IIS服务器时,身份验证在IE/Firefox和Chrome上运行得非常好.

我开始使用身份验证进行一些测试并在不同的平台上登录,我想出了一个奇怪的错误.偶尔Owin框架/ IIS只是不向浏览器发送任何cookie.我将输入一个用户名和密码,该代码运行正确,但根本没有cookie传递给浏览器.如果我重新启动服务器它开始工作,那么在某些时候我将尝试登录并再次cookie停止交付.单步执行代码不会做任何事情并且不会抛出任何错误.

 app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationMode = AuthenticationMode.Active,
            CookieHttpOnly = true,
            AuthenticationType = "ABC",
            LoginPath = new PathString("/Account/Login"),
            CookiePath = "/",
            CookieName = "ABC",
            Provider = new CookieAuthenticationProvider
               {
                  OnApplyRedirect = ctx =>
                  {
                     if (!IsAjaxRequest(ctx.Request))
                     {
                        ctx.Response.Redirect(ctx.RedirectUri);
                     }
                 }
               }
        });
Run Code Online (Sandbox Code Playgroud)

在我的登录程序中,我有以下代码:

IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                            authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);

var authentication = HttpContext.Current.GetOwinContext().Authentication;
var identity = new ClaimsIdentity("ABC");
identity.AddClaim(new Claim(ClaimTypes.Name, user.Username));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.User_ID.ToString()));
identity.AddClaim(new Claim(ClaimTypes.Role, role.myRole.ToString()));
    authentication.AuthenticationResponseGrant =
        new AuthenticationResponseGrant(identity, new AuthenticationProperties()
                                                   {
                                                       IsPersistent = isPersistent
                                                   }); …
Run Code Online (Sandbox Code Playgroud)

asp.net owin katana asp.net-identity

136
推荐指数
5
解决办法
6万
查看次数

Azure表存储返回400 Bad Request

我在调试模式下运行它,并附上一个包含异常细节的图像.我怎么知道出了什么问题?我试图在表格中插入数据.天蓝不能给我更多细节?

Obs:存储在Windows Azure上而不在我的机器上.表已创建,但插入数据时出现此错误

在此输入图像描述

// Retrieve the storage account from the connection string.
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***");

// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

// Create the table if it doesn't exist.
CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory");
table.CreateIfNotExists();
Run Code Online (Sandbox Code Playgroud)

这是插入代码:

public static void SetStatus(Employee e, bool value)
{
    try
    {
        // Retrieve the storage account from the connection string.
        Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=###;AccountKey=###");

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "people" …
Run Code Online (Sandbox Code Playgroud)

c# exception azure azure-table-storage

111
推荐指数
5
解决办法
6万
查看次数

如何防止表单从客户端多次提交?

有时,当响应很慢时,可能会多次单击"提交"按钮.

如何防止这种情况发生?

javascript submit

89
推荐指数
10
解决办法
12万
查看次数

如何将JavaScript日期对象转换为刻度

我应该如何将JavaScript日期对象转换为刻度?我希望在同步数据后使用刻度来获取C#应用程序的确切日期.

javascript c#

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

无法比较'System.Collections.Generic.ICollection`1类型的元素仅支持基本类型,枚举类型和实体类型

我写了这段代码

IQueryable<Site> sites = context.MainTable.Include("RelatedTable");

if (!string.IsNullOrEmpty(param1)) {
    sites = sites.Where(s => s.RelatedTable != null && s.RelatedTable.Any(p => p.Name == param1.ToLower() && p.PolicyType == "primary"));
}

foreach (string secondaryPolicy in secondaryPolicies)
{
    sites = sites.Where(s => s.RelatedTable != null && s.RelatedTable.Any(p => p.Name == secondaryPolicy.ToLower() && p.PolicyType == "secondary"));
}

return sites.ToList();
Run Code Online (Sandbox Code Playgroud)

但是ToList在线上我得到了例外

无法比较'System.Collections.Generic.ICollection`1 [[Project1,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]'类型的元素.仅支持基本类型,枚举类型和实体类型.

c# linq entity-framework

36
推荐指数
4
解决办法
3万
查看次数

尝试Catch之外:await Task.Run(()

尝试捕捉外面:await Task.Run(() =>有意义或只是在等待中使用它们?

private async void Test()
{
     try
     {
         await Task.Run(() =>
         {
             try
             {
                  DoingSomething();
             }
             catch (Exception ex)
             {
                  log.Error(ex.Message);
             }
         });
      }
      catch (Exception ex)
      {
          log.Error(ex.Message);
      }
}
Run Code Online (Sandbox Code Playgroud)

.net c# try-catch async-await

12
推荐指数
2
解决办法
2万
查看次数

从LESS获得缩小的CSS输出的最佳方法是什么?

是否有可能自动从LESS获得缩小的编译CSS?每次我改变一些东西,我都要手动压缩它.

我使用less.js来编译LESS.

谢谢.

minify less

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

如何为对象类型设置React默认道具

我们已经知道,如何设置defaultProps.

TestComponent.defaultProps = {
    isTest: true
};
Run Code Online (Sandbox Code Playgroud)

但我经常使用道具作为对象类型.

在父母,

render(){
    let sample = {
        isTest : true,
        isLoggedIn : true
    }
    return (
        <div>
            <TestComponent sample = {sample} />
        </div>
    )
}
Run Code Online (Sandbox Code Playgroud)

在子组件,我想设置isLoggedInfalse默认.如果未设置(或未从Parent传递)isLoggedIn,则默认值为true

但我不知道如何设置defaultProps object type

TestComponent.defaultProps = {
    sample : {
        isLoggedIn: false
    }
};
Run Code Online (Sandbox Code Playgroud)

这该怎么做 ?

reactjs

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

序列化"System.Reflection"类型的对象时检测到循环引用

我有一个像这样的asp.net MVC 3控制器动作方法:

public JsonResult GetRecordingRates(int Id)
{            
    List<DefaultRateChart> defaultRateCharts = new List<DefaultRateChart>();
    using (IDefaultRateChartManager defaultRateChartManager = new ManagerFactory().GetDefaultRateChartManager()) {
       defaultRateCharts = defaultRateChartManager.GetAll().Where(rc => rc.Currency.Id == Id && (!rc.NumberPrefix.StartsWith("#") || rc.NumberPrefix.StartsWith("Default")) && rc.AccountCredit == "Credit").ToList();
    }
    return Json(defaultRateCharts);
}
Run Code Online (Sandbox Code Playgroud)

我想将此列表发送到jquery ajax成功方法,但我收到 500内部服务器错误

我的ajax调用是这样的:

$.ajax({
type: "POST",
dataType: "json",
url: "/Home/GetRecordingRates",
data: {
    Id: $("#hdCurrencyId").val()                 
},
success: function (data) {
        alert(data);
   }
}); 
Run Code Online (Sandbox Code Playgroud)

在响应标签下的firebug XHR中,它说:

序列化"System.Reflection.RuntimeModule"类型的对象时检测到循环引用.

[编辑]

我将动作方法更改为:

public JsonResult GetRecordingRates(int Id)
{
    List<DefaultRateChart> defaultRateCharts = new List<DefaultRateChart>();
    using (IDefaultRateChartManager defaultRateChartManager …
Run Code Online (Sandbox Code Playgroud)

asp.net ajax jquery json asp.net-mvc-3

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

比较两个数据集 - 查找更改 - LINQ

我已经在互联网上试图找到解决方案,也许我不会以正确的方式解决这个问题.

我需要比较两个数据集,结构相同,并希望找到新的和更改的对象(使用LINQ).

使用我在CodeProject中找到的内容,我能够将已更改的项目列表汇总在一起,但这是通过对每个列进行硬编码(并且会有很多)并检查相同的值来完成的:

var updRec = from u in updated
             join o in orig
                on u.KeyValue equals o.KeyValue
             where
                (o.Propery1 != u.Propery1) ||
                (o.Propery2 != u.Propery2)
             select new record
             {
                 KeyValue = u.KeyValue,
                 Propery1 = u.Propery1,
                 Propery2 = u.Propery2 ,
                 RecordType = "mod" // Modified
             };
Run Code Online (Sandbox Code Playgroud)

我可以使用2件事的帮助:

  1. 是否有更有效的方法来遍历每个列,因为我计划添加更多需要比较的属性?必须有一种更好的方法来动态检查2个相同的数据集以进行更改.
  2. 我怎么能看到哪个属性发生了变化?例如,为所有不相同的项创建"Property,OriginalValue,UpdatedValue"列表?

希望这很好地解释了它.如果我没有正确地查看它,请随时指出处理此方案的其他方法.

c# linq

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