小编spo*_*ahn的帖子

将datetime2数据类型转换为日期时间数据类型会导致超出范围的值

我的HomeController中有以下代码:

public ActionResult Edit(int id)
{
    var ArticleToEdit = (from m in _db.ArticleSet where m.storyId == id select m).First();
    return View(ArticleToEdit);
}

[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Article ArticleToEdit)
{
    var originalArticle = (from m in _db.ArticleSet where m.storyId == ArticleToEdit.storyId select m).First();
    if (!ModelState.IsValid)
        return View(originalArticle);

    _db.ApplyPropertyChanges(originalArticle.EntityKey.EntitySetName, ArticleToEdit);
    _db.SaveChanges();
    return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)

这是Edit方法的视图:

<% using (Html.BeginForm()) {%>

    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="headline">Headline</label>
            <%= Html.TextBox("headline") %>
        </p>
        <p>
            <label for="story">Story <span>( HTML Allowed )</span></label>
            <%= Html.TextArea("story") %>
        </p>
        <p>
            <label for="image">Image …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

170
推荐指数
7
解决办法
22万
查看次数

Azure AD应用程序权限与委派权限

我正在创建一个Azure AD应用程序,并注意到有两种权限类型,即应用程序权限和委派权限.两者之间有什么区别,在什么情况下我应该使用它们?

security azure azure-active-directory

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

Invalid object name 'dbo.__MigrationHistory' using Database.Create; EF6.02 when connection string is passed in

I experience an error when trying to create a database using the following code. Note the problem does not happen if the connection string is not passed in. Also the problem happens when I run the program in the IDE. It does not happen if I run the program .exe or if I run the unit tests within the IDE.

However if the database is created by running the unit tests or by running the .EXE then the __MigrationHistory table …

package-managers entity-framework-6

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

使用C#和SymmetricAlgorithm进行真正简单的加密

我正在寻找一种非常简单的crypt/decrypt方法.我将始终使用相同的静态密钥.我知道这种方法的风险.目前我正在使用以下代码,但在加密和删除相同的字符串后,它不会生成相同的结果(字符串中间有一些垃圾).

public static string Crypt(this string text)
{
    string result = null;

    if (!String.IsNullOrEmpty(text))
    {
        byte[] plaintextBytes = Encoding.Unicode.GetBytes(text);

        SymmetricAlgorithm symmetricAlgorithm = DES.Create();
        symmetricAlgorithm.Key = new byte[8] {1, 2, 3, 4, 5, 6, 7, 8};
        using (MemoryStream memoryStream = new MemoryStream())
        {
            using (CryptoStream cryptoStream = new CryptoStream(memoryStream, symmetricAlgorithm.CreateEncryptor(), CryptoStreamMode.Write))
            {
                cryptoStream.Write(plaintextBytes, 0, plaintextBytes.Length);
            }

            result = Encoding.Unicode.GetString(memoryStream.ToArray());
        }
    }

    return result;
}

public static string Decrypt(this string text)
{
    string result = null;

    if (!String.IsNullOrEmpty(text))
    {
        byte[] …
Run Code Online (Sandbox Code Playgroud)

c# encryption des encryption-symmetric

27
推荐指数
3
解决办法
7万
查看次数

Automapper ResolveUsing或MapFrom

我将映射定义定义为

Mapper.CreateMap<Calculator, CalculatorViewModel>()
  .ForMember(dest => dest.TypeIndicator, src => src.ResolveUsing(new TypeIndicatorResolver()));
Run Code Online (Sandbox Code Playgroud)

我应该使用ResolveUsing还是MapFrom(src => SomePrivateMethod())

ResolveUsing和MapFrom在复杂映射方面有什么区别.

Resolver或Private方法将转到数据库并获取值.

automapper

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

角度重定向到默认子视图

我有以下路由配置,但我收到错误 Invalid configuration of route 'tenant': redirectTo and children cannot be used together

一旦我点击/租户,我想以某种方式显示两个租户的内容,然后审计?这可能吗 ?我的租户网址如下所示http://localhost:8080/#/tenant

{
    path: 'tenant',
    redirectTo: '/tenant/(view:audit)', 
    pathMatch: 'full',
    component: TenantComponent,
    data: {
        authorities: ['ROLE_USER', 'ROLE_ADMIN'],
        pageTitle: 'tenant.home.title'
    },
    children: [
        {
            path: 'audit',
            component: PacketDataComponent,
            data: {
                authorities: ['ROLE_USER', 'ROLE_ADMIN'],
                pageTitle: 'tenant.home.title'
            },
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

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

Azure门户:错误请求 - 请求太长

当我尝试从portal.azure.com运行内置b2c编辑策略时,我刚刚收到以下错误.我打开了2个门户选项卡.为什么我收到此错误?

错误请求 - 请求太长HTTP错误400.请求标头的大小太长.

注意:在测试active-directory-b2c-dotnet-webapp-and-webapi示例项目时,我遇到了同样的错误消息.提供的原因是我发送了太多cookie.是同样的问题吗?

如果是同样的问题,在创建新的cookie之前是否应该删除陈旧的cookie


我确实为https://login.microsoftonline.com看到了很多cookie

铬饼干节点

屏幕截图1的饼干 屏幕截图2的饼干

azure-active-directory azureportal azure-ad-b2c

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

将Application Insights与单元测试结合使用?

我有一个MVC网络应用程序,我正在使用Simple Injector进行DI.我的几乎所有代码都包含在单元测试中.但是,现在我已经在某些控制器中添加了一些遥测调用,我在设置依赖项时遇到了麻烦.

遥测调用用于将指标发送到Microsoft Azure托管的Application Insights服务.该应用程序未在Azure中运行,只是一个带有ISS的服务器.AI门户网站会告诉您有关应用程序的各种信息,包括使用遥测库发送的任何自定义事件.因此,控制器需要一个Microsoft.ApplicationInsights.TelemetryClient实例,该实例没有接口,并且是一个带有2个构造函数的密封类.我试着像这样注册它(混合生活方式与这个问题无关,我只是为了完整而包含它):

// hybrid lifestyle that gives precedence to web api request scope
var requestOrTransientLifestyle = Lifestyle.CreateHybrid(
    () => HttpContext.Current != null,
    new WebRequestLifestyle(),
    Lifestyle.Transient);

container.Register<TelemetryClient>(requestOrTransientLifestyle);
Run Code Online (Sandbox Code Playgroud)

问题是,由于TelemetryClient有2个构造函数,SI抱怨并且验证失败.我找到了一篇文章,展示了如何覆盖容器的构造函数解析行为,但这似乎相当复杂.首先,我想要备份并提出这个问题:

如果我没有使TelemetryClient成为一个注入的依赖项(只是在类中创建一个新的),那么在每次运行单元测试时是否会将遥测发送到Azure,从而产生大量错误数据?或者Application Insights是否足够聪明,知道它在单元测试中运行,而不是发送数据?

对此问题的任何"见解"将不胜感激!

谢谢

c# unit-testing azure simple-injector azure-application-insights

16
推荐指数
5
解决办法
6455
查看次数

ASP.Net Core 2.0混合身份验证JWT和Windows身份验证不接受凭据

我在asp.net core 2.0中创建了API,我正在使用混合模式身份验证.对于一些控制器JWT和一些使用Windows身份验证.

我对使用JWT授权的控制器没有任何问题.但对于我想要使用Windows身份验证的控制器,我无限期地提示使用chrome的用户名和密码对话框.

这里是我的示例控制器代码,我想使用Windows身份验证而不是JWT.

[Route("api/[controller]")]
[Authorize(AuthenticationSchemes = "Windows")]
public class TestController : Controller
{
    [HttpPost("processUpload")]
    public async Task<IActionResult> ProcessUploadAsync(UploadFileModel uploadFileModel)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我的配置服务代码

public void ConfigureServices(IServiceCollection services)
{
     services.AddAuthentication(options =>
     {
        options.DefaultAuthenticateScheme = IISDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
     })
     .AddJwtBearer("Bearer", options =>
     {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateAudience = false,       
            ValidateIssuer = false,  
            ValidateIssuerSigningKey = true,
            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("blahblahKey")),
            ValidateLifetime = true, //validate the expiration and not before values in the token
            ClockSkew = TimeSpan.FromMinutes(5) //5 minute …
Run Code Online (Sandbox Code Playgroud)

c# authorization authorize-attribute asp.net-core-2.0

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

如何在.Net Core类库中使用Rijndael加密?(不是.Net Framework)

我们如何在.Net Core类库中使用Rijndael加密?(不是.Net Framework类库)我们需要创建一个共享的.Net Core库,用于多个项目,并且需要实现在项目中使用相同Rijndael加密的Encrypt和Decrypt方法.

我们目前正在使用:

  • VS企业版2015
  • C#
  • .Net核心类库
  • .NETStandard,Version = v1.6参考

似乎.Net Core 1.0版本中缺少Rijndael和AES的实现...它似乎只包括基类.我们如何获得Rijndael或AES加密的.Net Core实现作为新的.Net核心类库项目的参考?

以下是在.Net Framework 4.5.2中使用的Encrypt方法:

public static string Encrypt(string valueToEncrypt, string symmetricKey, string initializationVector)
{
    string returnValue = valueToEncrypt;

    var aes = new System.Security.Cryptography.RijndaelManaged();
    try
    {
        aes.Key = ASCIIEncoding.ASCII.GetBytes(symmetricKey);
        aes.IV = ASCIIEncoding.ASCII.GetBytes(initializationVector);
        aes.Mode = CipherMode.CBC;
        aes.Padding = PaddingMode.ISO10126;

        var desEncrypter = aes.CreateEncryptor();
        var buffer = ASCIIEncoding.ASCII.GetBytes(valueToEncrypt);

        returnValue = Convert.ToBase64String(desEncrypter.TransformFinalBlock(buffer, 0, buffer.Length));
    }
    catch (Exception)
    {
        returnValue = string.Empty;
    }

    return returnValue;
}
Run Code Online (Sandbox Code Playgroud)

.net c# cryptography rijndaelmanaged .net-core

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