简体   繁体   中英

asp.net login redirect

I have an asp.net webpage which a couple of pages link to. I don't want the user to directly type in the page URL to access it without logging in.

For example I have a page www.test.com/data.aspx, if the user types the URL in without logging in, then I want them redirected to the main login page.

I'm not using the .Net login control, just textboxes for the username and password.

I'm not sure what you wanna say , By the way , if you wanna oblige users to Log-in in order to access some pages , then you should do these steps :

1- Set your authentication mode to "Form" :

<authentication mode="Forms">
    <forms loginUrl="~/SomeDirectory_OrPageOnYourSite_WhichUsersCanLogin.aspx" />
</authentication>

// It's not necessary to use login control , You can make it yourself . here loginUrl define the pages which users can login

2- Restrict anonymous users from viewing your pages . It's a good idea move those pages to a specific folder and add a new web.config file . and setting like this :

<system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
</system.web>

And if you wanna chose specific pages , not all pages ,then you can set that page like this :

  <location path="Thankyou.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM