Link to home
Start Free TrialLog in
Avatar of negreteo
negreteoFlag for United States of America

asked on

How to protect my files page.aspx.cs

Hi

 Is there a way to protect my files page.aspx.cs from users to see its content?

Thanks in advance
Avatar of praneetha
praneetha

users cannot see .cs files....
page.aspx.cs is needed when deployed, it is compiled into the dll under directory bin
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
when user makes a req for cs file it throws an error

 Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cs' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
it is by default protected from browsing:

inside your machine config:

<httpHandlers>
                  <add verb="*" path="*.vjsproj" type="System.Web.HttpForbiddenHandler"/><add verb="*" path="*.java" type="System.Web.HttpForbiddenHandler"/><add verb="*" path="*.jsl" type="System.Web.HttpForbiddenHandler"/><add verb="*" path="trace.axd" type="System.Web.Handlers.TraceHandler"/>
                  <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>
                  <add verb="*" path="*.ashx" type="System.Web.UI.SimpleHandlerFactory"/>
                  <add verb="*" path="*.asmx" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
                  <add verb="*" path="*.rem" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
                  <add verb="*" path="*.soap" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false"/>
                  <add verb="*" path="*.asax" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.ascx" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="GET,HEAD" path="*.dll.config" type="System.Web.StaticFileHandler"/>
                  <add verb="GET,HEAD" path="*.exe.config" type="System.Web.StaticFileHandler"/>
                  <add verb="*" path="*.config" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.cs" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.csproj" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.vb" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.vbproj" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.webinfo" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.asp" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.licx" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.resx" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="*" path="*.resources" type="System.Web.HttpForbiddenHandler"/>
                  <add verb="GET,HEAD" path="*" type="System.Web.StaticFileHandler"/>
                  <add verb="*" path="*" type="System.Web.HttpMethodNotAllowedHandler"/>
            </httpHandlers>


and since the .cs is mapped to the asp_net.dll , anyone trying to view your code behind files will be processed by the ForbiddenHandler

type error:
page.aspx.cs is not necessary for deployment, so you don't need to put it on
the web server at all.