我创建了一个全新的ASP.NET MVC 5项目来测试[Authorize]属性FormsAuthentication.SetAuthCookie.我只是在一个动作中设置一个cookie(在我的Home控制器中):
public ActionResult About()
{
FormsAuthentication.SetAuthCookie("someUser", false);
Run Code Online (Sandbox Code Playgroud)
我限制访问另一个:
[Authorize]
public ActionResult Contact()
{
Run Code Online (Sandbox Code Playgroud)
当我启动我的网页并导航到时/home/contact,我被正确地重定向到登录页面.然后我去/home/about,拿到我的cookie,然后回到联系页面.但是我仍然被重定向到登录页面 - cookie没有验证/授权我.
在调试器中,HttpContext.User.Identity.IsAuthenticated == false当我多次加载About页面时(也就是说,即使在设置了auth cookie之后,它也从未将我视为已经过身份验证).
这里必须要做一些额外的步骤吗?我不应该为基本身份验证设置自己的IPrincipal,我应该吗?
如果TypeScript是JavaScript的严格超集,为什么任意对象上的点符号都是错误的?我有JS代码,我想转换到TS以获得更好的类型安全性,但所有使用点表示法(例如myObj.thing)的访问都给我错误Property 'thing' does not exist on type '{}'..当我使用括号表示法(例如,myObj['thing'])时,它可以正常工作.

我编写了一个proc-macro库来配合我正在编写的库 - 它们一起使用,前者用于抽象掉后者中的大量冗余代码。
我在 proc 宏中成功生成了多个结构和实现。我也在使用cargo doc该库,我的文档正是我所期望的。但是,我在 proc 宏中创建的文档注释未按预期工作。我的 proc 宏中的一些代码大致如下所示:
#[proc_macro_derive(MyDerive)]
pub fn derive(input: TokenStream) -> TokenStream {
...
let expanded = quote! {
...
impl #my_struct {
/// This comment doesn't show up in documentation
pub fn foo(&self, n: i32) -> bool {
false
}
/// This comment DOES show up in documentation
pub fn bar(n: i32) -> Vec<String> {
...
}
}
}
expanded.into()
}
Run Code Online (Sandbox Code Playgroud)
当我打开生成的文档时:
foo本身出现在文档中,但其注释没有bar及其评论在文档中bar …我正在尝试删除我编写并部署到 Azure Kubernetes 服务的服务(以及随附的所需 Dask 组件),当我运行 时kubectl delete -f my_manifest.yml,我的服务陷入终止状态。控制台告诉我它已被删除,但命令挂起:
> kubectl delete -f my-manifest.yaml
service "dask-scheduler" deleted
deployment.apps "dask-scheduler" deleted
deployment.apps "dask-worker" deleted
service "my-service" deleted
deployment.apps "my-deployment" deleted
Run Code Online (Sandbox Code Playgroud)
我必须Ctrl+C这个命令。当我检查我的服务时,Dask 已成功删除,但我的自定义服务尚未成功删除。如果我尝试手动删除它,它也会同样挂起/失败:
> kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP x.x.x.x <none> 443/TCP 18h
my-service LoadBalancer x.x.x.x x.x.x.x 80:30786/TCP,443:31934/TCP 18h
> kubectl delete service my-service
service "my-service" deleted
Run Code Online (Sandbox Code Playgroud)
这个问题说先删除 Pod,但我所有的 Pod 都被删除了(kubectl get pods不返回任何内容)。还有这个已关闭的 K8s 问题 …
我想对我的架构执行 JSON 验证,该架构有四个属性:
grouppartitionselectfeatures如果使用 或group,partition则features需要。如果使用select,则被features禁止。(请注意,这似乎与这个问题中的情况不同- 我不想将其设置为features“不需要”,但如果包含它,则会出现验证错误。
所以我的三个选择是:
group和featurespartition和featuresselect并不是features我将它们编码为:
"oneOf": [
{ "required": [ "group", "features" ] },
{ "required": [ "partition", "features" ] },
{ "required": [ "select" ] }
]
Run Code Online (Sandbox Code Playgroud)
但我不知道如何适当地强制features排除在最后一个选项之外 - 或者这是否有可能?
使用 PyO3,我能够从 Rust 传递类型到 Python &str:String
#[pyfunction]
fn test_str(py: Python) -> &str {
"this is a &str"
}
#[pyfunction]
fn test_string(py: Python) -> String {
"this is a String".to_string()
}
Run Code Online (Sandbox Code Playgroud)
Python 可以很好地调用这些:
>>> test_str(), type(test_str())
('this is a &str', <class 'str'>)
>>> test_string(), type(test_string())
('this is a String', <class 'str'>)
Run Code Online (Sandbox Code Playgroud)
我也能够将它们包装PyResult<&str>为PyResult<String>相同的行为。
我需要知道什么(如果有的话)以及需要采取其他步骤来确保内存在这里得到正确处理?如果我不想维护对相同字符串的引用,我是否需要告诉 GIL 有关 s 的信息,String以便它可以在必要时释放它们?
如果我需要做更多的事情,我是否还需要对其他方法执行相同的操作,例如当我创建 Rust 时struct?
#[pyfunction]
fn new_thing(py: Python) -> Thing {
Thing { foo: 1, …Run Code Online (Sandbox Code Playgroud) 我在 Rust 中有一个 struct + 实现,我返回到 Python。这个对象也可以传回给 Rust 做进一步的工作。(在我的实际代码中,我使用的是HashMap<String, MyStruct>,但即使只是直接使用结构似乎也会导致相同的问题,因此我的示例使用struct Person简单起见。)
看来,我需要impl FromPyObject for Person,但锈找不到PyAny的downcast方法
#[pyclass]
struct Person {
name: String,
age: u8,
height_cm: f32,
}
impl pyo3::FromPyObject<'_> for Person {
fn extract(any: &PyAny) -> PyResult<Self> {
Ok(any.downcast().unwrap())
^^^^^^^^ method not found in `&pyo3::types::any::PyAny`
}
}
#[pyfunction]
fn make_person() -> PyResult<Person> {
Ok(Person {
name: "Bilbo Baggins".to_string(),
age: 51,
height_cm: 91.44,
})
}
#[pyfunction]
fn person_info(py:Python, p: PyObject) …Run Code Online (Sandbox Code Playgroud) 我有一个将字节数组传递给 C# 的 Rust 函数:
#[no_mangle]
pub extern "C" fn get_bytes(len: &mut i32, bytes: *mut *mut u8) {
let mut buf : Vec<u8> = get_data();
buf.shrink_to_fit();
// Set the output values
*len = buf.len() as i32;
unsafe {
*bytes = buf.as_mut_ptr();
}
std::mem::forget(buf);
}
Run Code Online (Sandbox Code Playgroud)
在 C# 中,我可以调用它而不会崩溃。(代替崩溃,我认为这是正确的,但不是 100% 确定):
[DllImport("my_lib")] static extern void get_bytes(ref int len,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] ref byte[] bytes);
void test()
{
int len = 0;
byte[] bytes = null;
get_bytes(ref len, ref bytes); …Run Code Online (Sandbox Code Playgroud) 我创建了一个带有一些视图和控制器的MVC 5网页,添加了一些图像(gif和svg),并验证它主要在本地工作.图像显示出来,一切都按预期运行.
当我部署到Azure时,gif图像加载正常,但svg图像给我错误The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.当我使用我的Azure凭据登录我的网站的FTP时,gif和svg文件都在那里.我可以/img/loading.gif从网上访问我的文件就好了; 然而,/img/logo.svg-虽然它确实存在于目录中,并没有显示出来,当我在本地运行- 不是由我Azure的网站提供服务发现.
我不认为它是相关的,但我告诉我的网站路由现有文件:
routes.RouteExistingFiles = true;
Run Code Online (Sandbox Code Playgroud)
我的所有图像 - gif和svg - 都位于Solution 'mySolutionName' -> myMvcProjectName -> img.因此,我无法看到任何指示我的网站以不同方式处理这些文件的内容.
rust ×4
asp.net-mvc ×2
azure ×2
c# ×2
pyo3 ×2
azure-aks ×1
ffi ×1
javascript ×1
json ×1
jsonschema ×1
kubernetes ×1
rust-cargo ×1
svg ×1
typescript ×1
validation ×1