开发者

ASP.NET MVC Authorization with jQuery & AJAX posting in IE

开发者 https://www.devze.com 2023-01-06 07:09 出处:网络
I\'m not sure how to post this question without including half of my sites code, but here goes. I have a site with a Subcontract Form, a Company Form, and a Contact Form.From the subcontract form, yo

I'm not sure how to post this question without including half of my sites code, but here goes.

I have a site with a Subcontract Form, a Company Form, and a Contact Form. From the subcontract form, you can create a new company and/or a new contact via buttons which open jQuery dialogs and post the company or contact information. From the company form, there is a button to create a new contact.

From subcontract form:

$('#popupCreateCompany').dialog(
        {
            autoOpen: false,
            modal: true,
            width: 600,
            open: function(event, ui) {
                if ($('#primary_company').val().length > 0开发者_开发百科) {
                    $('#secondary').attr('checked', 'true');
                }
                else {
                    $('#primary').attr('checked', 'true');
                    $('#sec').hide();
                }
            },
            buttons:
            {
                'Add': function() {
                    var dialog = $(this);
                    var form = dialog.find('input:text, select');
                    $.post('<%= ResolveUrl("~/company/post") %>', $(form).serialize(), function(data) {
                        if (data.Result == "success") { ...

.

$('#popupCreateContact').dialog(
        {
            autoOpen: false,
            modal: true,
            width: 600,
            buttons:
            {
                'Add': function() {
                    var dialog = $(this);
                    var form = dialog.find('input:text, select');
                    $.post('<%= ResolveUrl("~/contact/post") %>', $(form).serialize(), function(data) { ...

From the company form:

$('#popupCreateContact').dialog(
        {
            autoOpen: false,
            modal: true,
            buttons:
            {
                'Add': function() {
                    var dialog = $(this);
                    var form = dialog.find('input:text, select');
                    $.post('<%= ResolveUrl("~/contact/post") %>', $(form).serialize(), function(data) {
                        if (data.Result == "success") { ...

This functionality worked until we implemented some custom authorization to the site. Now, you can add a contact from the subcontract form, but you cannot add a company from the subcontract. You cannot add a contact from the company form. When you click "Add" nothing happens. I've added an alert before and after the $.post line and it hits the alert before, but not the alert after. Put a breakpoint at contact/post and it never gets there. The same Authorization groups have access to add subcontracts, companies, and contacts.

In the Company Controller:

[AcceptVerbs(HttpVerbs.Post), MarlowAuthorize(Roles = "Subcontract_Modify, Admin", ViewName = "AuthorizationError")]
    public JsonResult Post(company company)
    {
        if (ModelState.IsValid)
        {
            try
            {

The same contact post routine is called from the subcontract form as from the company form. But one works and the other doesn't. In the Contact Controller:

[AcceptVerbs(HttpVerbs.Post), MarlowAuthorize(Roles = "Subcontract_Modify, Admin", ViewName = "AuthorizationError")]
    public JsonResult Post(contact contact)
    {
        if (ModelState.IsValid)
        {
            try
            {

I've tried adding Authorization attributes to places in the controller and I've tried removing them. Whatever the combo I try, I get the same result. You can add a contact from the subcontract, but not a company. And, you cannot add a contact from the company. I keep thinking that knowing that will lead to me to see what the difference is somewhere, but I can't seem to find it.

EDIT Just went into Firefox to use Firebug and it appears that it's working in Firefox. But doesn't work in IE7 or IE8.


Use Fiddler and compare the differences in the data that Firefox and IE sends.


Got it to work, but I'd be interested to know if anyone can explain the "why".

Changed this

var dialog = $(this);
var form = dialog.find('input:text, select');
$.post('<%= ResolveUrl("~/company/post") %>', $(form).serialize(), function(data) { ...

to

var dialog = $(this);
var form = $('#popupCreateCompany').find('input:text, select');
$.post('<%= ResolveUrl("~/company/post") %>', $(form).serialize(), function(data) { ...

and it now works in IE.

I don't understand why it worked until last week and why it still worked for the contact from subcontract, but not the company from subcontract or the contact from company.

0

精彩评论

暂无评论...
验证码 换一张
取 消