小编tug*_*erk的帖子

解密字符串时偶尔出现错误数据错误:System.Security.Cryptography.CryptographicException

在我的 ASP.NET WebForms 应用程序(该应用程序运行在 windows server 2008 R2、IIS 7.5 和 Runtime v4.0 集成模式应用程序池上,如果重要的话),我正在加密数据,将它放在 QueryString 上并使用System.Security.Cryptography.SymmetricAlgorithm类解密数据。但是我偶尔会在解密数据时遇到一些问题,我收到以下异常;

坏数据。

说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Security.Cryptography.CryptographicException:错误数据。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。

堆栈跟踪:

[加密异常:错误数据。]
System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +33
System.Security.Cryptography.Utils._DecryptData(SafeKeyHandle hKey, Byte[] data, Int32 ib, Int32 cb, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode PaddingMode, Boolean fDone) +0
System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +313
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +33 Cryptography35.SymmetricEncryptionUtility.DecryptData(Byte[] data, String keyFile) 在 E:\Documents\@Library\Cryptography35\Cryptography35\SymmetricEncryptionUtility.cs:124 Cryptography35.SymmetricedQueryString.Symmetricly ..ctor(String encryptedData, String keyfilename, String algorithmname) in E:\Documents\@Library\Cryptography35\Cryptography35\SymmetricQueryString\SymmetriclyEncryptedQueryString.cs:67 WebForms.Web.Views.purchase_a.GetSymmetriclyEncryptedQueryString() 在 E:\Documents\ WebForms.Web\Views\purchase-a.aspx.cs:35 WebForms.Web.Views.purchase_a.Page_Load(Object sender, …

.net asp.net encryption cryptography encryption-symmetric

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

仅支持初始值设定项,实体成员和实体导航属性.(ASP.NET MVC和实体框架)

我被困在我的ASP.NET MVC 3应用程序的某个地方.这是我得到的错误:

LINQ to Entities不支持指定的类型成员'AccommPropertyTags'.仅支持初始值设定项,实体成员和实体导航属性.

我已经找到了如何在以下文章中解决这个问题:

仅支持初始值设定项,实体成员和实体导航属性

但我的有点奇怪.

这是我的实体的部分类之一:

[MetadataType(typeof(AccommPropertyWebDetail.MetaData))]
public partial class AccommPropertyWebDetail {

    public virtual ICollection<string> AccommPropertyTags {

        get {

            return Helpers.AccommPropertyTag.CreateStringListFromString(this.PropertyTags);
        }
    }

    private class MetaData {

        [Required, StringLength(50)]
        public string Category { get; set; }

    }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,AccommPropertyTags属性是typeof ICollection<string>.我在控制器中尝试的内容如下:

public ViewResult Tag(string tag) {

    var _rawTag = HttpUtility.UrlDecode(tag);

    ViewBag.Tag = _rawTag;

    var model = _accommpropertyrepo.GetAllAccommPropertiesFullWebIgnoringApprovalStatus();

    model = model.Where(
            x => x.AccommPropertyTags.Any(
                    y => y == _rawTag
                )
        );

    return View(model);
}
Run Code Online (Sandbox Code Playgroud)

由于我在 …

c# asp.net-mvc entity-framework entity-framework-4.1 asp.net-mvc-3

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

Visual Studio 11开发人员预览版中的Visual C#SQL CLR数据库项目

我无法Visual C# SQL CLR Database Project在Visual Studio 11开发人员预览版中找到.只有与SQL Server相关的东西是SQL Server Database Project.

在VS 11 Dev上为SQL Server开发和部署CLR Project的方法是什么?预习?

sql-server visual-studio-2010 visual-studio visual-studio-2012

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

自定义验证:从validationContext获取属性名称

对于我的 ASP.NET MVC 项目,我创建了一个自定义验证属性。这是我正在努力解决的代码:

  protected override ValidationResult IsValid(object value, ValidationContext validationContext) {

        //Here I need to resolve the url in order to make a call to that controller action and get the JSON result back

        var httpContext = new HttpContextWrapper(HttpContext.Current);
        var urlHelper = new UrlHelper(
            new System.Web.Routing.RequestContext(
                httpContext, new System.Web.Routing.RouteData()
            )
        );
        var url = urlHelper.Action(Action, Controller, null, 
            urlHelper.RequestContext.HttpContext.Request.Url.Scheme);

        var fullUrl = string.Format("{0}?{1}={2}", url, 
            /*validationContext.MemberName*/"term", value);

        if (!GetResult(fullUrl)) {

            var message = FormatErrorMessage(validationContext.DisplayName);
            return new ValidationResult(message);
        }

        return null;
    } …
Run Code Online (Sandbox Code Playgroud)

.net asp.net asp.net-mvc asp.net-mvc-validation asp.net-mvc-3

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

HttpClient GetStringAsync - 它永远不会回来

新的ASP.NET Web API HttpClient给了我一些奇怪的结果.这是我的代码:

class Program {

    static async void Main(string[] args) {

        var address = "http://localhost:3895/api/urls";

        Console.WriteLine(await getStringAsync(address));
        Console.ReadLine();

    }

    public static async Task<string> getStringAsync(string uri) {

        var httpClient = new HttpClient();
        return await httpClient.GetStringAsync(uri);
    }
}
Run Code Online (Sandbox Code Playgroud)

这永远不会回来,控制台突然出现并消失.当我更改下面的代码时,它的工作原理应该是:

static void Main(string[] args) {

    var address = "http://localhost:3895/api/urls";

    Console.WriteLine(getString(address));
    Console.ReadLine();

}

public static string getString(string uri) { 

    var httpClient = new HttpClient();

    return httpClient.GetStringAsync(uri).Result;
}
Run Code Online (Sandbox Code Playgroud)

关于什么是问题的任何想法?

c# httpclient async-await c#-5.0 asp.net-web-api

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

分页和内部联接

我有一种情况需要我做分页INNET JOIN.这是我的类似场景:

DECLARE @categories AS TABLE(
    CatID INT,
    CategoryName NVARCHAR(100)
);

DECLARE @fooTable AS TABLE(
    ID INT,
    CatID INT,
    Name NVARCHAR(100),
    MinAllow INT,
    Price DECIMAL(18,2)
);

INSERT INTO @categories  VALUES(1, 'Cat1');
INSERT INTO @categories  VALUES(2, 'Cat2');
INSERT INTO @categories  VALUES(3, 'Cat3');
INSERT INTO @categories  VALUES(4, 'Cat4');
INSERT INTO @categories  VALUES(5, 'Cat5');

INSERT INTO @fooTable  VALUES(1, 1, 'Product1', 2, 112.2);
INSERT INTO @fooTable  VALUES(3, 1, 'Product3', 5, 233.32);
INSERT INTO @fooTable  VALUES(6, 1, 'Product6', 4, 12.43);
INSERT INTO @fooTable …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server inner-join sql-server-2008-r2

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

检查Cache后,System.Web.HttpContext.Current自身为空

我今天遇到了一个奇怪的问题,对我来说毫无意义.以下是摘要:

在方法内部,我检查一个缓存的项目如下:

private async Task<RatesStatus> getRatesStatusAsync() {

    //...

    if (_currentHttpContext != null) {

        //Here, I am checking for a Cached item
        var cachedRatesStatusObj = HttpContext.Current.Cache[Constants.RATESSTATUS_CACHE_KEY_NAME];
        if (cachedRatesStatusObj != null)
            return (RatesStatus)cachedRatesStatusObj;
    }

    //...

    cacheRatesStatusObject(ratesStatus);

    //...
}
Run Code Online (Sandbox Code Playgroud)

这里,HttpContext.CurrentASP.NET应用程序中的预期值不是预期的.然后,在cacheRatesStatusObject方法内部,我检查是否HttpContext.Current为null,如下所示:

private void cacheRatesStatusObject(RatesStatus ratesStatus) {

    //...

    //Seeing if HttpContext.Current is null or not first.
    //and it is null here...
    if (HttpContext.Current == null)
        return;

    //...
}
Run Code Online (Sandbox Code Playgroud)

它在那里是空的.不知道这里发生了什么.有什么想法吗?

asp.net caching httpcontext system.web

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

当我尝试将值设置为xml属性时,powershell奇怪地编码&符号

在我的构建脚本中,我有一个helper powershell函数,如下所示:

function set-connectionstring {
  param($path, $name, $value)
  $settings = [xml](get-content $path)
  $setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name }
  $setting.connectionString = "$value"
  $setting.providerName = "System.Data.SqlClient"
  $resolvedPath = resolve-path($path) 
  $settings.save($resolvedPath)
}
Run Code Online (Sandbox Code Playgroud)

它工作得很好,除了当我尝试设置值时,它奇怪地编码了&符号.这是问题:

在我的连接字符串里面,我&quot有价值.这应该是完全有效的.但是,我的上述代码将此转换&amp;quot;为完全不合理的.你知道我能解决这个问题吗?

xml powershell build-script powershell-2.0

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

选择操作时,ASP.NET Web Api会忽略RouteParameter.Optional

我通过以下步骤找到了此问题:

  1. 使用已安装的项目模板创建一个新的WebApi项目

  2. 转到Controllers/ValuesController.cs,有两个这样的Get方法:

    public IEnumerable<string> Get() //这个提供了GetAll功能

    public string Get(int id) //这个是GetOneById

  3. 我不喜欢这个设计,因为我认为两个api方法可以组合成一个:

    public IEnumerable<string> Get(string ids) 当ids为null时,它返回所有记录,否则返回id的结果(看起来像id1,id2,id3 ......)

我也修改了路线:

    config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{ids}",
            defaults: new { ids = RouteParameter.Optional }
        );
Run Code Online (Sandbox Code Playgroud)

现在我觉得一切都准备好了.但是当我/values在浏览器中访问时(没有指定ids参数),我被告知"没有找到任何操作",直到我添加一个默认值ids:

public IEnumerable<string> Get(string ids = null)
Run Code Online (Sandbox Code Playgroud)

从现在开始,一切都按照我的预期运作.我仍然无法defaults在路线中移动参数.这意味着:代码将ids参数声明为可选两次.

查看位于System.Web.Http.Controllers.ActionSelectorCacheItem.FindActionUsingRouteAndQueryParameters方法的MVC4的源代码,我可以看到在找到正确的操作时忽略路由中定义的可选参数.就个人而言,我认为这真的很糟糕,即使是变通方法也很容易.或者我误解了路线和行动方法之间的关系?我认为路由是用于帮助请求查找其相应操作的规则,而"参数是可选的"恰好是规则的一部分.

c# asp.net-mvc asp.net-mvc-4 asp.net-web-api

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

FindAndModify在哪里适合CQRS?

在我当前的应用程序中,我FindAndModify对MongoDB服务器进行了以下MongoDB 调用

public static TEntity PeekForRemoveSync<TEntity>(this MongoCollection<TEntity> collection, string reason)
    where TEntity : class, IEntity, IUpdatesTrackable, ISyncable, IDeletable, IApprovable
{
    if (reason == null)
    {
        throw new ArgumentNullException(nameof(reason));
    }

    IMongoQuery query = Query.And(
        Query<TEntity>.EQ(e => e.SyncInfo.IsDirty, true),
        Query<TEntity>.NE(e => e.Deletion, null),
        Query<TEntity>.NE(e => e.Approval, null),
        Query<TEntity>.EQ(e => e.SyncInfo.HumanInvestigateFlag, null),
        Query.Or(
            Query<TEntity>.EQ(e => e.SyncInfo.IsUpdateInProgress, false),
            Query<TEntity>.LT(e => e.SyncInfo.UpdateStartInfo.OccuredOn, DateTime.UtcNow.AddSeconds(-SyncConstants.PeekExpireTimeInSeconds))
        ),
        Query<TEntity>.LTE(e => e.SyncInfo.PeekedCount, MaxPeekedCount)
    );

    return PeekForSync(collection, query, reason);
}

private static TEntity PeekForSync<TEntity>(this MongoCollection<TEntity> collection, IMongoQuery query, string …
Run Code Online (Sandbox Code Playgroud)

c# mongodb cqrs

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