简体   繁体   English

通过网页调试aspx.cs

[英]Debug aspx.cs through web page

I have a question in .net Website.我在 .net 网站上有一个问题。

Note : I am new in .net注意:我是 .net 新手

I have made a website and checked it in my local IIS, and its working fine in local.我已经建立了一个网站并在我的本地 IIS 中进行了检查,并且在本地运行良好。 But when I am deploying this website to server then I am not able to login但是当我将此网站部署到服务器时,我无法登录

My code flow is: 1. Created a Default.aspx with login id and password, then i am submitting it as follow我的代码流程是: 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>

Now JS is现在 JS 是

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

and now backend code in default.aspx.cs is as follow现在 default.aspx.cs 中的后端代码如下

Dafault.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; }
}

I am reading from JSON.我正在阅读 JSON。

This code is working fine in Local system.此代码在本地系统中运行良好。 But not in Server.但不在服务器中。 When I press Login button then Page should redirect to Admin/AdminUser Page.当我按下登录按钮时,页面应该重定向到 Admin/AdminUser 页面。 but it is just refreshing the page.但它只是刷新页面。 I am unable to debug as well, in server side, as there is no Visual Studio.我也无法在服务器端进行调试,因为没有 Visual Studio。 Also not able to find the exact issue.也无法找到确切的问题。

If you want to Debug your code.如果你想调试你的代码。 You can write logs after any line where you want to debug.您可以在要调试的任何行之后写入日志。 You can use this method:您可以使用此方法:

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)
    {

    }
}

And call it like :并称之为:

WriteLog(json);

Plus also check your web browser console .另外还要检查您的web browser console

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

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