Question

This is what I get by default:

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Requested URL htt p://localhost:56335/Account/Login?ReturnUrl=%2fManagerPages%2fVideoManager.aspx
Physical Path      c:\users\pc\documents\visual studio 2012\Projects\Lab8\Lab8\Account\Login
Logon Method       Anonymous
Logon User     Anonymous
Request Tracing Directory      C:\Users\Pc\Documents\IISExpress\TraceLogFiles\LAB8

I tried with:

<customErrors defaultRedirect="Error.aspx" mode="On">
      <error statusCode="401" redirect="Account/Login.aspx" />
      <error statusCode="404" redirect="Forbidden.aspx" />
    </customErrors>

but, no success, like I didn't change anything. I also tried with almost every solution I found on stackoverflow, google, but no matter what I do this page always appears. The code doesn't even get in codebehind, so how can I redirect them? In membership perhaps?

Edit:

I replaced Account/Login with Login.aspx in browser address tab and it worked fine. How to replace this in code?

Was it helpful?

Solution

I experimented a bit with <rewrite> tag and got it to work when I changed the url to match the wrong path "Account/Login":

<system.webServer>
    <rewrite>
      <rules> 
         <rule name="Unauthorized access" stopProcessing="true">
           <match url="Account/Login" />
           <action type="Redirect" url="/Login.aspx"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

Now it's not only redirecting to "Login.aspx" but it also has the original query string: Login.aspx?ReturnUrl=%2fManagerPages%2fVideoManager.aspx

OTHER TIPS

<authentication mode="Forms">
      <forms name="DForm" loginUrl="/login.aspx" />
    </authentication>
.....
<location path="ManagerPages">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top