<p>I wonder what the best practice for this scenario is:</p>

<p>I have a Sharepoint Site (MOSS2007) with an ASPX Page on it. However, I cannot use any inline source and stuff like Event handlers do not work, because Sharepoint does not allow Server Side Script on ASPX Pages per default.</p>

<p>Two solutions:</p>

<ol>
<li><p>Change the <code>PageParserPath</code> in <em>web.config</em> as per <a href="http://blogs.msdn.com/kaevans/archive/2007/04/26/code-blocks-are-not-allowed-in-this-file-using-server-side-code-with-sharepoint.aspx" rel="nofollow noreferrer">this site</a>  </p>

<pre><code>&lt;PageParserPaths&gt;
&lt;PageParserPath VirtualPath="/pages/test.aspx" 
        CompilationMode="Always" AllowServerSideScript="true" /&gt;
&lt;/PageParserPaths&gt;
</code></pre></li>
<li><p>Create all the controls and Wire them up to Events in the <em>.CS</em> File, thus completely eliminating some of the benefits of ASP.net</p></li>
</ol>

<p>I wonder, what the best practice would be? Number one looks like it's the correct choice, but changing the <em>web.config</em> is something I want to use sparingly whenever possible.</p>

[{'answer_id': 42248, 'author': 'Daniel McPherson', 'author_id': 897, 'author_profile': 'https://Stackoverflow.com/users/897', 'pm_score': 1, 'selected': False, 'text': '<p>What does the ASPX page do? What functionality does it add? How are you adding the page into the site? By the looks of it this is just a "Web Part Page" in a document library. </p>\n\n<p>I would have to do a little research to be 100%, but my understanding is that inline code is ok, providing it\'s in a page that remains ghosted, and thereby trusted. Can you add your functionality into the site via a feature? </p>\n\n<p>I would avoide option 1, seems like bad advice to me. Allowing server side code in your page is a security risk as it then becomes possible for someone to inject malicious code. Sure you can secure the page, but we are talking remote execution with likely some pretty serious permissions.</p>\n'}, {'answer_id': 42508, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 0, 'selected': False, 'text': "<p>Well, it's a page that hosts user controls. It's a custom .aspx Page that will be created on the site, specially because I do not want to create WebParts.</p>\n\n<p>It's essentially an application running within Sharepoint, utilizing Lists and other functions, but all the functionality is only useful within the application, so flooding the web part gallery with countless web parts that only work in one place is something i'd like to avoid.</p>\n"}, {'answer_id': 43255, 'author': 'Daniel McPherson', 'author_id': 897, 'author_profile': 'https://Stackoverflow.com/users/897', 'pm_score': 2, 'selected': True, 'text': '<p>So in that case I would wrap it up in a feature and deploy it via a solution. This way I think you will avoid the issue you are seeing. This is especially useful if you plan to use this functionality within other sites too. </p>\n\n<p>You can also embed web parts directly in the page, much like you do a WebControl, thereby avoiding any gallery clutter.</p>\n'}, {'answer_id': 43728, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 1, 'selected': False, 'text': '<p>Thanks so far. I\'ve successfully tried Andrew Connel\'s solution:</p>\n\n<p><a href="http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx" rel="nofollow noreferrer">http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx</a></p>\n\n<p>Wrapping it into a solution is part of that, but the main problem was how to get the code into that, and it\'s more leaning towards Option 2 without having to create the controls in code.</p>\n\n<p>What I was missing:<br>\nIn the .cs File, it is required to manually add the "protected Button Trigger;" stuff, because there is no automatically generated .designer.cs file when using a class library.</p>\n'}]
['https://Stackoverflow.com/questions/41576', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/91/']