Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • trfletch 595 posts 571 karma points
    Jul 16, 2012 @ 12:08
    trfletch
    0

    Check user role using XSLT and c#

    Hi All,

    I have a complex XSLT file that I do not want to have to re-write into a usercontrol so I am hoping that there is some way I can do this in XSLT. I am using a custom membership provider and I need to check whether a user is in a specific role in my XSLT. I found an article that showed me how to run some c# code in my XSLT to find a key from a web.config file. I have tried to apply the same logic to see if a user is in a role but I get an error when saving the XSLT file. Can anyone help with this? The script I have so far is:

    <msxsl:script implements-prefix='userRoles' language='CSharp'>
    <![CDATA[
    
    public string getWebConfigKey(string key)
    {   
        return System.Configuration.ConfigurationSettings.AppSettings[key];
    }
    
    public bool subscriber(string role)
    {
        if (System.Web.HttpContext.Current.User.IsInRole(role))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    ]]>
    </msxsl:script>

    The first part (getWebConfigKey) works fine but I get an error when trying to save my XSLT after adding the "subscriber" code:

    Error occured

    Error in XSLT at line 348, char 17
    346: public bool subscriber(string role)
    347: {
    348: >>> if (System.Web.HttpContext.Current.User.IsInRole(role)) <<<
    349: {
    350: return true;

  • trfletch 595 posts 571 karma points
    Jul 18, 2012 @ 16:33
    trfletch
    0

    Does anyone have any suggestions on this one? Or know if it is even possible? Or does anyone know a way in just XSLT I can check the role of a user with having to use "System.Web.HttpContext.Current.User.IsInRole(role)"

    Regards

    Tony

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies