小编Ale*_*hin的帖子

具有基本身份验证的Webclient/HttpWebRequest返回404找不到有效URL

编辑:我想回过头来注意问题根本不是我的问题,而是另一个公司的代码.

我正在尝试使用基本身份验证来启动页面.我一直收到404 Page not found错误.我可以将我的网址复制并粘贴到浏览器中并且工作正常(如果我没有登录到他们的网站,它会弹出一个凭据框,否则它会打开我想要打开的内容).我必须到正确的地方并进行身份验证,因为如果我一方面输入了错误的用户名/密码,我得到一个401(未经过身份验证的错误),如果我在查询字符串中传递了一个错误的参数,我会收到内部服务器错误500 .我尝试使用Webclient和HttpWebRequest都导致相同的404未找到错误.

使用Webclient:

string url = "MyValidURLwithQueryString";
WebClient client = new WebClient();
String userName = "myusername";
String passWord = "mypassword";
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + passWord));
client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
var result = client.DownloadString(url);
Response.Write(result);
Run Code Online (Sandbox Code Playgroud)

使用HttpWebRequest

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("MyValidURL");
string authInfo = "username:password";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers.Add("Authorization", "Basic " + authInfo);
request.Credentials = new NetworkCredential("username", "password");
request.Method = WebRequestMethods.Http.Get;
request.AllowAutoRedirect = true;
request.Proxy = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream …
Run Code Online (Sandbox Code Playgroud)

.net c#

54
推荐指数
3
解决办法
10万
查看次数

使用Windows身份验证连接到SQL Server

当我尝试使用以下代码连接到SQL Server时:

SqlConnection con = new SqlConnection("Server=localhost,Authentication=Windows Authentication, Database=employeedetails");
con.Open();
SqlCommand cmd;
string s = "delete employee where empid=103";
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确,以及SQL Server是否配置为允许远程连接.(提供程序:SQL网络接口,错误:25 - 连接字符串无效)

c# sql sql-server asp.net

50
推荐指数
3
解决办法
28万
查看次数

FloatingActionButton 在列表的最后一项上

我有一个带有FloatingActionButton. 我想让列表在列表之前完成,FloatingActionButton因为列表的最后一项不再可见(FAB 已结束列表项)

return Scaffold(
    body: ListView(
      scrollDirection: Axis.vertical,
      controller: _scrollController,
      shrinkWrap: true,
      children: <Widget>[
        _buildUpcomingExpansionTileEvents(myUpcomingEvents),
        _buildPastExpansionTileEvents(myPastEvents),
      ],
    ),
    floatingActionButton: UnicornDialer(
        parentButtonBackground: Colors.blue,
        orientation: UnicornOrientation.VERTICAL,
        parentButton: Icon(OMIcons.add),
        childButtons: childButtons));
Run Code Online (Sandbox Code Playgroud)

如何更改我的列表以完成一个空项目?或者这个问题的最佳解决方案是什么?

dart floating-action-button flutter flutter-layout

7
推荐指数
1
解决办法
1525
查看次数

角色 - 身份服务器 4

我有一个使用 Asp.Net Core 2.0 API、Identity Server 和 WPF 应用程序完成的项目。登录后,我可以从 WPF 访问 API。

现在我正在尝试实现角色,以便我能够仅授权某些用户访问 API。

在 Config.cs 中,我声明了我的客户端并添加到范围:

  new Client
            {
             AllowedScopes =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                    IdentityServerConstants.StandardScopes.OfflineAccess,
                    "fiver_auth_api",
                    "role"
                },
            AlwaysIncludeUserClaimsInIdToken=true
           }
Run Code Online (Sandbox Code Playgroud)

声明测试用户:

  return new List<TestUser>
        {
            new TestUser
            {
                SubjectId = "", Username = "", Password = "",
                Claims = new List<Claim>
                {
                    new Claim(JwtClaimTypes.Email, "AliceSmith@email.com"),
                    new Claim(JwtClaimTypes.EmailVerified, "true", ClaimValueTypes.Boolean),
                    new Claim(JwtClaimTypes.Role, "Admin"),
                    new Claim(JwtClaimTypes.Scope, "openid offline_access fiver_auth_api")
                }
            }
       }   
Run Code Online (Sandbox Code Playgroud)

在我使用的控制器中:

[Authorize(Roles = "Admin")]
Run Code Online (Sandbox Code Playgroud)

为什么我没有在令牌中获得用户声明?

roles claims identityserver4

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

从 JSON 中提取第一个元素

我怎样才能从 Json 中取出第一个元素?

//take result back
    void HandleIncomingMessage(object sender, PEventArgs e)
    {
        RetMessage += e.Result;
        //here can not deserialize correct
        var deserialized_message = JsonConvert.DeserializeObject<Message>(RetMessage);
    }
Run Code Online (Sandbox Code Playgroud)

在这里,我正在执行反序列化,但是因为它占用了整个对象,因此无法正确解析它。

我只需要 JSON。[0]

编辑:原始 Json :

 [{"unique_id":55,"action_name":"INSERT","start_date":"2018-06-11T16:00:00","end_date":"2018-06-11T17:00:00"},"1sddsd","my_channel"]
Run Code Online (Sandbox Code Playgroud)

c# json

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

在flutter中设置下拉按钮的默认值

我有一个正常工作的下拉按钮,但是当我尝试设置默认值时,它将失败,并显示以下错误:

'package:flutter / src / material / dropdown.dart':失败的断言:620行pos 15:'item == null || items.isEmpty || 值== null || items.where(((DropdownMenuItem item)=> item.value == value).length == 1':不正确。

这是我的下拉按钮:

 Widget changeWorkspace() {
return StatefulBuilder(
    builder: (BuildContext context, StateSetter setState) {
  return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
    Padding(
      padding: EdgeInsets.all(8.0),
      child: DropdownButton<AssignedWorkspace>(
          isExpanded: true,
          hint: Text("SELECT WORKSPACE"),
          value: selectedWorkspace,
          onChanged: (dropdownValueSelected) {
            setState(() {
              selectedWorkspace = dropdownValueSelected;
            });
          },
          items: workspaces != null && workspaces.length > 0
              ? workspaces.map((AssignedWorkspace workspace) {
                  return new DropdownMenuItem<AssignedWorkspace>(
                    value: workspace, …
Run Code Online (Sandbox Code Playgroud)

default-value dropdown flutter dropdownbutton

0
推荐指数
1
解决办法
125
查看次数