Asp.net mvc 如何在Microsoft.AspNet.Mvc.Facebook.Facebook中动态设置权限? 控制器 过载
编译错误 在上面的代码块中,我们有以下代码Asp.net mvc 如何在Microsoft.AspNet.Mvc.Facebook.Facebook中动态设置权限? 控制器 过载,asp.net-mvc,facebook,asp.net-mvc-3,asp.net-mvc-4,facebook-c#-sdk,Asp.net Mvc,Facebook,Asp.net Mvc 3,Asp.net Mvc 4,Facebook C# Sdk,编译错误 在上面的代码块中,我们有以下代码 [Microsoft.AspNet.Mvc.Facebook.FacebookAuthorize(userPermissions)] 下面给出了编译错误 我的理解是,您不能动态地将任何内容分配给属性参数(错误消息备份时) 我与我的定制会员提供商做了一些事情,我认为您可以进行调整以实现您的目标。我想要一个角色/权限设置,定义用户对系统各个部分的访问权限,而不需要为用户分配一系列单独的权限,但仍然可以非常精确地控制每个角色可以做什么。我遵循这个方法(做了
[Microsoft.AspNet.Mvc.Facebook.FacebookAuthorize(userPermissions)]
下面给出了编译错误
我的理解是,您不能动态地将任何内容分配给属性参数(错误消息备份时) 我与我的定制会员提供商做了一些事情,我认为您可以进行调整以实现您的目标。我想要一个角色/权限设置,定义用户对系统各个部分的访问权限,而不需要为用户分配一系列单独的权限,但仍然可以非常精确地控制每个角色可以做什么。我遵循这个方法(做了一些修改)来完成这项工作
如果在您的场景中需要即时执行此操作,我将采取的方法是定义一个常量
角色
,用于操作方法
的FacebookAuthorize
属性,然后在处理权限检查通行证(或让它查找)的过程中,为每个方法定义一个权限
数组“角色”。这样,您分配给authorized属性的“角色”是一个常量。不确定它是否有用,但这就是我允许用户添加额外权限的方式
/// <summary>
/// Use this method when an action fails due to lack of priviligies. It will redirect user to facebook with provided permission request.
/// Refactor to handle list of request.
/// </summary>
/// <param name="permission"></param>
private static void AddAdditionalPermissions(string permission)
{
System.Diagnostics.Trace.TraceInformation(permission + " not authorized for user.");
string facebook_urlAuthorize_base = "https://graph.facebook.com/oauth/authorize";
string scope = permission; //see: https://developers.facebook.com/docs/authentication/permissions/ for extended permissions
string urlAuthorize = facebook_urlAuthorize_base;
urlAuthorize += "?client_id=" + AppId;
urlAuthorize += "&redirect_uri=" + "https://mydomainnamehere.nu/";
urlAuthorize += "&scope=" + scope;
//redirect the users browser to Facebook to ask the user to authorize our Facebook application
HttpContext.Current.Response.Redirect(urlAuthorize, true); //this cannot be done using WebRequest since facebook may need to show dialogs in the users browser
}
//
///当操作因缺乏权限而失败时,请使用此方法。它将用户重定向到facebook,并提供权限请求。
///重构以处理请求列表。
///
///
私有静态void AddAdditionalPermissions(字符串权限)
{
系统.诊断.跟踪.跟踪信息(权限+“未授权用户”);
字符串facebook\u urlAuthorize\u base=”https://graph.facebook.com/oauth/authorize";
字符串范围=权限;//请参阅:https://developers.facebook.com/docs/authentication/permissions/ 用于扩展权限
字符串urlAuthorize=facebook\u urlAuthorize\u base;
urlAuthorize+=“?客户机_id=“+AppId;
urlAuthorize+=”&重定向_uri=“+”https://mydomainnamehere.nu/";
urlAuthorize+=“&scope=“+scope;
//将用户浏览器重定向到Facebook,要求用户授权我们的Facebook应用程序
HttpContext.Current.Response.Redirect(urlAuthorize,true);//这不能使用WebRequest完成,因为facebook可能需要在用户浏览器中显示对话框
}
您链接到的页面已关闭,您的答案中直接包含的内容缺少详细信息:(请更新不再有效的链接,并提供有关链接页面内容的最少信息。@Alexei该链接仍在为我工作,并提供详细的实现方法作为我所做的示例,不一定是对他的问题的回答,我在第三段中的建议仍然有效。@Matthew-何时我已经检查过了,它不工作(404)。现在,它工作了。
/// <summary>
/// Use this method when an action fails due to lack of priviligies. It will redirect user to facebook with provided permission request.
/// Refactor to handle list of request.
/// </summary>
/// <param name="permission"></param>
private static void AddAdditionalPermissions(string permission)
{
System.Diagnostics.Trace.TraceInformation(permission + " not authorized for user.");
string facebook_urlAuthorize_base = "https://graph.facebook.com/oauth/authorize";
string scope = permission; //see: https://developers.facebook.com/docs/authentication/permissions/ for extended permissions
string urlAuthorize = facebook_urlAuthorize_base;
urlAuthorize += "?client_id=" + AppId;
urlAuthorize += "&redirect_uri=" + "https://mydomainnamehere.nu/";
urlAuthorize += "&scope=" + scope;
//redirect the users browser to Facebook to ask the user to authorize our Facebook application
HttpContext.Current.Response.Redirect(urlAuthorize, true); //this cannot be done using WebRequest since facebook may need to show dialogs in the users browser
}