ASP.NET MVC5 ID를 가지고 놀면서 클레임 기반 인증을 구현하려고합니다.
다음과 같은 오류가 발생합니다.
암시 적으로 'System.Collections.Generic.IEnumerable << 익명 형식 : 문자열 제목, 문자열 형식, 문자열 값 >>'형식을 'System.Web.Mvc.ActionResult'로 변환 할 수 없습니다. 명시 적 변환이 존재합니다 (캐스트가 누락 되었습니까?).
다음은 코드입니다.
public ActionResult GetClaims()
{
var identity = User.Identity as ClaimsIdentity;
var claims = from c in identity.Claims
select new
{
subject = c.Subject.Name,
type = c.Type,
value = c.Value
};
return claims;
}
http://bitoftech.net/2015/03/31/asp-net-web-api-claims-authorization-with-asp-net-identity-2-1/ 의 예를 따르고 있습니다.
MVC 컨트롤러에있는 경우 IEnumerable<Claim>
모델로 허용하는 뷰를 반환해야합니다 .
public ActionResult GetClaims()
{
var identity = User.Identity as ClaimsIdentity;
var claims = from c in identity.Claims
select new
{
subject = c.Subject.Name,
type = c.Type,
value = c.Value
};
return View(claims);
}
API 컨트롤러에 있으면 반환 할 수 있습니다. IHttpActionResult
public IHttpActionResult GetClaims()
{
var identity = User.Identity as ClaimsIdentity;
var claims = from c in identity.Claims
select new
{
subject = c.Subject.Name,
type = c.Type,
value = c.Value
};
return Ok(claims);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다