简体   繁体   English

通过localhost上的IIS从ASP.NET/C#连接到Atlassian JIRA

[英]Connecting to Atlassian JIRA from ASP.NET/C# via IIS on localhost

I am trying to create a small utility application wherein I need to login to JIRA (Atlassian.com). 我正在尝试创建一个小型实用程序,其中需要登录JIRA(Atlassian.com)。

Our JIRA server is hosted at Atlassian - example.atlassian.net and the application that I am trying to develop is hosted on my local server (192.168.1.XXX), on IIS. 我们的JIRA服务器托管在Atlassian-example.atlassian.net上,而我要开发的应用程序托管在IIS上的本地服务器(192.168.1.XXX)上。 The application uses ASP.NET / C#. 该应用程序使用ASP.NET/C#。

I tried to run the sample JIRA example which presents a simple login page wherein the user is supposed to enter his/her JIRA credentials. 我尝试运行示例JIRA示例,该示例提供了一个简单的登录页面,用户应在其中输入其JIRA凭据。 Everything is fine up to this point. 到目前为止,一切都很好。

If someone enters incorrect username/password, the application displays some error message (which I believe is broken): 如果有人输入了错误的用户名/密码,应用程序将显示一些错误消息(我认为该消息已损坏):

The remote server returned an error: (401) Unauthorized.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[WebException: The remote server returned an error: (401) Unauthorized.]
   System.Net.HttpWebRequest.GetResponse() +1743
   JiraExample.JiraManager.RunQuery(JiraResource resource, String argument, String data, String method) +597
   JiraExample.JiraManager.GetProjects() +100
   JiraExample.Login.Button1_Click(Object sender, EventArgs e) +143
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11802193
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1735

But if correct username/password are entered, it says "This site cannot be reached" and points to firewall/proxy issues. 但是,如果输入正确的用户名/密码,则会显示“无法访问此站点”,并指出防火墙/代理问题。

Is it because of lack of FQDN or because of the private IP address? 是因为缺少FQDN还是因为专用IP地址? If yes, is there a way to forward the JIRA response to my application? 如果是,是否可以将JIRA响应转发到我的应用程序?

Thanks 谢谢

EDIT: 编辑:

This example is using basic authentication: 此示例使用基本身份验证:

    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    request.ContentType = "application/json";
    request.Method = method;
    string base64Credentials = GetEncodedCredentials();
    request.Headers.Add("Authorization", "Basic " + base64Credentials);

    private string GetEncodedCredentials()
    {
       string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
       byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
      return Convert.ToBase64String(byteCredentials);
   }

(above code listing is partial) (以上代码清单为部分内容)

It's because of the private IP address. 这是因为专用IP地址。 The sample you're using is built around OAuth, which involves a roundtrip of tokens. 您使用的示例是围绕OAuth构建的,该过程涉及令牌的往返。 See this Jira OAuth article. 请参阅这篇Jira OAuth文章。 To keep it simple, use basic authentication by base64-encoding your username:password and add it (with a prefix of "Basic") to the Authorization header. 为简单起见,请通过对您的username:password进行base64编码来使用基本身份验证 ,并将其(带有“ Basic”前缀)添加到Authorization标头中。

var encodedAuth = System.Convert.ToBase64String(
    System.Text.Encoding.UTF8.GetBytes("username:password")
);
var Client = new HttpClient();
Client.DefaultRequestHeaders.Add("Authorization", "Basic " + encodedAuth);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM