如何在MVC 4中为来自视图的Ajax调用设置基本身份验证 [英] How to set basic Authentication in MVC 4 for Ajax call from view

查看:112
本文介绍了如何在MVC 4中为来自视图的Ajax调用设置基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC 4的新手。我创建了MVC 4应用程序。我正在使用基本身份验证。当我第一次加载然后它工作正常,它要求凭据。但是当我从没有任何凭据的相同视图进行Ajax调用时,它仍然调用Controllers Action。当我使用基本身份验证时,它会假设要求凭据或者它假设提供错误未授权,但它会调用Action,然后当结果来自Controllers操作时它会显示401 Unauthorized。但这不是错误,Ajax请求是成功的。



请告诉我如何使用凭据进行从视图到Action的Ajax调用的基本身份验证?



提前致谢....

I am new at MVC 4. I have created MVC 4 application. I am using Basic Authentication. When I am first time loading then it works fine, it asks credentials. But when I make Ajax call from same view without any credentials still it calls Controllers Action. As I am using basic Authentication it suppose to ask credentials or it suppose to give error Unauthorized, but it makes calls to Action and then when result comes from Controllers action it says 401 Unauthorized. But it is not error, Ajax request is successful.

Please let me know how to make Basic Authentication for Ajax call from view to Action with credentials?

Thanks in advance....

推荐答案

我得到了解决方案,



1.您只需从IIS设置基本身份验证

2.将[Authorize]属性设置为所有操作。

3.发送用户名和密码来自ajax电话。
I got its solution,

1. you just set basic authentication from IIS
2. Set [Authorize] attribute to all actions.
3. send user name and password from ajax call.


这篇关于如何在MVC 4中为来自视图的Ajax调用设置基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆