使用表单身份验证,当应用程序需要重定向到登录页面时,是否有一个事件或任何可扩展点,可以让我在重定向到登录页面之前对请求执行其他工作?
我想在查询字符串中发送可能不同的其他信息,以便在web.config中的loginUrl节点的链接中静态嵌入它.
编辑:为了澄清,我想在重定向到登录页面之前拦截请求.
例:
<authentication mode="Forms">
<forms loginUrl="http://the/interwebs/login.aspx" timeout="2880"
enableCrossAppRedirects="true" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
在用户被重定向到http://the/interwebs/login.aspx之前,我希望能够打包查询值,这样网址可能会像http://the/interwebs/login.aspx一样? =刷新
作为我的Android应用程序的一部分,我想上传要远程存储的位图.我有简单的HTTP GET和POST通信工作完美,但有关如何进行多部分POST的文档似乎与独角兽一样罕见.
此外,我想直接从内存传输图像,而不是使用文件.在下面的示例代码中,我从一个文件中获取一个字节数组,以便稍后使用HttpClient和MultipartEntity.
File input = new File("climb.jpg");
byte[] data = new byte[(int)input.length()];
FileInputStream fis = new FileInputStream(input);
fis.read(data);
ByteArrayPartSource baps = new ByteArrayPartSource(input.getName(), data);
Run Code Online (Sandbox Code Playgroud)
这一切对我来说都是相当清楚的,除了我不能为我的生活找到从哪里得到这个ByteArrayPartSource.我已链接到httpclient和httpmime JAR文件,但没有骰子.我听说HttpClient 3.x和4.x之间的包结构发生了巨大的变化.
是否有人在Android中使用此ByteArrayPartSource,他们是如何导入的?
在浏览文档并搜索互联网之后,我想出了一些符合我需求的东西.要创建一个多部分请求,例如表单POST,以下代码为我做了诀窍:
File input = new File("climb.jpg");
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:3000/routes");
MultipartEntity multi = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
String line;
multi.addPart("name", new StringBody("test"));
multi.addPart("grade", new StringBody("test"));
multi.addPart("quality", new StringBody("test"));
multi.addPart("latitude", new StringBody("40.74"));
multi.addPart("longitude", new StringBody("40.74"));
multi.addPart("photo", new FileBody(input));
post.setEntity(multi);
HttpResponse resp = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
我有以下用于单元测试的存储库:
public class MyTestRepository<T>
{
private List<T> entities = new List<T>();
public IQueryable<T> Entities
{
get { return entities.AsQueryable(); }
}
public T New()
{
//return what here???
}
public void Create(T entity)
{
entities.Add(entity);
}
public void Delete(T entity)
{
entities.Remove(entity);
}
}
Run Code Online (Sandbox Code Playgroud)
我在New()方法中返回什么?
我试过这个:
public T New()
{
return (T) new Object();
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的单元测试时,这给了我以下异常:
System.InvalidCastException: Unable to cast object of type 'System.Object' to type 'MyCustomDomainType'.
Run Code Online (Sandbox Code Playgroud)
有关如何实现New()方法的任何想法?
我讨厌确定/取消对话框,因为如果我的应用程序询问某人他是否真的想要做某事你永远不应该回答"取消".
一个小例子:
final AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setIcon(android.R.drawable.ic_dialog_alert);
b.setTitle("Hello World");
b.setMessage("Did you do your homework?");
b.setPositiveButton(android.R.string.yes, null);
b.setNegativeButton(android.R.string.no, null);
b.show();
Run Code Online (Sandbox Code Playgroud)
常量"是"和"否"是否可能真的意味着"是"和"否"与本地化?或者我在我的字符串资源中明确地这样做,并且不能使用全局常量.所以我用以下代码替换这两行:
b.setPositiveButton("Yes", null);
b.setNegativeButton("No", null);
Run Code Online (Sandbox Code Playgroud)
(或者资源而不是常量)
真诚的xZise
我目前有一个以下脚本作为项目的后期构建:
if $(ConfigurationName) == "Debug (x64)" || $(ConfigurationName) == "Release (x64)" (goto :x64)
if $(ConfigurationName) == "Debug" || $(ConfigurationName) == "Release" (goto :x86)
:x64
copy "$(SolutionDir)References\x64\System.Data.SQLite.dll" "$(TargetDir)System.Data.SQLite.dll"
goto :default
:x86
copy "$(SolutionDir)References\System.Data.SQLite.dll" "$(TargetDir)System.Data.SQLite.dll"
goto :default
:default
copy "$(SolutionDir)References\System.Data.SQLite.Linq.dll" "$(TargetDir)System.Data.SQLite.Linq.dll"
Run Code Online (Sandbox Code Playgroud)
(它根据配置将x86或x64版本的程序集复制到输出文件夹)
这个脚本返回错误级别255,因为我不知道批处理脚本,有人能指出我的错误吗?
C档案:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE *ptr;
char m[200];
char *data = malloc(200);
data=getenv("QUERY_STRING");
sscanf(data,"%s", m);
printf("%s", m);
ptr=fopen("c:/test.txt", "w");
fprintf(ptr, "%s", m);
fclose(ptr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
// gcc -g print.c -o print.exe
HTML文件:
<html>
<body>
<h2>CGI Server</h2>
<p>
<form action="http://localhost/cgi-bin/print.exe">
<div><label>value: <input name="m" size="10"></label></div>
<div><input type="submit" value="Run"></div>
</form>
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果输入到网页表单是c:/data.txt,则结果为:c%3A%2Fdata.txt
发生了什么?为什么输出中的/和:损坏了?似乎问题出在QUERY_STRING上,因为getenv("PATH")不会出现这个问题.
我想要类似以下内容:
$arrayOfValues = array(1,2,3,4);
$sqlArray = mysql_convertToSqlArray($arrayOfValues);
Run Code Online (Sandbox Code Playgroud)
然后将返回 SQL 中的内容:
(1,2,3,4)
Run Code Online (Sandbox Code Playgroud)
但在 php 中将是字符串“(1,2,3,4)”
是否有任何伪随机数生成器很容易与心算,心算和手指计数.显然,这限制了相当简单的数学 - 它需要具有平均数学能力的人才能做到,或者可能是程序员的平均能力,而不是数学天才.
我发现最简单的是中间方法,但不仅知道它是一个不好的随机源,它看起来仍然太复杂,没有铅笔和纸.
如果唯一的方法是限制范围,也许它只能输出8位数,那很好.我怀疑其中一个标准的PRNG算法在8位版本中足够简单,但我不知道如何将它们从32位版本简化为8位版本.(我查看的所有内容取决于特殊选择的种子数,这些种子数根据您使用的位数而有所不同,通常只给出32位和64位示例.)
R脚本如何确定它运行的平台?我正在使用R 2.10.1,有时在Windows上,有时在Linux上.我更喜欢内置函数而不是文件系统分类.我已经在描述中用"os"或"platform"搜索了基本软件包的索引 - 没有骰子,唉.
我有一个上下文管理器,它将输出捕获到一个字符串中,用于在with语句下缩进的代码块。这个上下文管理器产生一个自定义的结果对象,当块完成执行时,它将包含捕获的输出。
from contextlib import contextmanager
@contextmanager
def capturing():
"Captures output within a 'with' block."
from cStringIO import StringIO
class result(object):
def __init__(self):
self._result = None
def __str__(self):
return self._result
try:
stringio = StringIO()
out, err, sys.stdout, sys.stderr = sys.stdout, sys.stderr, stringio, stringio
output = result()
yield output
finally:
output._result, sys.stdout, sys.stderr = stringio.getvalue(), out, err
stringio.close()
with capturing() as text:
print "foo bar baz",
print str(text) # prints "foo bar baz"
Run Code Online (Sandbox Code Playgroud)
当然,我不能只返回一个字符串,因为字符串是不可变的,因此用户从with语句中返回的字符串在他们的代码块运行后无法更改。但是,事后必须将结果对象显式转换为字符串是一件很麻烦的事str(我还尝试将对象作为一种语法糖来调用)。
那么是否有可能使结果实例像一个字符串一样运行,因为它实际上在命名时返回一个字符串?我尝试实现__get__ …