通过网页调试 aspx.cs



>我在.net网站上有一个问题。

注意:我是.net的新手

我已经制作了一个网站并在我当地的 IIS 中检查了它,它在本地工作正常。但是当我将此网站部署到服务器时,我无法登录

我的代码流是: 1.创建了一个默认.aspx 使用登录ID和密码,然后我提交如下

达克尔.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 是

应用.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 () {
     };
 });

现在默认的后端代码.aspx.cs如下

哒.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。也无法找到确切的问题。

如果要调试代码。您可以在要调试的任何行之后写入日志。您可以使用此方法:

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

最新更新