Authentification-None for one folder(page) when th

2020-07-23 05:12发布

I have a WebApplication on asp.net 2.0 with namespace Admin. I have Form Authentification mode for the project.

    <authentication mode="Forms">
        <forms name="ASP_XML_Form" loginUrl="Login.aspx" protection="All" timeout="30"
               path="/" requireSSL="false" slidingExpiration="true"
               cookieless="AutoDetect">
        </forms>

    </authentication>

Now, I try to share one folder (one inside page) for not Authentificatied users:

<location path="Recovery">
    <system.web>
        <roleManager enabled="false" >
        </roleManager>

        <authentication mode="None">
        </authentication>

        <authorization>
            <allow users="*" />
        </authorization>

        <httpHandlers>
            <remove verb="GET" path="image.aspx" />
            <remove verb="GET" path="css.aspx" />
        </httpHandlers>
    </system.web>
</location>

But when I create the page inside the shared folder, it can't get access to the assembly. And I see the error like this:

Could not load file or assembly 'Admin' or one of its dependencies. The system cannot find the file specified.

It also shows me the error:

ASP.NET runtime error: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Does anybody know how to share (Authentification None) one folder(page) when the project is under FormsAuthentifications?

2条回答
看我几分像从前
2楼-- · 2020-07-23 05:48

check the namespace in he code behind file - it looks like you may have some conflict ( did you create the file in another folder and then physically move it to shared folder). also you have to do the set the location property for the shared folder to share it for non authenticated users

查看更多
够拽才男人
3楼-- · 2020-07-23 05:52

You should just have the following in your <location> element:

<location path="Recovery">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

(If you really need to remove them, you could also include the handlers element).

Neither the Authentication nor the RoleManager elements are allowed in a non-application level web.config, so you can't define them in a <location> element.

Edit in response to comment

Sorry, to clarify: you have too much in your location element - the <authentication> and <roleManager> elements are not allowed in there (unless /Recovery is an application in IIS) and will most certainly cause the second error you are reporting in your question, these will need to be removed before the page will display properly at all.

Are you seeing the "can't find assembly" error everywhere, or just on the page in the Recovery folder? Is that folder marked as an "application" within IIS? If so, you'll need to copy your site's binaries into a /bin folder under /Recovery, or remove the application settings on the folder in IIS.

I've just realised that I said "authorization elements" in the first two sections when I meant "Authentication Elements" - sorry if that confused.

Edit in response to second comment

Basically, in IIS, you can have one or more web sites - these are the roots of the site, and are defined as an Application Start Point.

IIS also allows you to configure sub-folders of a web site as an application as well, this allows you to do things like:

  • Change configuration settings that are only allowed to be set at the application level
  • Run part of the site in a different memory space
  • Run part of the site under a different user account

However, if you do make a folder an application, you will need to ensure that all the code it needs is reachable, and as you've started a new application, code in the root /bin (or /app_code) folders is no longer reachable by that folder.

Normally, in IIS Manager you would click on the folder and remove the application so that it inherits from the root.

查看更多
登录 后发表回答