|
Hi, I need little help with starting the web API because I am not familiar with web development. My goal is to set up REST API for just one endpoint and some webhook or something to receive callback POST notification. I need to send every day request to subscribe for next day and receive notifications from it.
I created new project c# ASP.NET Core Web App (NET 7) and installed Swashbuckle.AspNetCore package, build it and run. It loads the page locally with no problems but when I publish it and upload to my (paid) hosting server it show me 404 error. In my output I have webroot folder and app.dll app.exe and couple .js files but no index.js or index.php to show startup page, I think it must be something to start. How can I execute or start my app on web page? I created index.php or .html whith "hello world" and after upload it in root folder shows page instantly. Can anyone help me or guide me how to solve this?
|
|
|
|
|
I got information now that my hosting server is not for asp.net, it's for linux not windows. Dummy question: is there any way to bridge it?
|
|
|
|
|
|
Hello,
i use ajax, HtmlEditorExtender to let users writing their own description
i store in database, and in my database i can see properly data store in table like this :
'🔸🖤 DANCE SQUARE 🖤🔸\n📝 LA TRILOGIE :\n3 dates à ne surtout pas manquer\n.\n🟧◾️ 29 Octobre - LA'
but when i read data by sql, in string variable, i lose all the specials characters like hearts in my example, all specials characters are replace by ?
what should i do to keep specials characters ? (correctly store in database.)
i read like this :
if (!res.IsDBNull(i))
ss {
return res.GetString(i);
}
else
{
return string.Empty;
}
|
|
|
|
|
Even money's on this (NOUS VOYON (sp?)):
CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
A blind man could probably use GOOGLE to find this but ... I haven't got a blind man's machine so this is a conjecture on my part.
(Un aveugle pourrait probablement utiliser GOOGLE pour trouver cela mais ... je n'ai pas de machine pour aveugle, donc c'est une conjecture de ma part.)
|
|
|
|
|
Yes, but an intelligent man could understand that I have already found and applied this, but it is not enough
|
|
|
|
|
Probably your data is Unicode or UTF-8. I am not an expert on such things but you should ensure the data is being processed approriately.
One possibility is the font being used. The data might be just fine but if you are not using a font that supports Unicode or UTF-8 (whatever is relevant) then you won't see it correctly.
However the "\n" implies it is something else. That character is the carriage return, such as the Enter key in the keyboard.
Note that Rich Text is not the same as HTML. The formats are very different.
|
|
|
|
|
Currently I'm using c#, web forms and ms sql. I'm using ms sql as my search engine for searching for jobs and candidates. I ran across two issues. Recruiters need it to be simple and be able to search with regular basic boolean functions and sometimes they paste an entire job description and wonder why it takes for ever or crashes.. timeout.
What products should be looking at to fix my issues? This needs to be an in-house hosted option.
|
|
|
|
|
The products you are using should be fine. The issue is likely to be your implementation. If a recruiter can post a complete job description as a search entry then there is something wrong at the front end. Change the search box(es) so they are restricted to keywords, and maybe no more than six or seven.
|
|
|
|
|
You have to search for it according to the website so that you can find it without any hassle. The job depends on the web search you are doing according to you get the search. Whenever you search for any job online you have to search it with multiple keywords to get the relevant one for you.
|
|
|
|
|
Searching for keywords on Jobs / CVs (Resumes) can never lead to anything but grief. Ask any job applicant or recruiter who has been stung by keyword search systems.
If you are, say, looking for a job application that needs SQL and C#, how would you reject some sentence like "I have never used SQL and I hate C#" or distinguish the relative merits of an applicant who says "I have 20 years experience in C#" from one who says "I have not used C# but I would like to learn it".
|
|
|
|
|
Greetings again dear experts,
Back for more your great assistance.
DateTime runDate = DateTime.Parse(rsRunDate.Text);
When I run my app, I get the following:
The string was not recognized as a valid DateTime. There is an unknown word starting at index 0. This error points to the line code I posted.
I tried changing the code to the following:
DateTime runDate = DateTime.ParseExact(srRunDate.Text,"dd/MM/yyyy", null);
However, I still get same error.
I tried the following:
DateTime _runDate;
string runDate = "";
_runDate = DateTime.Parse(srRunDate.Text);
runDate = _runDate.ToString("dd/MMM/yyyy");
But then, the following produces an error:
if (runDate.Date > DateTime.Now.Date)...
Now, I get the following error:
The name 'runDate' does not exist in the current context
I ran the code in debug mode, it shows runDate with the following value: {1/1/0001 12:00:00 AM} System.DateTime
I am out of ideas.
Any ideas how to fix this?
modified 20-Oct-22 13:04pm.
|
|
|
|
|
You shouldn't be looking at the variable that hold the parsed value. The text hasn't been parsed, so what's the point?
You should be looking at the content of srRunDate.Text . For example, trying to use Parse on an empty string will throw an exception.
You should change your code to use TryParse instead. At least then, you'll get a return value of true or false denoting if the parse operation worked or not.
|
|
|
|
|
Thank you very much Dave.
|
|
|
|
|
"{" is not part of a date. The exception is correct.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I am migrating the .Net Project to .Net core 3.1 and there are loads of dependencies in the project so I cannot create a new .Net core application. How can I add Program.Cs file in my existing .Net api project?
I need this code in my existing .Net api project
<pre>public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog((hostingContext, loggerConfiguration) =>
{
var connectionString = hostingContext.Configuration.GetSection("Serilog:WriteTo:0:Args:connectionString");
connectionString.Value = connectionString.Value;
loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration);
});
}
|
|
|
|
|
If you're migrating, you might want to move to something that will be supported for more than two months:
.NET Core 3.1
End of Support: December 13, 2022
Currently, the "long-term support" (LTS) version is .NET 6.0, which is supported until at least November 12, 2024.
Also, you forgot to explain what the problem is with your code. There's nothing obviously wrong with it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a ASP .NET MVC project, inside controller, I call a simple WebAPI using WebClient
e.g.
WebClient client = new WebClient();
client.Headers.Add("cache-control", "no-cache");
client.Headers.Add("accept-encoding", "gzip, deflate");
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("Accept", "application/json");
client.Headers.Add("Authorization", "Basic xxxxxx");
var respond = client.UploadString(new Uri("https://xxxxxx/"), "POST", "xxxxxx");
there is an exception when call UploadString immediately with error
"The entry '*' has already been added." in webConfig.
If remove the line "<add address="*" maxconnection="500"/>" from webConfig, the
exception is gone. Same thing is also happen when using HttpClient and RestClient.
WebConfig
"...
<connectionManagement>
<add address="*" maxconnection="500"/>
</connectionManagement>
..."
Do anyone know why it happen? Why does WebClient attempt to add the entry to configuration
during runtime and cause the error?
BTW, I have fixed the problem by remove the line from WebConfig, and put it to program StartUp
e.g.
System.Net.ServicePointManager.DefaultConnectionLimit = 500;
|
|
|
|
|
It's likely that the configuration from a higher level already defines the * address. This could be in a config file from a parent application, or the machine-level config file.
The simplest option is to clear or remove the addresses before adding the new one:
<connectionManagement>
<remove address="*" />
<add address="*" maxconnection="500" />
</connectionManagement>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have dynamic data showing on a blazor page
@foreach (var item in DisplayList.OrderBy(i => i.CompanyId))
{
<tr>
<td style="width:300px; color:darkgreen;">@item.Company</td>
<td style="width:250px; color:blue;">@item.FunctionName</td>
<td style="width:250px;">@item.Identifier</td>
<td>@item.SkillsSet</td>
</tr>
}
In my code I do a if..contains..replace on the part item.SkillsSet.
This is a string.
What I'm trying to do is: when this string contains a value I want that value to be surrounded with the "mark" tag so that part is highlighted.
Like: Jo | Lisa | Me | John
But the result is not what I expect. It shows the names and the tag. It doesn't highlight the text
It shows:
Jo | Lisa | <mark>Me</mark> | John
What to do?
|
|
|
|
|
Try using the Html.Raw helper method to indicate that the string should not be HTML-encoded:
@Html.Raw(item.SkillsSet) NB: You'll need to make sure the rest of the string is properly HTML-encoded to ensure it displays correctly and to avoid the potential for a persisted cross-site scripting vulnerability.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
<appSettings>
<add key="FilePath" value="C:\Users\*****\Desktop\Plans_First.xlsx"/>
<add key="SheetName" value="LAVVAGGIO|MANUTENZIONE|Map"/>
<add key="SortColumnName" value="LAVVAGGI_VALUE|MANUTENZIONI_VALUE"/>
<add key="MapColumn" value="NAME|LAVVAGGI_RANK|MANUTENZIONI_RANK"/> <!--ID Column should be present by default-->
<add key="RankColumn" value="LAVVAGGI_RANK|MANUTENZIONI_RANK"/>
</appSettings>
private DataTable SortSheet(string FilePath, string SheetName, string SortColumnName,string RankColumn)
{
try
{
var fileName = FilePath;
if (!File.Exists(FilePath))
{
txtLogger.Text += FilePath + " File Not Found!!!" + Environment.NewLine;
MessageBox.Show(" File Not Found!!!");
new DataTable();
}
#region Reading excel file
var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;IMEX=0;HDR=YES;TypeGuessRows=0;ImportMixedTypes=Text\""; ;
DataSet ds = new DataSet();
using (var conn = new OleDbConnection(connectionString))
{
try
{
try
{
conn.Open();
}
catch (Exception ex1)
{
txtLogger.Text += " exception : " + ex1.StackTrace + Environment.NewLine;
MessageBox.Show("File is Open, Please close to proceed!!!");
new DataTable();
}
var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
DataRow[] dr = sheets.Select("[Table_name]= '" + SheetName.ToString() + "$'");
if (dr.Length == 0)
{
MessageBox.Show("SheetName Not Found!!!");
txtLogger.Text += SheetName.ToString() + " : SheetName Not Found!!!" + Environment.NewLine;
new DataTable();
}
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM [" + SheetName + "$] WHERE [ID] IS NOT NULL ";
var adapter = new OleDbDataAdapter(cmd);
adapter.Fill(ds);
}
}
catch (Exception ex)
{
txtLogger.Text += " exception : " + ex.StackTrace + Environment.NewLine;
MessageBox.Show("Error Occured ,Please check the log!!!");
new DataTable();
}
finally
{
conn.Close();
conn.Dispose();
}
}
#endregion
#region Sorting based on SortColumnName
DataTable dt = ds.Tables[0];
DataView view = dt.DefaultView;
view.Sort = SortColumnName + " ASC";
DataTable sortedData = view.ToTable();
if(sortedData.Columns.Contains(RankColumn))
{
int rank = 1;
foreach (DataRow row in sortedData.Rows)
{
row[RankColumn] = rank;
rank++;
}
}
txtLogger.Text += " Sort Completed : Sheet " + SheetName + Environment.NewLine;
return sortedData;
#endregion
}
catch (Exception)
{
throw;
}
}
private void InsertSheet(string FilePath, DataTable MapDatatable, string MapSheetName, List<string> updatedColumns)
{
try
{
var fileName = FilePath;
if (!File.Exists(FilePath))
{
txtLogger.Text += FilePath + " File Not Found!!!" + Environment.NewLine;
MessageBox.Show(" File Not Found!!!");
return;
}
var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;IMEX=0;HDR=YES;TypeGuessRows=0;ImportMixedTypes=Text\""; ;
#region Updating Excel
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
try
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.Connection = conn;
var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
int colcount = 0;
System.Type type;
foreach (DataRow row in MapDatatable.Rows)
{
colcount = 0;
StringBuilder commandString = new StringBuilder();
commandString.Append("UPDATE [" + MapSheetName.ToString() + "$"+"] SET ");
foreach (DataColumn c in MapDatatable.Columns)
{
if (updatedColumns.Contains(c.ColumnName))
{
commandString.Append(c.ColumnName);
type = row.ItemArray[colcount].GetType();
if ((type == typeof(string)) || (type == typeof(DateTime)))
{
commandString.Append(" = '").Append(row.ItemArray[colcount]).Append("' ,");
}
else if (row.ItemArray[colcount].ToString().Trim() == string.Empty)
{
commandString.Append(" = ' ").Append(row.ItemArray[colcount]).Append("' ,");
}
else
{
commandString.Append(" = ").Append(row.ItemArray[colcount]).Append(" ,");
}
}
colcount++;
}
commandString.Remove(commandString.Length - 1, 1);
commandString.Append(" where ID = " + row["ID"].ToString() + ";");
cmd.CommandText = commandString.ToString();
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
txtLogger.Text += " Update exception on Line : " + ex.StackTrace + ": Sheet " + MapSheetName+ Environment.NewLine;
MessageBox.Show("Error Occured ,Please check the log!!!");
return;
}
finally
{
conn.Close();
conn.Dispose();
}
}
#endregion
}
catch (Exception)
{
throw;
}
}
<pre>private void button1_Click(object sender, EventArgs e)
{
#region Full Event
try
{
txtLogger.Text = string.Empty;
string FilePath = System.Configuration.ConfigurationManager.AppSettings["FilePath"];
string SheetName = System.Configuration.ConfigurationManager.AppSettings["SheetName"];
string SortColumnName = System.Configuration.ConfigurationManager.AppSettings["SortColumnName"];
string MapColumn = System.Configuration.ConfigurationManager.AppSettings["MapColumn"];
string RankColumn = System.Configuration.ConfigurationManager.AppSettings["RankColumn"];
string[] Sheets = SheetName.Split('|');
string[] sortColumnName = SortColumnName.Split('|');
string[] mapColumn = MapColumn.Split('|');
string[] rankColumn = RankColumn.Split('|');
int colcount = 0;
List<string> updatedColumns = new List<string>();
foreach (var item in mapColumn)
{
updatedColumns.Add(mapColumn[colcount].ToString());
colcount++;
}
if(DateTime.Now.Year==2023)
{
MessageBox.Show("error");
return;
}
DataTable Sheet1, Sheet2 , Sheet3;
Sheet1 = SortSheet(FilePath, Sheets[0].ToString(), sortColumnName[0].ToString(),rankColumn[0].ToString());
Sheet2 = SortSheet(FilePath, Sheets[1].ToString(), sortColumnName[1].ToString(),rankColumn[1].ToString());
Sheet3 = SortSheet(FilePath, Sheets[2].ToString(), "ID", rankColumn[1].ToString());
if ((Sheet1.Rows.Count>0)&&(Sheet2.Rows.Count > 0))
{
if(!Sheet1.Columns.Contains(mapColumn[0].ToString()))
{
Sheet1.Columns.Add(mapColumn[0].ToString(), typeof(System.String));
foreach (DataRow row in Sheet1.Rows)
{
row[mapColumn[1].ToString()] = string.Empty;
}
}
if (!Sheet1.Columns.Contains(mapColumn[1].ToString()))
{
Sheet1.Columns.Add(mapColumn[1].ToString(), typeof(System.Int32));
foreach (DataRow row in Sheet1.Rows)
{
row[mapColumn[1].ToString()] = 0;
}
}
if (!Sheet1.Columns.Contains(mapColumn[2].ToString()))
{
Sheet1.Columns.Add(mapColumn[2].ToString(), typeof(System.Int32));
foreach (DataRow row in Sheet1.Rows)
{
row[mapColumn[2].ToString()] = 0;
}
}
}
Sheet1.AsEnumerable()
.Join(Sheet2.AsEnumerable(),
dt1_Row => dt1_Row.ItemArray[0],
dt2_Row => dt2_Row.ItemArray[0],
(dt1_Row, dt2_Row) => new { dt1_Row, dt2_Row })
.ToList()
.ForEach(o =>
o.dt1_Row.SetField(7, o.dt2_Row.ItemArray[6]));
InsertSheet(FilePath, Sheet1, Sheets[2].ToString(),updatedColumns);
MessageBox.Show(" Reschedule Completed!!!");
return;
}
catch (Exception ex)
{
txtLogger.Text += " exception : " + ex.StackTrace + Environment.NewLine;
MessageBox.Show("Error Occured ,Please check the log!!!");
return;
}
#endregion
}
modified 4-Oct-22 17:41pm.
|
|
|
|
|
A massive wall of unexplained code is not a question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So have I have a modal with a updatepanel and a repeater inside it. I have an open another modal on linkbutton click, I would like to update the 2nd modal with a checkboxlist, but the linkbutton click doesn't fire for me to update the 2nd modal data.
|
|
|
|