forms authentication asp.net vb

2019-02-21 01:26发布

问题:

I have a log in page which is the home page so is located at www.domainname.com

when someone goes to this page it adds a returnurl to the string so they are at:

www.domainname.com/default.aspx?ReturnUrl=%2f so when they log in they get returned to http://www.domainname.com/, which is the login page again, so to access the site they have to login twice.

Does anyone know how to fix this? I think a fix to this would be to allow everyone access to the home page - http://www.domainname.com/ as well as http://www.domainname.com/default.aspx but i'm not sure how to acheive this.

I want all user roles to be denied access to every page apart from the home page before they login, i also have an admin/cms section that only Admin roles can access but everyone can access the cms login page.

I currently have this in my web.config

        <authentication mode="Forms">
        <forms protection="All" loginUrl="default.aspx" defaultUrl="~/home/" />
    </authentication>
    <authorization>
        <allow roles="Admin, User"/>
        <deny users="?" />
    </authorization>

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

<location path="cms/default.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

<location path="cms">
    <system.web>
        <authorization>
            <allow roles="Admin"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>

回答1:

Well i seemed to have done it a bit by luck.

I just changed

<authentication mode="Forms">
    <forms protection="All" loginUrl="default.aspx" defaultUrl="~/home/" />
</authentication>

To

<authentication mode="Forms">
    <forms protection="All" loginUrl="/" defaultUrl="~/home/" />
</authentication>


回答2:

You should send them to the page you want them to default to. What you should do is create the login page on a seperate page (login.aspx) for instance and then make the default.aspx page the home page. Then when they go to default.aspx they will be redirected to login.aspx?ReturnURL=%2f .



回答3:

Yes, we can use the above solution. One problem here is when we are using SEO implementation. To achieve your requirement, you can use URLRewrite.

http://weblogs.asp.net/scottgu/archive/2010/04/20/tip-trick-fix-common-seo-problems-using-the-url-rewrite-extension.aspx