小编Joh*_*ohn的帖子

使用AutoMapper来展平嵌套对象的更好方法是什么?

我一直在将域对象展平为DTO,如下例所示:

public class Root
{
    public string AParentProperty { get; set; }
    public Nested TheNestedClass { get; set; }
}

public class Nested
{
    public string ANestedProperty { get; set; }
}

public class Flattened
{
    public string AParentProperty { get; set; }
    public string ANestedProperty { get; set; }
}

// I put the equivalent of the following in a profile, configured at application start
// as suggested by others:

Mapper.CreateMap<Root, Flattened>()
      .ForMember
       (
          dest => dest.ANestedProperty
          , opt …
Run Code Online (Sandbox Code Playgroud)

c# nested flatten automapper

23
推荐指数
3
解决办法
1万
查看次数

具有表单身份验证的Web API匿名服务访问

我正在尝试确定如何在表单身份验证下配置对Web API控制器服务的访问.如果我添加授权配置以通过添加授权元素拒绝所有匿名用户:

<authorization>
   <! - 拒绝所有匿名用户 - >
   <deny users ="?" />
</ authorization>

只能按预期访问登录页面.但我还想访问从控制器返回的列表.我将[AllowAnonymous]属性添加到一个简单的服务,该服务返回用于填充下拉菜单的值.例如:

namespace WebAPI.Controllers
{
    public class RegisterController : ApiController
    {
        [AllowAnonymous]
        public List<ListElement> GetActivitiesList()
        {
            List<ListElement> li = new List<ListElement>();

            li.Add(new ListElement() { Id = 1, Text = "Item 1" });
            li.Add(new ListElement() { Id = 2, Text = "Item 2" });
            li.Add(new ListElement() { Id = 3, Text = "Item 3" });

            return li;

        }

    }
}
Run Code Online (Sandbox Code Playgroud)

我将controllers目录添加到web.config中允许的列表中:

<location path ="Controllers">
   <system.web>
   <authorization>
      <allow users …

asp.net forms-authentication web-config asp.net-web-api

2
推荐指数
1
解决办法
3362
查看次数