How to protect my files page.aspx.cs

Posted on 2005-04-21
Last Modified: 2008-01-16

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

Thanks in advance
Question by:negreteo
    LVL 15

    Expert Comment

    users cannot see .cs files....
    LVL 12

    Expert Comment

    page.aspx.cs is needed when deployed, it is compiled into the dll under directory bin
    LVL 18

    Accepted Solution

    just dont Upload it on the server...

    Your CS file are compiled to DLL files in Bin directory.. so whenever you upload your file to hosting server or your Production Server you dont need to include them...

    LVL 15

    Expert Comment

    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.
    LVL 23

    Expert Comment

    it is by default protected from browsing:

    inside your machine config:

                      <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"/>

    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

    LVL 12

    Expert Comment

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

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now