小编mls*_*ves的帖子

使用ASP.NET MVC和表单身份验证的不同URL的不同LoginUrl

我有一个ASP.NET MVC项目,我想为网站的不同区域提供不同的LoginUrl.根据站点的区域,输入不同类型的凭据.

http://host.com/widget/home应该将用户重定向到http://host.com/widget/logon.

http://host.com/admin/home应该将用户重定向到http://host.com/admin/logon.

到目前为止,我提出的最佳解决方案是在web.config中使用Forms Auth loginUrl ="〜/ Account/Logon":

   <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880"/>
   </authentication>
Run Code Online (Sandbox Code Playgroud)

在帐户的控制器中:

public ActionResult LogOn()
{
   //redirect depending on the returnUrl?
   string returnUrl = ControllerContext.Controller.ValueProvider["ReturnUrl"].AttemptedValue;
   if (returnUrl.StartsWith("/widget"))
   {
       return Redirect(string.Format("/widget/Logon?ReturnUrl={0}", returnUrl));
   }
   if (returnUrl.StartsWith("/admin"))
   {
       return Redirect(string.Format("/admin/Logon?ReturnUrl={0}", returnUrl));
   }
   return View();
}
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

asp.net-mvc forms-authentication

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

有人用过.NET中的Win32 API函数CredWrite吗?

我正在尝试使用CredWrite,但出现ERROR_INVALID_PARAMETER 87 (0x57)错误。目的是有一个安全的位置来保存我的 .net WPF 应用程序的用户密码。

我的代码:

public class CredMan
{
    private const string TARGET_PREFIX = "myappname:";

    public static void SavePassword(string username, string password)
    {
        Win32CredMan.Credential cred = new Win32CredMan.Credential();
        cred.Flags = 0;
        cred.Type = Win32CredMan.CRED_TYPE.GENERIC;
        cred.TargetName = TARGET_PREFIX + username;

        var encoding = new System.Text.UTF8Encoding();
        cred.CredentialBlob = encoding.GetBytes(password);
        cred.Persist = Win32CredMan.CRED_PERSIST.LOCAL_MACHINE;
        cred.UserName = username;

        bool isGood = Win32CredMan.CredWrite(cred, 0);
        int lastError = Marshal.GetLastWin32Error();

    }
}
Run Code Online (Sandbox Code Playgroud)

这是 win32 包装器:(大部分来自pinvoke.net

internal class Win32CredMan
{
    [DllImport("Advapi32.dll", …
Run Code Online (Sandbox Code Playgroud)

.net c# winapi credentials marshalling

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

测试Google的ClientLogin

我有一个WPF表单,它使用ClientLogin将用户登录到他们的Google帐户.

具体来说,我想测试我的CAPTCHA处理路由.我似乎无法让我的帐户生成CAPTCHA.

有没有人对如何可靠地让Google ClientLogin要求CAPTCHA挑战进行测试有任何建议?

google-api

4
推荐指数
1
解决办法
681
查看次数

从集合中删除模型时,Marionette CollectionView会重新渲染

我想出了我的问题,但我想知道为什么,这样我(希望)可以更好地理解木偶/骨干.

问题以下代码在删除项目时会更新视图:

var MainView = Marionette.ItemView.extend({
    template: "#sample-template",
    events :{
        "click #remove" : "remove"
    },
    remove: function(){            
        this.trigger("property:remove", this.model);
    }
});
var CollectionView = Marionette.CollectionView.extend({
    itemView: MainView,
    initialize: function(){
        this.on("itemview:property:remove", function(view, model){
            alert(this.collection.length);
            this.collection.remove(model);
            alert(this.collection.length);
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

一个JsFiddle,可以看到它的所有荣耀

修复下面的代码确实按预期更新了视图:

var MainView = Marionette.ItemView.extend({
    template: "#sample-template",
    triggers :{
        "click #remove" : "property:remove"
    },
});

var CollectionView = Marionette.CollectionView.extend({
    itemView: MainView,
    initialize: function(){
        this.on("itemview:property:remove", function(view, model){
            alert(this.collection.length);
            this.collection.remove(view.model);
            alert(this.collection.length);
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

jsFiddle

backbone.js marionette

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

在类中查找属性的类型

我想确定一个类中属性的类型.我setattr用来设置值,我想检查预期的类型,以便我可以在调用之前正确转换字符串值setattr.

你是如何在python中做到这一点的?

编辑1-目前为止基于答案的一些其他信息:

我只知道我想要类型的属性的名称,这里是一些代码:

def populate_object_properties(values_as_strings, 
                               object_to_populate, 
                               properties_to_populate):
    for k in properties_to_populate:        
        value = values_as_strings.get(k)
        if value:
            setattr(object_to_populate, k, value)
        else:
            setattr(object_to_populate, k, None)
Run Code Online (Sandbox Code Playgroud)

我想value在打电话之前测试一下这是正确的类型setattr.

编辑2-我需要验证类型的原因是,我使用的是Google AppEngine的db.Model作为基类型object_to_populate,并且在将字符串放入int类型时不喜欢.我试图让问题尽可能简单,但也许这条信息会对某人的回答产生影响.(?)

python google-app-engine

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