 |
|
ปรึกษาการเก็บค่าไว้ในตัวแปร หรือโมเดลที่ไม่ถูกเคลียร์ทิ้ง |
|
 |
|
|
 |
 |
|
ใช้ Session น่าจะตอบโจทย์ได้
Code (C#)
public void ConfigureServices(IServiceCollection services)
{
//In-Memory
//services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(90);
});
Code (C#)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseSession();
ตัวอย่างการใช้งาน
Code (C#)
public IActionResult Index()
{
HttpContext.Session.SetString("isLogin", "false");
if (!IsLogin() || !User.Identity.IsAuthenticated)
{
return RedirectToAction("Login"); //Fixed url not change. http://localhost:6969/Account/Login
}
return View();
}
|
 |
 |
 |
 |
Date :
2019-07-11 09:54:38 |
By :
xxx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริงฯแล้วผมก้ไม่เข้าใจ MVC อย่างถ่องแท้ มีหลายฯท่าน ณ.ที่นี้สามารถอธิบายความสงสัยได้ แต่ผมก็ไม่กล้าถาม
ตามที่ผมเข้าใจ C ไม่มีความหมาย/ความสำคัญอะไรเลย
|
 |
 |
 |
 |
Date :
2019-07-11 10:01:45 |
By :
xxx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมถามอาจารย์ของผมท่านบอกว่า
Code (C#)
return View();
สำคัญมากที่สุด (ผมก็ยังงงงงงง) บอกใบ้แต่เพียงว่า มันคือสะพาน และมันไม่ยึดติด
ผมก็มึนตึ๊บ
|
 |
 |
 |
 |
Date :
2019-07-11 10:11:12 |
By :
xxx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลืมตัวอย่าง isLogin
และผมไม่จำเป็นต้องใช้ ASP.NETCORE Identity
Code (C#)
private bool IsLogin()
{
bool result = false;
if (HttpContext.Session.GetString("isLogin") != null)
{
if (HttpContext.Session.GetString("isLogin") == "true")
{
result = true;
}
}
return result;
}
|
 |
 |
 |
 |
Date :
2019-07-11 10:20:28 |
By :
xxx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เท่าที่ผมจับประเด็นได้ MVC ทุกฯตัวไม่มีความสำคัญอะไรเลย และมันถูกใช้งาน
ณ. ที่เดียวนั่นก็คือ _Layout.cshtml
MVC ไม่ได้ถูกใช้งานที่อื่นฯเลย ผมก็ยังงงงงงง
แต่สักพักหนึ่งผมน่าจะเข้าใจ
|
 |
 |
 |
 |
Date :
2019-07-11 10:26:16 |
By :
xxx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูเหมือนว่าเขาจะใช้ตรงนี้เป็นหลัก
Code (C#)
@RenderSection("Scripts", required: false)
</body>
</html>
มองแบบง่ายฯเลยก็คือ require(...)
Code (JavaScript)
//node version : 10.15.3
const mqtt = require('mqtt'); //Hacks It's
const os = require('os');
const fs = require('fs-extra');
const file = 'logfile.txt'; //root path (NodeJS/logfile.txt)
const Fileoptions = { flag: 'a' };
const options = {
port: 6969,
host: 'mqtt://123.456.789.0',
clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
username: 'mymqtt',
password: 'mqttwise',
keepalive: 60,
reconnectPeriod: 1000,
protocolId: 'MQIsdp',
protocolVersion: 5,
clean: true,
encoding: 'utf8'
};
const client = mqtt.connect('mqtt://123.456.789.0'', options);
client.on('connect', function () { // When connected
// subscribe to a topic
client.subscribe('wise/data', function () {
// when a message arrives, do something with it
client.on('message', function (topic, message, packet) {
console.log("Received '" + message + "' on '" + topic + "'");
writeToFile(message);
});
});
});
async function writeToFile(text) {
await fs.outputFile(file, `${text}${os.EOL}`, Fileoptions);
}
|
 |
 |
 |
 |
Date :
2019-07-11 10:37:54 |
By :
xxx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|