开发者

How to add a controller for an aspx page?

开发者 https://www.devze.com 2022-12-17 00:28 出处:网络
This is the common issue ,that i have faced. when the user clicks one of the menu item, if the user didn\'t login ,I want to r开发者_如何学Pythonedirect to Login page itself.

This is the common issue ,that i have faced. when the user clicks one of the menu item, if the user didn't login ,I want to r开发者_如何学Pythonedirect to Login page itself. Which is the efficient way to do this?

In Jsp we have a controller for every page, I dont know what we use in asp.net.


The easiest way is using web.config file. Have a look at the documentation for the <authentication> section. You might end up with settings like this:

<!-- Anonymous users denied, exceptions in the Location sections below -->
<authorization>
    <deny users="?" />
</authorization>
<authentication mode="Forms">
    <forms loginUrl="~/LogOn.aspx" timeout="2880" name=".ASPXAUTH_CMS" protection="All" />
</authentication>

<!-- Allow all users to see the login screen -->
<location path="~/LogOn.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

If the user is not logged on they will be redirected to "Logoin.aspx" and once they've successfully authenticated they will be redirected back to the original URL.


If you're not using ASP.NET Membership and using your own variables cookies etc for logging in the user then you can override the Page Class and derive all your pages from this Page class. Then all your pages construct the Page class with a constructor whether the page needs login or not. The Page class checks this variable while constructing and redirects the url to the login page when the page requires login and the credentials are not present.


Try Response.Redirect("TheLoginPage.aspx");

0

精彩评论

暂无评论...
验证码 换一张
取 消