0

I have an idea where when an Icon is click on my SharePoint site it will redirect people to a page which is linked with their user group. Issue is i do not know how to do this. I have found a web application which does this but it seems it doesn't want to work.

Any other solutions, Also if code could you please provide and example of the code so i know what to do :) Thanks

Update

<style type="text/css"> .redirect {     TEXT-ALIGN: center;
 PADDING-BOTTOM: 100px; PADDING-LEFT: 300px; PADDING-RIGHT: 300px;
 FONT-WEIGHT: 900; PADDING-TOP: 100px }</style><script
 type="text/javascript">

 var
URL="URL HERE",timer=0,current="none",popup="",msg="",img="";
if (popup) alert(popup); 
var d=new
 Date(),a=document.getElementById("aspnetForm"),b=document.getElementsByTagName("body")[0],c=document.createElement("div"),i=document.createElement("img"),t=document.createElement("div");
a.style.display=current;c.className="redirect";i.src=img;c.appendChild(i);c.appendChild(t);b.insertBefore(c,a);
 function wait(){var tleft=Math.round(timer-(new
Date())/1000+d/1000);if (tleft>0) {t.innerHTML="<p>"+msg+"</p><p>Wait
for "+tleft+" second(s) or <a href='"+URL+"'>click here</a> to be
redirected.</p>";setTimeout("wait()",1000);}else
{t.innerHTML="<p>Redirecting</p>";window.location.href=URL;}}
wait();</script>

The above code works in a Content Editor webpart as it redirects all users to the page, but is there a way which i could use this code to say if(user.group ="Spain") then redirect?

4

1 回答 1

0

实现这一目标的小例子

public bool IsUserInGroup(SPWeb web, SPUser user, string groupName)
{
    try
    {
        SPGroup group = web.Groups[groupName];    
        return IsUserInGroup(user, group);
    }   
    catch
    {
        return false;
    }

}

public bool IsUserInGroup(SPUser user, SPGroup group)
{
    return user.Groups.Cast<SPGroup>().Any(g => g.ID == group.ID);
}

//Redirect for example:
SPUser user = web.CurrentUser;
bool isInGroup = IsUserInGroup(web, user, "My Custom group");
if(isInGroup)
{
    Response.Redirect("some url");
}

希望它会有所帮助

于 2013-01-24T12:34:18.697 回答