我在.net网站上有一个问题。
注意:我是.net
的新用户我已经创建了一个网站并在我的本地IIS中进行了检查,并且它在本地工作正常。但是,当我将此网站部署到服务器时,我无法登录
我的代码流程是: 1.使用登录ID和密码创建Default.aspx,然后我按照以下方式提交
Dafault.aspx
<form id="form1" method="post" enctype="multipart/form-data" runat="server" name="loginForm" ng-controller="loginDetail as loginCtrl">
<!-- For ID -->
<input type="text" id="login_id" ng-model="login_id" class="form-control" name="login_id" placeholder="Enter Login ID" value="" required />
<!-- For Password -->
<input type="password" id="login_pass" ng-model="login_pass" class="form-control" name="login_pass" placeholder="Enter Your Password" value="test123" required />
<input type="submit" value="Login" class="btn-success"/>
</form>
现在JS是
app.js
var app = angular.module("Admin",['ui.bootstrap']);
app.controller('loginDetail', function ($scope, $http) {
this.loginToolTip = "Press this to \bLogin";
$scope.init = function () {
document.getElementById('login_id').focus();
};
$scope.submitForm = function () {
};
});
现在default.aspx.cs中的后端代码如下
Dafault.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Newtonsoft.Json;
namespace Main
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");
string loginid = Request.Form["login_id"];
string loginpass = Request.Form["login_pass"];
List<User> allUsers = new List<User>();
if (loginid != null)
{
try
{
using (StreamReader r = new StreamReader(Server.MapPath("json/admins.json")))
{
string json = r.ReadToEnd();
allUsers = JsonConvert.DeserializeObject<List<User>>(json);
}
int i = 0;
while (i < allUsers.Count)
{
if (allUsers[i].Name.ToLower() == loginid.ToLower() && Base64Decode(allUsers[i].Password) == loginpass)
{
Session["User"] = loginid.ToLower();
if(loginid.ToLower() == "admin")
{
Response.Redirect("AdminUser.aspx", false);
}
else
{
Response.Redirect("Admin.aspx", false);
}
}
i++;
}
if (i == allUsers.Count)
{
//Check NonSuccess.
}
Session["AllUsers"] = allUsers;
}
catch (System.Exception ex)
{
//Some issue
}
}
}
public static string Base64Decode(string base64EncodedData)
{
byte[] base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
}
}
public class User
{
public string Name { get; set; }
public string Password { get; set; }
}
我正在阅读JSON。
此代码在本地系统中正常运行。但不是在服务器中。当我按下“登录”按钮时,“页面”应重定向到“管理员/管理员页面”。但它只是刷新页面。我无法在服务器端进行调试,因为没有Visual Studio。也无法找到确切的问题。
答案 0 :(得分:0)
如果要调试代码。您可以在要调试的任何行之后写入日志。您可以使用此方法:
public static void WriteLog(string LogStr)
{
try
{
string LogFilePath = Server.MapPath("Logs.txt");
FileStream fs = new FileStream(LogFilePath, FileMode.Create | FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(DateTime.Now.ToShortDateString() + " | " + DateTime.Now.TimeOfDay + "=|" + LogStr);
sw.Close();
fs.Close();
}
catch (Exception e)
{
}
}
并称之为:
WriteLog(json);
另外还要检查web browser console
。