문제

I'm using Membership Provider for create and manage users and roles in my site. I'm trying to restric access to a specific roles to the Account folder using web.config into this folder with this rule:

<system.web>
  <authorization>
    <allow roles="Administrator"/>
    <deny users="*" />
  </authorization>
</system.web>

I'm using Web Forms and forms authentication like show below:

<authentication mode="Forms">
  <forms loginUrl="~/Login.aspx" timeout="2880" defaultUrl="~/" />
</authentication>

But when I try to access to page located into Account folder I'm getting:

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Below a picture with the error:

enter image description here

How can I do for redirect to Login when the user try to access to unauthorized folder or url?

도움이 되었습니까?

해결책

You are accessing the Login.aspx like /Account/Login/Default.aspx which doesn't exist.

Shouldn't that be ~/Account/Login.aspx?

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>

How to debug?

  1. Make sure you can access Login.aspx properly.
  2. Then paste that URL inside form tag in web.config like above.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top