小编Jak*_*urc的帖子

FindBugs for .NET

在Java中,这是一个名为FindBugs的好工具..Net中有类似的东西吗?

.net static-analysis findbugs

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

如何在ASP.NET MVC中为经过身份验证的用户关闭输出缓存?

我有一个ASP.NET MVC应用程序.我需要缓存一些页面,但仅限于未经过身份验证的用户.

我尝试使用VaryByCustom="user"以下GetVaryByCustomString实现:

public override string GetVaryByCustomString(HttpContext context, string custom)
{
  if (custom == "user")
  {
      if (context.User.Identity.IsAuthenticated)
      {
        return context.User.Identity.Name;
      }
      else
      {
        return "";
      }
  }  

  return base.GetVaryByCustomString(context, custom);
}
Run Code Online (Sandbox Code Playgroud)

然而,这并不是我需要的,因为页面仍然被缓存.唯一的区别是现在分别为每个用户缓存.

一种可能的解决方案是Guid.NewGuid()每次用户进行身份验证时返回,但这对我来说似乎是一种巨大的资源浪费.

所以你有什么提示吗?

asp.net-mvc outputcache

15
推荐指数
2
解决办法
4220
查看次数

Apache HttpClient摘要式身份验证

基本上我需要做的是执行摘要式身份验证.我尝试的第一件事是这里提供的官方示例.但是当我尝试执行它时(通过一些小的更改,Post而不是Get方法)我得到了一个

org.apache.http.auth.MalformedChallengeException: missing nonce in challange
at org.apache.http.impl.auth.DigestScheme.processChallenge(DigestScheme.java:132)
Run Code Online (Sandbox Code Playgroud)

当这次失败时我尝试使用:

DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null), new UsernamePasswordCredentials("<username>", "<password>"));

HttpPost post = new HttpPost(URI.create("http://<someaddress>"));
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("domain", "<username>"));
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

DigestScheme digestAuth = new DigestScheme();
digestAuth.overrideParamter("algorithm", "MD5");
digestAuth.overrideParamter("realm", "http://<someaddress>");
digestAuth.overrideParamter("nonce", Long.toString(new Random().nextLong(), 36));
digestAuth.overrideParamter("qop", "auth");
digestAuth.overrideParamter("nc", "0");
digestAuth.overrideParamter("cnonce", DigestScheme.createCnonce());

Header auth = digestAuth.authenticate(new
      UsernamePasswordCredentials("<username>", "<password>"), post);
System.out.println(auth.getName());
System.out.println(auth.getValue());
post.setHeader(auth);


HttpResponse ret = client.execute(post);
ByteArrayOutputStream v2 = new ByteArrayOutputStream();
ret.getEntity().writeTo(v2);
System.out.println("----------------------------------------");
System.out.println(v2.toString()); …
Run Code Online (Sandbox Code Playgroud)

java android digest-authentication apache-commons-httpclient

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

在什么情况下System.Collections.ArrayList.Add会抛出IndexOutOfRangeException?

我们在生产环境中遇到了奇怪的错误,我们无法调试或注入日志代码.我试图解决这个问题但是跟踪堆栈跟踪让我感到困惑.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Collections.ArrayList.Add(Object value)
   at ...
Run Code Online (Sandbox Code Playgroud)

根据MSDN Add方法应该只抛出NotSupportedException.

我不知道这里发生了什么.你呢?

.net collections arraylist

14
推荐指数
3
解决办法
5853
查看次数

如何正确地在.NET中大写希腊语单词?

我们有ASP.NET应用程序,它运行着世界各地的不同客户.在这个应用程序中,我们有每种语言的字典.在字典中,我们使用小写的单词,有时我们会在代码中将其大写为排版原因.

var greek= new CultureInfo("el-GR");
string grrr = "????";
string GRRR = grrr.ToUpper(greek); // "????"
Run Code Online (Sandbox Code Playgroud)

问题是:

......如果你使用大写字母,那么它们必须如下所示: feΠΟΛΗ而不是ΠΌΛΗ,所有其他用大写字母书写的字相同

因此,通常可以在.NET中正确地使用大写的希腊语单词吗?或者我应该为希腊大写编写自己的自定义算法?

他们如何在希腊解决这个问题?

.net asp.net localization

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

秒表真的坏了吗?

秒表课程的 MSDN页面上,我发现了有趣文章的链接,该文章对秒表进行了以下说明:

但是有一些严重的问题:

  • 在具有多个处理器的PC上,这可能不可靠.由于
    BIOS中的错误,必须在同一处理器上执行Start()和Stop()才能获得正确的结果.

  • 这对于没有恒定时钟速度的处理器来说是不可靠的(大多数处理器可以降低时钟速度以节省能量).这在详细解释这里.

我有点困惑.我见过大量使用秒表的例子,没有人提到这个缺点.这有多严重?我应该避免使用秒表吗?

.net stopwatch

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

org.apache.http.entity.FileEntity在Android 6(Marshmallow)中已弃用

我正在将应用升级到org.apache.http不推荐使用的API 23 .

我当前(已弃用)的代码如下所示:

HttpClient httpClient = new DefaultHttpClient();
File file = new File(attr.Value);
String url = server_url;
HttpPost request = new HttpPost(url);
FileEntity fileEntity = new FileEntity(file, "image/png");
request.setEntity(fileEntity);
HttpResponse response = httpClient.execute(request);
String output = getContent(response.getEntity().getContent());
Run Code Online (Sandbox Code Playgroud)

我已经找到了一些关于如何使用它的建议HttpURLConnection,但它们比当前的解决方案(不能再使用)复杂得多.我正在谈论用于执行与上述相同功能的许多代码行.

示例包括:此页面此页面

有没有人有一个很好的固定更短的解决方案呢?

java android httpurlconnection apache-commons-httpclient android-6.0-marshmallow

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

Angular 6使用httpclient问题获取响应标头

我正在使用下面的代码尝试从响应头中提取值(ReturnStatus);

Keep-Alive: timeout=5, max=100
ReturnStatus: OK,SO304545
Server: Apache/2.4.29 (Win32) OpenSSL/1.0.2m
Run Code Online (Sandbox Code Playgroud)

代码;

import { Injectable } from '@angular/core';

import { Account } from './model/account';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from "rxjs";
import { map, filter, catchError, mergeMap } from 'rxjs/operators';

 createOrder(url) : Observable<any> {

  return this._http.get(url, {withCredentials: true, observe: 'response'})
  .pipe(
    map((resp: any) => {
      console.log("response", resp);
      return resp;

    }), catchError( error => {
      console.log("createOrder error",error );
      alert("Create Order Service returned an error. See server …
Run Code Online (Sandbox Code Playgroud)

angular angular-httpclient

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

是否可以确定哪个进程启动我的.Net应用程序?

我正在.Net中开发控制台应用程序,我想根据应用程序从cmd.exe或explorer.exe启动的信息稍微更改一下行为.可能吗?

.net windows process-management

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

NAnt最佳实践

我这里有300行长的NAnt文件,这是一个非常混乱.我想知道是否有任何样式指南用于编写NAnt脚本以及这样做的最佳实践.

有小费吗?

.net nant coding-style

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