I am trying to play about with the asp.net MVC SPA template in visual studio 2013, I don't need any of the authentication bits, I just need to load directly onto one of the controllers pages.
我试图在visual studio 2013中使用asp.net MVC SPA模板,我不需要任何身份验证位,我只需要直接加载到其中一个控制器页面上。
How do I get rid of all the authentication stuff from the initial template?
如何从初始模板中删除所有身份验证内容?
5 个解决方案
#1
19
Remove the [Authorize]
annotation from HomeController
and remove this:
从HomeController中删除[Authorize]注释并删除它:
@section Scripts{
@Scripts.Render("~/bundles/knockout")
@Scripts.Render("~/bundles/app")
}
from Views\Home\Index.cshtml
because one of does js
is causing the redirect to the login page even after removing the [Authorize]
annotation from HomeController
and probably you don't need it. If you need these scripts in your page, then you need to edit one of them.
来自Views \ Home \ Index.cshtml,因为其中一个js导致重定向到登录页面,即使从HomeController中删除[Authorize]注释后可能你不需要它。如果您在页面中需要这些脚本,则需要编辑其中一个脚本。
#2
8
Here's what I did.
这就是我做的。
Remove [Authorize]
attribute from the home controller.
从家庭控制器中删除[授权]属性。
Then in app.viewmodel.js
you'll see this:
然后在app.viewmodel.js中你会看到:
self[options.bindingMemberName] = ko.computed(function () {
if (!dataModel.getAccessToken()) {
// The following code looks for a fragment in the URL to get the access token which will be
// used to call the protected Web API resource
var fragment = common.getFragment();
if (fragment.access_token) {
// returning with access token, restore old hash, or at least hide token
window.location.hash = fragment.state || '';
dataModel.setAccessToken(fragment.access_token);
} else {
// no token - so bounce to Authorize endpoint in AccountController to sign in or register
window.location = "/Account/Authorize?client_id=web&response_type=token&state=" + encodeURIComponent(window.location.hash);
}
}
return self.Views[options.name];
});
This is the section that will redirect you to the login screen, so comment out or remove the if
block. If you want you can also go into app.datamodel.js
and remove or comment out self.getAccessToken
.
这是将您重定向到登录屏幕的部分,因此注释掉或删除if块。如果你想要,你也可以进入app.datamodel.js并删除或注释掉self.getAccessToken。
In addition, in WebApiConfig.cs
you will probably want to remove / comment out the following lines:
此外,在WebApiConfig.cs中,您可能希望删除/注释掉以下行:
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
#3
2
Here is how I solved it. I just removed the
这是我解决它的方式。我刚刚删除了
Removed the [Authorize] annotation from HomeController.cs (got this from Castro Roy's answer). Even after this the app redirected to the login page.
从HomeController.cs中删除了[Authorize]注释(从Castro Roy的回答中得到了这个)。即使在此之后,应用程序也会重定向到登录页面。
To resolve the redirection remove the [Authorize] annotation from the AccountController.cs
要解决重定向,请从AccountController.cs中删除[Authorize]注释
However I have retained the authentication related code so that can be used in other pages.
但是,我保留了与身份验证相关的代码,以便可以在其他页面中使用。
#4
0
In addition to removing [Authorize]
from the controllers, the file home.viewmodel.js is causing the redirect problem on the home page load. In App_Start/BundleConfig.cs
, remove the line ~/Scripts/app/home.viewmodel.js
from the bundles/app
ScriptBundle.
除了从控制器中删除[Authorize]之外,home.viewmodel.js文件还会导致主页加载时出现重定向问题。在App_Start / BundleConfig.cs中,从bundle / app ScriptBundle中删除〜/ Scripts / app / home.viewmodel.js行。
#5
0
Put [AllowAnonymous]
at the beginning of the function you want to allow anonymous access to.
将[AllowAnonymous]放在要允许匿名访问的函数的开头。
#1
19
Remove the [Authorize]
annotation from HomeController
and remove this:
从HomeController中删除[Authorize]注释并删除它:
@section Scripts{
@Scripts.Render("~/bundles/knockout")
@Scripts.Render("~/bundles/app")
}
from Views\Home\Index.cshtml
because one of does js
is causing the redirect to the login page even after removing the [Authorize]
annotation from HomeController
and probably you don't need it. If you need these scripts in your page, then you need to edit one of them.
来自Views \ Home \ Index.cshtml,因为其中一个js导致重定向到登录页面,即使从HomeController中删除[Authorize]注释后可能你不需要它。如果您在页面中需要这些脚本,则需要编辑其中一个脚本。
#2
8
Here's what I did.
这就是我做的。
Remove [Authorize]
attribute from the home controller.
从家庭控制器中删除[授权]属性。
Then in app.viewmodel.js
you'll see this:
然后在app.viewmodel.js中你会看到:
self[options.bindingMemberName] = ko.computed(function () {
if (!dataModel.getAccessToken()) {
// The following code looks for a fragment in the URL to get the access token which will be
// used to call the protected Web API resource
var fragment = common.getFragment();
if (fragment.access_token) {
// returning with access token, restore old hash, or at least hide token
window.location.hash = fragment.state || '';
dataModel.setAccessToken(fragment.access_token);
} else {
// no token - so bounce to Authorize endpoint in AccountController to sign in or register
window.location = "/Account/Authorize?client_id=web&response_type=token&state=" + encodeURIComponent(window.location.hash);
}
}
return self.Views[options.name];
});
This is the section that will redirect you to the login screen, so comment out or remove the if
block. If you want you can also go into app.datamodel.js
and remove or comment out self.getAccessToken
.
这是将您重定向到登录屏幕的部分,因此注释掉或删除if块。如果你想要,你也可以进入app.datamodel.js并删除或注释掉self.getAccessToken。
In addition, in WebApiConfig.cs
you will probably want to remove / comment out the following lines:
此外,在WebApiConfig.cs中,您可能希望删除/注释掉以下行:
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
#3
2
Here is how I solved it. I just removed the
这是我解决它的方式。我刚刚删除了
Removed the [Authorize] annotation from HomeController.cs (got this from Castro Roy's answer). Even after this the app redirected to the login page.
从HomeController.cs中删除了[Authorize]注释(从Castro Roy的回答中得到了这个)。即使在此之后,应用程序也会重定向到登录页面。
To resolve the redirection remove the [Authorize] annotation from the AccountController.cs
要解决重定向,请从AccountController.cs中删除[Authorize]注释
However I have retained the authentication related code so that can be used in other pages.
但是,我保留了与身份验证相关的代码,以便可以在其他页面中使用。
#4
0
In addition to removing [Authorize]
from the controllers, the file home.viewmodel.js is causing the redirect problem on the home page load. In App_Start/BundleConfig.cs
, remove the line ~/Scripts/app/home.viewmodel.js
from the bundles/app
ScriptBundle.
除了从控制器中删除[Authorize]之外,home.viewmodel.js文件还会导致主页加载时出现重定向问题。在App_Start / BundleConfig.cs中,从bundle / app ScriptBundle中删除〜/ Scripts / app / home.viewmodel.js行。
#5
0
Put [AllowAnonymous]
at the beginning of the function you want to allow anonymous access to.
将[AllowAnonymous]放在要允许匿名访问的函数的开头。