在MVC3项目中具有自定义表单身份验证的Ajax [英] Ajax with custom Form Authentication in MVC3 project

查看:125
本文介绍了在MVC3项目中具有自定义表单身份验证的Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个具有自定义表单身份验证的MVC3项目.
我使身份验证工作正常(我使用了"HttpContext.Current.User.Identity.IsAuthenticated"属性,以确保它可以正常工作)

我在表单上使用了Ajax:

Hi,

I have an MVC3 project with custom form authentication.
I got the authentication to work fine (I used the "HttpContext.Current.User.Identity.IsAuthenticated" property in order to make sure it worked)

I use on my of my forms an Ajax:

$(document).ready(function () {
        $.ajax({
            url: '/MyPages/MyControllerFunction',
            type: 'POST',
            success: function (result) { $('#MyJavaTemplate').tmpl(result).appendTo('#MyHtmlTable'); },
            error: function (result) {
                $('#errorDisplay').html(result.responseText);
            }
        })
    });



当我到达此页面(ajax应该调用此控制器的函数)时,出现此错误:

HTTP错误404.0-找不到
您要查找的资源已被删除,名称已更改或暂时不可用.


仅当我通过Ajax调用控制器的功能时,这种情况才会发生.在将程序更改为可以使用表单身份验证之前,所有步骤都可以正常工作.好像用户未通过身份验证(即使通过了验证)

应该怎么解决这个问题?

谢谢



When I get to this page (and the ajax should call this controller''s function) I get this error:

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.


It only happens to me with mhen I call the controller''s function through ajax. Before I changed my program to work with form authentication, It all worked. It''s as if the user is not authenticated (even though it is)

What should solve this problem?

Thanks

推荐答案

(文档).ready( function (){
(document).ready(function () {


.ajax({ 网址:' /MyPages/MyControllerFunction', 类型:' POST', 成功:功能(结果){
.ajax({ url: '/MyPages/MyControllerFunction', type: 'POST', success: function (result) {


(' #MyJavaTemplate').tmpl(result).appendTo(' # MyHtmlTable'); }, 错误:函数(结果){
('#MyJavaTemplate').tmpl(result).appendTo('#MyHtmlTable'); }, error: function (result) {


这篇关于在MVC3项目中具有自定义表单身份验证的Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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