本文介绍了mvc 5身份验证是否与mvc4 / mvc3不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b



我想在我的项目中实施认证/授权



对于跨浏览器和移动访问,我们在我们的项目中实现web api。



对于View我们使用的是普通控制器。对于数据我们使用的是api控制器



那么如何在asp.net mvc 5中实现基于角色的访问和授权。





我在web.config中添加了身份验证标签

当我运行应用程序时遇到以下错误



HTTP错误500.19 - 内部服务器错误

无法访问请求的页面,因为页面的相关配置数据无效。

错误代码:0x800700b7

谢谢

Syed Khaleel

Hi

I want to implement Authentication/authorization in my project

For cross browser and mobile access we are implementing web api in our project.

For View we are using normal controller.For data we are using api controller

So how can i achieve role based access and authorization in asp.net mvc 5.


I have added authentication tag in web.config
When i run application im getting follwing error

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Cod: 0x800700b7
Thanks
Syed Khaleel

推荐答案

<authentication mode="none" />to <authentication mode="form" /> 



它停止工作。

所以要解决这个问题,添加


its stops working.

So to solve this issue add

Response.SuppressFormsAuthenticationRedirect = true

。通常认证模式设置为none,但如果您更改,则可以解决。

Response.SuppressFormsAuthenticationRedirect做的是

in the prescribed class.Normally authentication mode is set to none ,but in case you change you can resolve.

What the Response.SuppressFormsAuthenticationRedirect does is

Quote:

获取或设置一个值指定是否应禁止表单身份验证重定向到登录页面。

Gets or sets a value that specifies whether forms authentication redirection to the login page should be suppressed.





MVC5支持OpenID和Forms身份验证。

希望这会有所帮助..

如果您在此找到价值,请接受..

Happy Coding SD:)



MVC5 does support both OpenID and Forms authentications.
Hope this helps..
Accept if you find value in this..
Happy Coding SD's :)


public void ProcessRequest(HttpContext context)
{
    Response.StatusCode = 401;
    Response.StatusDescription = "Authentication required";
    Response.SuppressFormsAuthenticationRedirect = true;
}



试试这个...在控制器中将其放在方法本身。


try this...in the controller else place it in the method itself.


这篇关于mvc 5身份验证是否与mvc4 / mvc3不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:14