Sure, you can remote debug your ASP.NET app hosted on your servers, please follow the following How-to guide to learn more details:
https://learn.microsoft.com/en-us/visualstudio/debugger/remote-debugging-aspnet-on-a-remote-iis-7-5-computer?view=vs-2019#network-requirements
is it possible to debug asp.net mvc app on the server?
We provide applicant tracking software for our clients. This is done via the web. We host these websites on our servers. Every now and then one of them will want to view something from the server logs. So I wrote a log analyzer that will read the log files and create the various reports. When I test it on my local machine using the logs from a single specific user it works fine.
So I installed the software to a directory on our servers and then for each client I create an app in IIS that points to the log Analyzer.
Here is some code that says which logs to read in the Controller
string processID = Request.ServerVariables["INSTANCE_ID"].ToString();
Logfile log = new Logfile();
string path = @"C:\inetpub\logs\LogFiles\W3SVC" + processID;
List<String> logs = log.ListLogs((DateTime)StartDate, (DateTime)EndDate);
List<Logfile> data = await log.GetLogs(logs, path);
and here is the class
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
namespace Log_Analyser.Models
{
public class Logfile
{
public string date { get; set; }
public string time { get; set; }
public string ServerIP { get; set; }
public string Method { get; set; }
public string URI { get; set; }
public string Query { get; set; }
public string Port { get; set; }
public string Username { get; set; }
public string IP { get; set; }
public string UserAgent { get; set; }
public string Referrer { get; set; }
public string Status { get; set; }
public string SubStatus { get; set; }
public string Win32Status { get; set; }
public string TimeOnSite { get; set; }
public string Browser { get; set; }
public string Domain { get; set; }
public List<String> ListLogs(DateTime StartDate, DateTime EndDate)
{
Cache c = new Cache();
List<String> logList = c.Get("FileList") as List<String>;
if (logList == null)
{
logList = new List<String>();
foreach (DateTime day in EachDay(StartDate, EndDate))
{
string d = day.Day.ToString("00");
string m = day.Month.ToString("00");
string yr = day.Year.ToString().Substring(2);
string logfile = "u_ex" + yr + m + d + ".log";
logList.Add(logfile);
}
c.Insert("FileList", logList, null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration);
}
return logList;
}
public Task<List<Logfile>> GetLogs(List<String> logList, string path)
{
Cache cache = new Cache();
List<Logfile> Files = cache.Get("logFiles") as List<Logfile>;
if (Files == null)
{
Files = new List<Logfile>();
foreach (string log in logList)
{
string newFile = path + @"\" + log;
if (File.Exists(newFile))
{
using (StreamReader sr = new StreamReader(newFile))
{
while (sr.Peek() >= 0)
{
Logfile lf = new Logfile();
string line = sr.ReadLine();
var info = Regex.Split(line, @"\s+");
if (!info[0].StartsWith("#"))
{
lf.date = info[0];
lf.time = info[1];
lf.ServerIP = info[2];
lf.Method = info[3];
lf.URI = info[4].ToLower();
lf.Query = info[5].ToLower();
lf.Port = info[6];
lf.Username = info[7];
lf.IP = info[8];
lf.UserAgent = info[9];
lf.Referrer = info[10].ToLower();
lf.Domain = ExtractDomainNameFromURL_Method1(lf.Referrer);
lf.Status = info[11];
lf.SubStatus = info[12];
lf.Win32Status = info[13];
lf.TimeOnSite = info[14];
lf.Browser = GetBrowser(info[9].ToUpper());
Files.Add(lf);
}
}
}
}
}
cache.Insert("logFiles", Files,null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration);
}
return Task.FromResult(Files);
}
}
My issue is that when I run on the webserver no information is returned. Is it possible to debug on the server itself?
-
CitrusYan-MSFT 151 Reputation points
2021-06-29T09:04:54.3+00:00
1 additional answer
Sort by: Most helpful
-
Duane Arnold 3,216 Reputation points
2021-06-29T21:56:39.023+00:00 Why don't you use local IIS on your developer machine to debug Web project on local IIS through visual stuido? IIS Express is not IIS on the Web server machine. Local IIS is the Web server on your local machine like IIS is on the Web server machine.