views:

97

answers:

2

I have a site that uses the SqlMembershiprovider. Its is a webshop. The user logs on with his username and password there.

Apart from that there is controller that is responsible for displaying delivery details for orders, that are imported from another system. These orders have no connection to users in the membershipsystem. To display delivery details you have to give the ordernumber and a token that is printed on the invoice.

To allow access I would like to implement a custom membershiprovider that is used only for this single controller. Is it feasible to use 2 different providers for one application?

EDIT

There are a couple of pages that the user can access once he provided the ordernumber and token.

+1  A: 

I don't think you need a separate membership provider. Just make that action and associated actions public (don't decorate with the AuthorizeAttribute). Then require that the order number and invoice token provided be valid. That is, if you have the order number and it's associated token, then you get to display the delivery details. You can check this by just verifying that they match in the data provided by the other system.

[AcceptVerbs( HttpVerbs.Post )]
public ActionResult DeliveryDetails( string orderNumber, string invoiceToken )
{
      var order = otherDb.Orders
                         .Where( o => o.OrderNumber == orderNUmber
                                      && o.InvoiceToken == invoiceToken )
                         .SingleOrDefault();

      if (order == null)
      {
          return View("Error");
      }

      return View(order);
}
tvanfosson
The problem is, that I have a couple of pages that need this logininformation. I realy have to have an authentication cookie. I update my question to include this information.
Malcolm Frexner
I think I would do this based on a session variable instead of a cookie. Create a custom action filter attribute that checks if the user is authorized OR if they have a session flag indicating they have a valid order/invoice token. This will help you avoid having to use special roles to distinguish normal, authenticated users from these "guests" and allow you to continue to use the default AuthorizeAttribute elsewhere.
tvanfosson
A: 

Hope this article helps: Using Two ASP.NET Membership Providers to CreateUser C#

Viktor Jevdokimov
Thats definitily interesting. Its not the solution yet, but at least I see that it is possible to configure 2 providers. Thanks!
Malcolm Frexner