您好,经过一些研究后,这是对我有用的解决方案:
- Install 剃刀降价 https://github.com/ServiceStack/ServiceStack/wiki/Markdown-Razor来自努盖特
- 更改文件结构以匹配默认行为 RM [Razor Markdown] 到 /views
- 按照中描述的方法修改 Web 配置这个服务堆栈示例 https://github.com/ServiceStack/SocialBootstrapApi/blob/master/src/SocialBootstrapApi/Web.config
- 将所有静态 html 文件更改为 .cshtml 文件,默认情况下,这会创建不带扩展名的相同路由,如不带扩展名的 /views/{Pagename} ,我只是使用这种方法来使授权逻辑更容易实现(至少为我)
- 使用授权属性更新服务方法您可以了解更多信息在此页面中 https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization
为了说明更多,这是我到目前为止的路线定义:
'use strict';
angular.module('myApp', ['myApp.directives', 'myApp.services']).config(
['$routeProvider', function($routeProvider) {
$routeProvider.when('/Dashboard', {
controller: 'dashboardCtrl',
templateUrl: 'Views/dashboard'
}).when('/Payments', {
controller: 'paymentsCtrl',
templateUrl: 'Views/payments'
}).
when('/Login', {
controller: 'loginCtrl',
templateUrl: 'Views/login'
});
}]
);
请注意,引用现在指向剃刀路径。
这是我用角度制作的小菜单
<div class="container">
<div class="navbar" ng-controller="indexCtrl">
<div class="navbar-inner">
<a class="brand" href="#/">header menu</a>
<ul class="nav">
<li ng-class="{active: routeIs('/Dashboard')}"><a href="#/Dashboard">Dashboard</a></li>
<li ng-class="{active: routeIs('/Login')}"><a href="#/Login">Login</a></li>
<li ng-class="{active: routeIs('/Payments')}"><a href="#/Payments">payments</a></li>
</ul>
</div>
</div>
<ng-view></ng-view>
</div>
假设付款页面受到限制,因此每次我点击该页面时都会收到 401 未经授权的消息。
服务主机:
public override void Configure(Container container)
{
Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
new FacebookAuthProvider(appSettings),
new TwitterAuthProvider(appSettings),
new BasicAuthProvider(appSettings),
new GoogleOpenIdOAuthProvider(appSettings),
new CredentialsAuthProvider()
})); //I'm going to support social auth as well.
Plugins.Add(new RegistrationFeature());
Routes.Add<UserRequest>("/Api/User/{Id}");
Routes.Add<LoginRequest>("/Api/User/login","POST");
Routes.Add<PaymentRequest>("/views/Payments");
}
我希望这有帮助