我在Visual Studio 2015中打开了Visual Studio 2012 Web窗体项目。我的问题出现在登录按钮单击后面的代码中。我尝试在按钮单击中调试代码,但是当我到达第一个if
语句并尝试进入代码时,调试器会跳过整个部分,即使条件为真且移动进入第二个if
声明就好了。两个文本框中肯定都有文本,我已经确定了。
以前调试VS 2012中的代码时,这个问题从未发生过。它只发生在VS 2015中。
下面我已经包含了代码:
Login.aspx HTML:
<asp:TextBox ID="txtUserId" CssClass="form-control" runat="server" Width="100%" TabIndex="1" PlaceHolder="Email"></asp:TextBox>
<asp:TextBox ID="txtPassword" CssClass="form-control" runat="server" Width="100%" TabIndex="2" PlaceHolder="Password" TextMode="Password"></asp:TextBox>
<br/>
<a runat="server" onserverclick="btnLogin_Click" class="ghost-button">Log-In</a>
Login.aspx代码背后:
protected async void btnLogin_Click(object sender, EventArgs e)
{
//the if statement in question
if ((txtUserId.Text != "") && (txtPassword.Text != ""))
{
await Login(txtUserId.Text, txtPassword.Text);
}
if (Session["AuthToken"] != null)
{
Response.Redirect("~/Dash.aspx", false);
}
else
{
txtUserId.Text = "";
txtPassword.Text = "";
lblUserError.Text = "Username and/or password is invalid";
}
}
public async Task Login(string username, string password)
{
try
{
var email = "";
string token;
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(_serviceUrl);
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var responseMessage = await httpClient.PostAsync("Token", new FormUrlEncodedContent(
new[] {
new KeyValuePair < string, string > ("grant_type", "password"),
new KeyValuePair < string, string > ("username", username),
new KeyValuePair < string, string > ("password", password)
}
));
var tokenModel = await responseMessage.Content.ReadAsAsync<TokenModel>();
token = tokenModel.AccessToken;
}
Session["AuthToken"] = token;
}
catch (Exception)
{
return;
}
}
我将不胜感激任何帮助。如果/何时需要更多信息,我会更新问题。