在Java中,这是一个名为FindBugs的好工具..Net中有类似的东西吗?
我有一个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()每次用户进行身份验证时返回,但这对我来说似乎是一种巨大的资源浪费.
所以你有什么提示吗?
基本上我需要做的是执行摘要式身份验证.我尝试的第一件事是这里提供的官方示例.但是当我尝试执行它时(通过一些小的更改,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
我们在生产环境中遇到了奇怪的错误,我们无法调试或注入日志代码.我试图解决这个问题但是跟踪堆栈跟踪让我感到困惑.
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.
我不知道这里发生了什么.你呢?
我们有ASP.NET应用程序,它运行着世界各地的不同客户.在这个应用程序中,我们有每种语言的字典.在字典中,我们使用小写的单词,有时我们会在代码中将其大写为排版原因.
var greek= new CultureInfo("el-GR");
string grrr = "????";
string GRRR = grrr.ToUpper(greek); // "????"
Run Code Online (Sandbox Code Playgroud)
问题是:
......如果你使用大写字母,那么它们必须如下所示: feΠΟΛΗ而不是ΠΌΛΗ,所有其他用大写字母书写的字相同
因此,通常可以在.NET中正确地使用大写的希腊语单词吗?或者我应该为希腊大写编写自己的自定义算法?
他们如何在希腊解决这个问题?
我正在将应用升级到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
我正在使用下面的代码尝试从响应头中提取值(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) 我正在.Net中开发控制台应用程序,我想根据应用程序从cmd.exe或explorer.exe启动的信息稍微更改一下行为.可能吗?
我这里有300行长的NAnt文件,这是一个非常混乱.我想知道是否有任何样式指南用于编写NAnt脚本以及这样做的最佳实践.
有小费吗?
.net ×6
android ×2
java ×2
angular ×1
arraylist ×1
asp.net ×1
asp.net-mvc ×1
coding-style ×1
collections ×1
findbugs ×1
localization ×1
nant ×1
outputcache ×1
stopwatch ×1
windows ×1