<p>I'm using the <a href="http://msdn.microsoft.com/en-us/library/ms178329.aspx" rel="nofollow noreferrer">ASP.NET Login Controls</a> and <a href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" rel="nofollow noreferrer">Forms Authentication</a> for membership/credentials for an ASP.NET web application.</p>

<p>I've got two roles:</p>

<ul>
<li>Users</li>
<li>Administrators</li>
</ul>

<p>I want pages to be viewable by four different groups:</p>

<ul>
<li>Everyone <em>(Default, Help)</em></li>
<li>Anonymous <em>(CreateUser, Login, PasswordRecovery)</em></li>
<li>Users <em>(ChangePassword, DataEntry)</em></li>
<li>Administrators <em>(Report)</em></li>
</ul>

<p>Expanding on the example in the <a href="http://www.asp.net/learn/videos/video-45.aspx" rel="nofollow noreferrer">ASP.NET HOW DO I Video Series: Membership and Roles</a>, I've put those page files into such folders:</p>

<p><img src="https://i.stack.imgur.com/Ps7sm.gif" alt="Visual Studio Solution Explorer"></p>

<p>And I used the ASP.NET Web Site Administration Tool to set up access rules for each folder.</p>

<p>It works but seems kludgy to me and it creates issues <a href="https://stackoverflow.com/questions/33089/how-do-i-use-aspnet-login-controls-when-my-loginaspx-is-not-at-the-root-of-my-a">when Login.aspx is not at the root</a> and with the <a href="https://stackoverflow.com/questions/33166/how-do-i-keep-my-loginaspx-pages-returnurl-parameter-from-overriding-my-aspnet">ReturnUrl parameter</a> of Login.aspx.</p>

<p>Is there a better way to do this?  Is there perhaps a simple way I can set permissions at the page level rather than at the folder level?</p>

[{'answer_id': 33283, 'author': 'Matt McMinn', 'author_id': 1322, 'author_profile': 'https://Stackoverflow.com/users/1322', 'pm_score': 7, 'selected': True, 'text': '<p>This works for me in Java 1.5 - I stripped out specific exceptions for readability.</p>\n\n<pre><code>import javax.xml.parsers.DocumentBuilderFactory;\nimport javax.xml.parsers.DocumentBuilder;\nimport org.w3c.dom.Document;\nimport java.io.ByteArrayInputStream;\n\npublic Document loadXMLFromString(String xml) throws Exception\n{\n    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n\n    factory.setNamespaceAware(true);\n    DocumentBuilder builder = factory.newDocumentBuilder();\n\n    return builder.parse(new ByteArrayInputStream(xml.getBytes()));\n}\n</code></pre>\n'}, {'answer_id': 33618, 'author': 'erickson', 'author_id': 3474, 'author_profile': 'https://Stackoverflow.com/users/3474', 'pm_score': 7, 'selected': False, 'text': "<p>Whoa there! </p>\n\n<p>There's a potentially serious problem with this code, because it ignores the character encoding specified in the <code>String</code> (which is UTF-8 by default). When you call <code>String.getBytes()</code> the platform default encoding is used to encode Unicode characters to bytes. So, the parser may think it's getting UTF-8 data when in fact it's getting EBCDIC or something&hellip; not pretty!</p>\n\n<p>Instead, use the parse method that takes an InputSource, which can be constructed with a Reader, like this:</p>\n\n<pre><code>import java.io.StringReader;\nimport org.xml.sax.InputSource;\n…\n        return builder.parse(new InputSource(new StringReader(xml)));\n</code></pre>\n\n<p>It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k.</p>\n"}, {'answer_id': 46121, 'author': 'shsteimer', 'author_id': 292, 'author_profile': 'https://Stackoverflow.com/users/292', 'pm_score': 3, 'selected': False, 'text': '<p>Just had a similar problem, except i needed a NodeList and not a Document, here\'s what I came up with.  It\'s mostly the same solution as before, augmented to get the root element down as a NodeList and using erickson\'s suggestion of using an InputSource instead for character encoding issues.</p>\n\n<pre><code>private String DOC_ROOT="root";\nString xml=getXmlString();\nDocument xmlDoc=loadXMLFrom(xml);\nElement template=xmlDoc.getDocumentElement();\nNodeList nodes=xmlDoc.getElementsByTagName(DOC_ROOT);\n\npublic static Document loadXMLFrom(String xml) throws Exception {\n        InputSource is= new InputSource(new StringReader(xml));\n        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n        factory.setNamespaceAware(true);\n        DocumentBuilder builder = null;\n        builder = factory.newDocumentBuilder();\n        Document doc = builder.parse(is);\n        return doc;\n    }\n</code></pre>\n'}, {'answer_id': 25137190, 'author': 'Xavier Dury', 'author_id': 599011, 'author_profile': 'https://Stackoverflow.com/users/599011', 'pm_score': 2, 'selected': False, 'text': '<p>To manipulate XML in Java, I always tend to use the Transformer API:</p>\n\n<pre><code>import javax.xml.transform.Source;\nimport javax.xml.transform.TransformerException;\nimport javax.xml.transform.TransformerFactory;\nimport javax.xml.transform.dom.DOMResult;\nimport javax.xml.transform.stream.StreamSource;\n\npublic static Document loadXMLFrom(String xml) throws TransformerException {\n    Source source = new StreamSource(new StringReader(xml));\n    DOMResult result = new DOMResult();\n    TransformerFactory.newInstance().newTransformer().transform(source , result);\n    return (Document) result.getNode();\n}   \n</code></pre>\n'}]
['https://Stackoverflow.com/questions/33263', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/83/']