天青与移动服务使用ASP.NET 4.0成员资格提供 [英] Using ASP.NET 4.0 membership provider with Azure Mobile Services

查看:130
本文介绍了天青与移动服务使用ASP.NET 4.0成员资格提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伊夫碰到的一个主要问题。

Ive come up against a major problem.

我建立这emloys一个ASP.NET 4 Web应用程序> Azure的SQL>的Azure移动服务>的Windows Phone 8应用的系统。该数据便被输入到这已经是托管在Azure和它采用的成员资格提供程序,因此它的默认表网站。这个数据已经成功地存储在Azure上的SQL数据库。

I am building a system which emloys a ASP.NET 4 Web App > Azure SQL > Azure Mobile Service > Windows Phone 8 app. The data is inputed into the Web Site which is already hosted on azure and which employs the Membership Provider and hence its default tables. This data is stored already successfully on Azure SQL db.

我的主要障碍是的的Azure移动服务要求在其每一个表有自己的主键被称为身份证 - 小写!疯狂的在我看来。当然的成员资格提供对PK的不同的名字。

My major obstacle is Azure Mobile Services requires each and every table on it to have their primary key to be called "id" - lower case! Crazy in my opinion. And of course the Membership Provider has different names for PK's.

问题 - 我应该重新设计我的整个ASP.NET应用程序(很多时间n精力)使用自定义成员(名为ID明杆PK),或试图找到一种方法来尝试动态更改列名ID(不知道如何!)。有没有人有什么建议?大部分AP preciated提前。

Question - Should I redesign my whole ASP.NET application (lot of time n effort) to use CUSTOM Membership (with PK coloum named "id") or try to find a way to try to change column name on the fly to "id" (no idea how to!). Has anyone any suggestions? Much appreciated in advance.

推荐答案

我不认为使用的Azure移动服务应该推你返工所有现有的架构。话虽这么说,THRE有两种可能的解决方案,你可以试试。

I do not think that using Azure Mobile Services should push you to rework all of your existing architecture. That being said, thre are two possible solutions that you could try.

第一种是真正不使用的Azure移动服务的EntityData类 - 它不是强制性的,从EntityData继承ORER使用AMS。你需要的情况下,要使用TableController这可能是一个好主意,因为它为您提供了大量的内置功能,但你可以选择使用普通ApiController和当前的模型继承EntityData。

The first one is to actually not use the EntityData classes of Azure Mobile Service - it is not mandatory to inherit from EntityData in orer to use AMS. You need to inherit EntityData in case you want to use TableController which is probably a good idea since it provides you with a lot of builtin functionality but you can choose to use a plain ApiController and your current models.

另一种可能的解决方案是使用所谓的DTO(数据传输对象),它可以帮助你保持当前的架构,但仍可以使用AMS。

Another possible solution is to use the so called DTOs (Data Transfer Objects) which can help you keep your current architecture but still be able to use AMS.

下面是有关DTO更多信息某个环节:
什么是数据传输对象?
<一href=\"http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-entity-framework/part-5\"相对=nofollow>创建数据传输对象(DTO的)

Here are some link with more info about DTO: what is Data Transfer Object? Create Data Transfer Objects (DTOs)

一个可能的implmentation:

A possible implmentation:

假设你有以下型号:

public class MyUser
{
    public int MyId
    {
        get;
        set;
    }

    public string SomeOther
    {
        get;
        set;
    }
}

正如你所指出的,如果你想使用AMS这种模式,你需要使用它们的ID属性而不是身份识别码。如果你想保持完好MYUSER您能介绍以下类:

As you have pointed out, if you want to use this model with AMS you need to use their Id property instead of MyId. If you want to keep MyUser intact you can introduce the following class:

public class MyUserDTO : EntityData
{
    public string SomeOther
    {
        get;
        set;
    }
}

现在您的服务将使用MyUserDTO这就好比为你的原始模型的代理。你必须解决的问题是,你应该MyUserDTO和MYUSER之间进行转换。如果你的模型很简单,你没有复杂的层次结构,这将是很容易的。如果你有复杂的模型的DTO可能不是正确的做法。 Automapper 是一个工具,可以帮助您从模型到DTO的,反之亦然映射。

Now your service will use MyUserDTO which is like a proxy for your original model. The problem that you have to tackle is that you should convert between MyUserDTO and MyUser. If your models are simple and you do not have complex hierarchies that would be quite easy. If you have complex models DTOs might not be the correct approach. Automapper is a tool that can help you with mapping from model to DTOs and vice-versa.

不过,我没有你的架构多的信息,并使用DTO的可能不是一个很好的选择。

Still, I do not have much information about your architecture and using DTOs might not be a good fit.

这篇关于天青与移动服务使用ASP.NET 4.0成员资格提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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