Hi,
I have below function which is used submit bugs to BugTracker.NET from C#. It's working fine. But i want once the submitted bugs through this function should be open bugs.aspx with submitted bugs. Now always redirect login page. That should not be. Should be open bugs.aspx with loggedin user. Thanks, Help me out.
public bool SubmitBugToBugTracker(string serverName,
bool useProxy,
string proxyHost,
int proxyPort,
string userName,
string password,
string description,
string comment,
int projectId)
{
if (!serverName.EndsWith(@"/"))
{
serverName += @"/";
}
string requestUrl = serverName + "insert_bug.aspx";
string requestMethod = "POST";
string requestContentType = "application/x-www-form-urlencoded";
string requestParameters = "username=" + userName
+ "&password=" + password
+ "&short_desc=" + description
+ "&comment=" + comment
+ "&projectid=" + projectId;
// POST parameters (postvars)
byte[] buffer = Encoding.ASCII.GetBytes(requestParameters);
// Initialisation
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(requestUrl);
// Add proxy info if used.
if (useProxy)
{
WebReq.Proxy = new WebProxy(proxyHost, proxyPort);
}
// Method is POST
WebReq.Method = requestMethod;
// ContentType, for the postvars.
WebReq.ContentType = requestContentType;
// Length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;
// Open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
// Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
// Read the response (the string)
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
string responseStream = _Answer.ReadToEnd();
// Find out if bug submission was successfull.
if (responseStream.StartsWith("OK:"))
{
//MessageBox.Show("Bug submitted successfully.");
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Bug submitted successfully.');", true);
// Redirect to bugs.aspx
// Response.Redirect("http://localhost/btnet/bugs.aspx?" + "userName=" + userName + "&password=" + password);
Response.Redirect(serverName +"bugs.aspx?" + "userName=" + userName + "&password=" + password);
return true;
}
else if (responseStream.StartsWith("ERROR:"))
{
//MessageBox.Show("Error occured. Bug hasn't been submitted.\nError Message: " + responseStream);
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Error occured. Bug hasn't been submitted.\nError Message:' '"+responseStream+"');", true);
return false;
}
else
{
//MessageBox.Show("Error occured. Bug hasn't been submitted.\nError Message: " + responseStream);
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Error occured. Bug hasn't been submitted.\nError Message:' '" + responseStream + "');", true);
return false;
}
}
protected void btnSendBugs_Click(object sender, EventArgs e)
{
string serverName = "http://localhost/btnet";
bool useProxy = false;
string proxyHost = "http://localhost/btnet";
int proxyPort = 0;
string userName = "admin";
string password = "admin";
string description = "Everycell is not applicable";
string comment = "";
int projectId = 1;
SubmitBugToBugTracker(serverName, useProxy, proxyHost, proxyPort, userName, password, description, comment, projectId);
}