restricting non-ASP.NET content

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KBTibbs
    New Member
    • Aug 2007
    • 13

    restricting non-ASP.NET content

    Hi.

    I'm restricting access to my webpage with forms authentication, but I have some .htm files that I want to restrict as well (by default, ASP.NET does not restrict this, so anyone with access to the URL could open them).

    I've run across a number of solutions on the web, none however seem to work for me. It's possible I'm just missing something stupid and obvious. (I hope that's it.)

    First, this page advised me to add a setting to IIS to make aspnet_asapi.dl l handle the .htm files. However, the result was less that satisfactory. In Firefox (2.0.0.x) the page would simply be blank, and IE (6&7) would give the "Internet Explorer cannot display the webpage" message.

    Then this page and this page suggested adding httpHandler entries into my web.config file.
    These settings did nothing to filter these files.

    Then, with ever increasing desperation I tried them both at the same time, and again I got the blank Firefox and the taunting IE message.

    Can anyone help me figure out what I'm missing here?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Are these pages to be protected by the same login credentials as the aspnet pages?
    Because you could restrict access to the directories they're in with the http security.
    (challenge authentication)

    Or convert them over to full-fledged aspx pages. Really you should have been able to just drop the html source code into the aspx page.

    Comment

    • KBTibbs
      New Member
      • Aug 2007
      • 13

      #3
      Originally posted by Plater
      Are these pages to be protected by the same login credentials as the aspnet pages?
      Because you could restrict access to the directories they're in with the http security.
      (challenge authentication)

      Or convert them over to full-fledged aspx pages. Really you should have been able to just drop the html source code into the aspx page.
      I'm handling the specifics of which files go to which users... All I need is a simple redirect to the login page if they aren't authenticated.

      The idea is that these are generated reports, and people get access to their own reports. Users access the reports page, the page queries the database, scoops up all the files in the folders specified by the database, and displays them in a datagrid with hyperlinks.

      The benefits to this are that:
      1) existing reports work (to preserve report histories without modifying those files by hand)
      2) the existing reporting process is automated and can generate and upload a new report to the ftp site. This setup preserves this functionality so it doesn't need to be modified.

      I've already got a good bit of other site content restricted by various roles granted by the forms authentication, the last bit to restrict is this non-ASP.NET content...

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        hmmm. well have you tried making a "serve-up" aspx page?

        Like all those hyperlinks goto:
        "myserveup.aspx ?filename=repor t456.html"

        And then your serveup.aspx page goes and grabs that file and returns the content.
        Then you can just make sure they're authenticated for that aspx page.

        I use this method in my own company. The actual location where the data files are is not available through the website, only through the serveup page can they be accessed.

        Comment

        • KBTibbs
          New Member
          • Aug 2007
          • 13

          #5
          Originally posted by Plater
          hmmm. well have you tried making a "serve-up" aspx page?

          Like all those hyperlinks goto:
          "myserveup.aspx ?filename=repor t456.html"

          And then your serveup.aspx page goes and grabs that file and returns the content.
          Then you can just make sure they're authenticated for that aspx page.

          I use this method in my own company. The actual location where the data files are is not available through the website, only through the serveup page can they be accessed.
          Hmmm, that's an intriguing idea. I'm not readily able to imagine some of the specifics (I'm a desktop programmer by trade that got somewhat pressed into this web development project just recently. I'll admit to being a bit out of my native element)... A couple of questions come to mind:

          Would I need to strip out any of the html from the files, or would the ASPX page simply not care about duplicate <HEAD> tags, <BODY> tags, etc?

          How can I set the folder to be inaccessible to the outside? Move it to be within the app_data folder? Could I still set that folder to be an FTP site to receive the auto-generated reports?

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            The aspx page...wouldn't really be an aspx page.
            Inside it would do all the validating of "should this user be able to access this file?"
            Then if yes it'd be something like:
            Code:
            Response.Clear();//wipe out anything that would be sent to client
            /*
            * Some code to send the file, I think it's like Response.TransmitFile(filename)
            */
            Response.End();
            If it was no, display some sort of "not allowed" message

            Comment

            • KBTibbs
              New Member
              • Aug 2007
              • 13

              #7
              Originally posted by Plater
              The aspx page...wouldn't really be an aspx page.
              Inside it would do all the validating of "should this user be able to access this file?"
              Then if yes it'd be something like:
              Code:
              Response.Clear();//wipe out anything that would be sent to client
              /*
              * Some code to send the file, I think it's like Response.TransmitFile(filename)
              */
              Response.End();
              If it was no, display some sort of "not allowed" message
              This sounds like a good solution, however I would still like a way to deny access to anyone who might be able to guess the URL of the source HTML files... Maybe I could store the files within app_data?

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Don't expose there location to the web.
                Like for instance in my setup, the iis website is located at:
                c:\inetpub\wwwr oot\
                And the datafiles are in say:
                c:\data\

                The code behind can access that directory, but the website does not have access to it.

                Comment

                • kunal pawar
                  Contributor
                  • Oct 2007
                  • 297

                  #9
                  Hi,
                  U can restrict by setting the web.config.

                  <location path="admin.htm l">
                  <system.web>
                  <customErrors mode="Off"/>
                  <compilation debug="true"/>
                  <authenticati on mode="Forms">
                  <forms name="frmLogin"
                  loginUrl="login .aspx">
                  </forms>
                  </authentication>
                  <authorizatio n>
                  <deny users ="?" />
                  </authorization>
                  </system.web>

                  </location>

                  try this one

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Oooo, good call on that one. I think you can take wildcards in the path= attribute too?

                    Comment

                    • dotneto
                      New Member
                      • Feb 2007
                      • 36

                      #11
                      Yes, using location for the files is the cleanest way to do that.

                      What you could also do is deny acces to unauthenticated users and grant acces to the specific role where your html files are. In you web.config:

                      Code:
                      <authentication mode="Forms">
                      <forms loginUrl="/yoursite/default.aspx" name="name" timeout="20" protection="All" path="/">
                      </forms>
                      </authentication>
                      <authorization>
                      		<deny users="?"/>
                      </authorization>
                      <location path="the folder where your html files are">
                      		<system.web>
                      			<authorization>
                      				<allow roles="Roles that can access the path"/>
                      			</authorization>
                      		</system.web>
                      	</location>

                      Comment

                      Working...