小编San*_*ijn的帖子

在读取webapi 2令牌时,读取HttpResponseMessage.Content会抛出Newtonsoft.Json.JsonReaderException

嗨,我已经编写了一段代码,应该从ac#desktop应用程序登录到WebAPI 2站点,所有接缝都能正常工作但是我得到了一个带有如下消息的Newtonsoft.Json.JsonReaderException

读取字符串出错.意外的令牌:StartObject.路径'',第1行,第1位.

我的代码如下.

static internal async Task<string> GetBearerToken(string siteUrl, string Username, string Password)
{
  HttpClient client = new HttpClient();
  client.BaseAddress = new Uri(siteUrl);
  client.DefaultRequestHeaders.Accept.Clear();

  HttpContent content = new StringContent("grant_type=password&username=" + Username + "&password=" + Password, Encoding.UTF8, "application/x-www-form-urlencoded");

  Task<HttpResponseMessage> responseTask = client.PostAsync("Token", content);
  HttpResponseMessage response = await responseTask;

  if (response.IsSuccessStatusCode)
  {
     Task<string> message = response.Content.ReadAsAsync<string>();

     return await message;
  }
  else
  {
     return null;
  }
}
Run Code Online (Sandbox Code Playgroud)

fiddler报告的原始响应消息

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 593
Content-Type: application/json;charset=UTF-8
Expires: -1
Server: …
Run Code Online (Sandbox Code Playgroud)

c# security json asp.net-web-api2

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

ClaimTypes.NameIdentifier 与 Microsoft GraphApi UserID 有何关系

我正在使用 User.FindFirstValue(ClaimTypes.NameIdentifier) 来检索当前登录用户的用户 ID。结果似乎是一个随机字符串。

如果我在 Azure AD 中查找用户,那里的 ID 看起来就像一个 guid。如果在 Graph Api 中查找用户,则 Id 也是一个 Guid。有什么方法可以将这两个属性联系起来吗?

或者.net core当前用户与登录的Azure Ad用户无关?

asp.net-core microsoft-graph-api

5
推荐指数
0
解决办法
183
查看次数

ControlTemplate TargetType 与模板化类型不匹配

我在 WPF 中创建了这个用户控件

<UserControl x:Class="WpfApp1.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:WpfApp1"
         DataContext="{Binding RelativeSource={RelativeSource Self}}">
<UserControl.Template>
    <ControlTemplate TargetType="{x:Type local:UserControl1}">
        <Grid x:Name="LayoutRoot" Background="White" Margin="7,7,7,0">
        </Grid>
    </ControlTemplate>
</UserControl.Template>
Run Code Online (Sandbox Code Playgroud)

当我编译这个时,我收到以下错误。

“UserControl1”ControlTemplate TargetType 与模板化类型“UserControl”不匹配。

但当我调试应用程序时,它工作正常。

这个错误是什么意思?我该如何解决它?

wpf xaml

4
推荐指数
1
解决办法
3674
查看次数