1
任何人都可以告訴我爲什麼我無法在我創建的新類的斷點上處理WebApi發佈請求?下面是我爲裝修新的類和方法的代碼與類屬性無法在AuthorizeAttribute類上創建斷點
namespace MercuryUserWeb.Core.Authorization {
public class ClientUserApi : System.Web.Http.AuthorizeAttribute
{
public void OnAuthorization(AuthorizationContext filterContext)
{
WebRequestState webRequestState = ContainerHome.Container.Resolve<WebRequestState>();
ActionDescriptor actionDescriptor = filterContext.ActionDescriptor;
if (actionDescriptor.IsDefined(typeof(StaffUserAuthorizeAttribute), true))
return;
if (!webRequestState.IsAuthenticated || webRequestState.ClientUser == null)
{
filterContext.Result = new HttpUnauthorizedResult();
return; // 401, always show log-in page
}
}
}
}
控制器動作
namespace MercuryUserWeb.Areas.JApi.Controllers{
[ClientUserApi]
public class ClientViewController: ApiController, IJApiController
{
[System.Web.Http.HttpPost]
[ClientUserApi]
public ActionResult assignViews(ClientViewModel model)
{
string[] clientViewIdsArray = model.selectedViewsForClient.Split(',');
IEnumerable<long> parsedClientViewIdArray = clientViewIdsArray.Select(long.Parse);
List<long> clientViewsIdList = parsedClientViewIdArray.ToList();
string[] volPoolIdArray = model.volPoolIds.Split(',');
IEnumerable<long> parsedIdArray = volPoolIdArray.Select(long.Parse);
List<long> volPoolIdList = parsedIdArray.ToList();
var clientId = clientApiPrincipal.ClientUser.ClientId;
clientViewService.assignViews(clientViewsIdList, volPoolIdList, clientId);
return null;
}
謝謝。現在就試試這個。 –
謝謝。這工作。雖然我仍然獲得WebRequestState的空值。不知道爲什麼.... –