0

I have a controller with [AuthorizeWebForm] attribute.

Now, If I am not login and I want to access that page, then it gives me

HTTP Error 401.0 - Unauthorized. You do not have permission to view this directory or page.

Now, How can I Handle that with using [AuthorizeWebForm] attribute? If I am not logged-in and try to access that page, then it should redirect to Login page.

6
  • Can we have your web.config section "authentication" and if you need access page without identification use location section Dec 15, 2016 at 8:45
  • What is your [AuthorizeWebForm] attribute? And is this web forms or asp.net.mvc?
    – user3559349
    Dec 15, 2016 at 8:46
  • This is asp.net MVC Question
    – kkakadiya
    Dec 15, 2016 at 8:49
  • web.config code.<system.web> <sessionState timeout="480"></sessionState> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" executionTimeout="100000" maxRequestLength="52428800" requestLengthDiskThreshold="2147483647" /> <!--executionTimeout and maxRequestLength is used for allowed upload larger file--> <customErrors mode="On"> <error statusCode="404" redirect="~/Error/Index" /> <error statusCode="403" redirect="~/Error/Index" /> </customErrors> </system.web>
    – kkakadiya
    Dec 15, 2016 at 8:50
  • Show the code for [AuthorizeWebForm] attribute or try replacing it with [Authorize] attribute.
    – Dandy
    Dec 15, 2016 at 9:24

1 Answer 1

1

I got solution. I just put below code to my web.config. the session was already checked in custom error class. if session is null, then it is redirecting to login page.

<authentication mode="Forms"> 
    <forms name=".SomeLoginCookie" loginUrl="~/Account/Login" timeout="2880"     protection="All" enableCrossAppRedirects="true" /> 
</authentication>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.