0

In web api project (with angularjs on the client side) I used Authorize attribute for web api controllers and websecurity class for user authentication in AccountController.

My HomeController looks like this:

public class HomeController : Controller
{
    [Authorize]
    public ActionResult Index()
    {
        ViewBag.Title = "Home Page";

        return View();
    }
}

My Index.cshtml (razor page) for Home controller looks like this:

<div ng-view>
</div>

In _Layout.cshtml, I defined angular app.

In web config, I use Forms Authentication, which looks like this:

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

For most of web api controllers I used [Atuthorize] attribute for methods. For some of the controllers I used [AllowAnonymous] attribute and it's fine (have access for web api services and get json result).

My app.js which uses angular and contains routing for my pages looks like this:

var myApp = angular.module("myApp", ['ngRoute', 'angular.morris', 'angularUtils.directives.dirPagination'])
.config(function ($routeProvider, $locationProvider) {
    $routeProvider
    .when('/', {
        templateUrl: 'Template/Dashboard.html',
        controller: 'dashboardController'
    })
    .when('/Page1/', {
        templateUrl: 'Template/Page1.html',
        controller: 'page1Controller'
    })
    .when('/Page2/', {
        templateUrl: 'Template/Page2.html',
        controller: 'page2Controller'
    })
    .when('/Page3/', {
        templateUrl: 'Template/Page3.html',
        controller: 'page3Controller'
    })
    .when('/Page4/', {
        templateUrl: 'Template/Page4.html',
        controller: 'page4Controller'
    })
    .when('/Page5/', {
        templateUrl: 'Template/Page5.html',
        controller: 'page5Controller'
    })
    .otherwise('/', {
        templateUrl: 'Template/Dashboard.html',
        controller: 'dashboardController'
    });
})

When run application, then display Log In page. (It's good).

Is there any solution, that when I write localhost:12345/#/Page2 (when I am not logged on the application) on browser that redirect me to this page (without user authentication)? Now, always redirect me to Login Page.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
oknevermind
  • 101
  • 3
  • 17

0 Answers0