|
I get what you want to do here, which is to create models to match your database perhaps, so each table has a matching model. But your over thinking this, and don't need that much detail. Keep it simple and flexible at first, and only add detail when needed. For some reason Microsoft likes to capitalize the first letter, and will nag you later about the first letter being lower case.
This is an example model in c# to match a DB table or collection. Your example is a like a model used to present data in the view. Even when presenting data in the view, I would keep that simple as well. You want to craft models as simple as possible, and try to make them as reusable as possible to keep models down in count.
public class PORTFOLIOS
{
public string Id { get; set; }
public DateTime TimeStamp { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string CreatedBy { get; set; }
public string UpdatedBy { get; set; }
public DateTime UpdateDate { get; set; }
public string HTML { get; set; }
public string AvatarB64 { get; set; }
public string AvatarName { get; set; }
public string AvatarType { get; set; }
public string AvatarUrl { get; set; }
public int AvatarX { get; set; }
public int AvatarY { get; set; }
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hi,
I'm using ASP.NET Core 6. I'm trying to establish a local connection with SQL SERVER. The authentication method is Windows Auth. I used the following code in appsettings.json:
"ConnectionStrings": {
"AuthConnectionString": "Server=.;Database=AspNetAuth;Trusted_Connection=True"
}
And following code in program.cs:
builder.Services.AddDbContext<AuthDbContex>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString")));
builder.Services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<AuthDbContex>();
I created Migration, but when I try to update database, the following error is occured:
Quote: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
|
|
|
|
|
Are you sure that . is a valid server address?
|
|
|
|
|
In a SQL connection string, . resolves to the local computer.
You can even use it with a named instance - for example: server=.\SQLEXPRESS
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, not seen it used before.
|
|
|
|
|
|
|
|
I used app.UseAuthentication and the problem solved.
|
|
|
|
|
I am trying to allow my users to check if they have ActiveSync enabled for email and if they do return you are good to go, else tell them they need to complete a form. So a simple test I setup tried to start with a powershell.asp page containing:
<form action="doPowershell.asp" method="post">
Network Username: <input type="textbox" name="userName"/>
<input type="submit"/>
</form>
Then the resulting doPowershell.asp page I have for testing:
<%
Dim userName
userName = Request.Form("userName")
response.write(userName)
Server.Execute("activesync.ps1")
%>
the activesync.ps1 file contains
(Get-CASMailbox -Identity <username>).ActiveSyncEnabled
On the screen it outputs the value the user entered and then outputs the content of the ps1 file. Doesn't physically run anything. Thoughts?
Note: The current form doesn't really effect the PowerShell script. Just a shell I wrote to see if I could run it. The PS1 right now is just hardcoded with a physical username.
|
|
|
|
|
"Classic" ASP is ancient and obsolete. It's been effectively "dead" for 20 years now.
The Server.Execute method executes an ASP file. Since your PowerShell script doesn't contain any ASP code, it simply outputs the content of the file.
Update your application to use ASP.NET, and use the PowerShell class from the System.Management.Automation namespace[^] to execute your PowerShell script.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks. Are there any examples of this with say ASP.NET Web Core 6? I'm pulling out my hair trying to find anyone who did this with recent versions. Also would this still need to rely on a ps1 file or could the commands be loaded directly in code?
|
|
|
|
|
According to this SO thread[^], it's been supported since .NET Core 2.0 and Powershell v6. There's a sample application on GitHub[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I want to create a web application in my local server. All clients can connect to it through the local network. This server has a static IP and all related settings have been set for port forwarding, so we can access the server and my web application through Internet. I want to use SQLite system in my app.
Is it possible? Can users use data stored in SQLite at the same time?
modified 18-Nov-21 4:00am.
|
|
|
|
|
Assuming you mean SQLite:
SQLite works great as the database engine for most low to medium traffic websites (which is to say, most websites). The amount of web traffic that SQLite can handle depends on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound. SQLite has been demonstrated to work with 10 times that amount of traffic.
Note that writing to the database will lock the entire database file. Concurrent writes will not be supported.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi all. I'm using vb.net and have a custom templatefield in a datagrid:
<asp:CommandField
ShowEditButton="True" />
<ItemTemplate>
<asp:CheckBox ID="ckbIsCurrentAccount" runat="server" width="30px" checked='<%#Eval("IsCurrent").ToString()%>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="ckbIsCurrentAccountEdit" runat="server" width="30px" Checked='<%#DataBinder.Eval(Container.DataItem, "IsCurrent") %>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="ckbIsCurrentAccountFooter" runat="server" width="30px" checked="true"/>
</FooterTemplate>
</asp:TemplateField>
So when I click 'edit', it gives me the update/cancel options. When I click 'update', it says this checkbox is passing a null value and therefore throwing an error.
I have seen some answers involving the RowDataBound event and tried to adapt them to my scenario, however the same error keeps popping up. Is anyone able to help with this?
Thanks all.
|
|
|
|
|
I have a class which is using shell32.dll and a console exe program. It works well. Howeve, when I used the class with (shell32.dll) in IIS (dotnet Core 5), it doesn't work.
My question is the SHELL32.DLL allowed to be in the IIS?
If not, is there any other dll I can use?
Here is the Error message:
Quote: System.InvalidCastException
HResult=0x80004002
Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{286E6F1B-7113-4355-9562-96B7E9D64C54}' failed due to the following error: No such interface supported (0x80004002 (E_NOINTERFACE)).
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.CompilerServices.CastHelpers.ChkCastAny(Void* toTypeHnd, Object obj)
|
|
|
|
|
Shell32 requires an STA thread. ASP.NET doesn't use STA threads, which is why you're getting this error.
There is almost certainly another solution to the problem you're trying to solve. But since you haven't told us anything about it, we can't tell you what the solution is.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Here is the API in MVC controller:
public JsonResult GetMusicFiles()
{
List list = new();
FILE_PATH = @"D:\medias\musics";
list = Helpers.MediaMetaData.SingleDir(FILE_PATH);
foreach (ClassMediaMetaData d in list) {
Console.WriteLine(d.FullFileName);
}
return new JsonResult("Success!");
}
Here is the function in a class
class MediaMetaData
{
[STAThread]
public static List SingleDir(string folder)
{
return GetFilesSingleDir(folder);
}
private static List GetFilesSingleDir(String folder)
{
TimeSpan dur = TimeSpan.Zero;
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder objFolder = shell.NameSpace(folder);
List list = new();
list.Clear();
foreach (FolderItem2 item in objFolder.Items())
{
if (!item.IsFolder)
{
ClassMediaMetaData md = new ClassMediaMetaData();
dur = TimeSpan.FromSeconds(item.ExtendedProperty("System.Media.Duration") / 10000000);
md.Duration = dur.Duration();
md.FullFileName = item.Name;
md.FullPath = folder;
list.Add(md);
}
}
return list;
}
...
I am using VS2019 with DotNet CORE 5.0 to compile this.
When I used the class in a console application, it works fine. Therefore I know the code is working. The diff is one is console app and the other one is web or IIS.
Thanks.
|
|
|
|
|
As I said, it doesn't work in IIS because it's not running in an STA thread.
There are various suggested workarounds in this SO thread:
c# - Exception when using Shell32 to get File extended properties - Stack Overflow[^]
You can ignore the solution from Nikhil Chavan, since it doesn't apply to ASP.NET applications.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I did change my logic to use Thread per your link. However, the problem won't go away - still the same error.
|
|
|
|
|
Sorry, this site does not provide code to order.
|
|
|
|
|
Code? For what?
All you've done is spew some keywords that do not describe any project at all.
Frankly, this "question" is so bad, I think you're a test account for spam. Don't bother, it won't long here.
|
|
|
|
|
We have a login
If you type the username and password and press submit, we called the login.cs
everything is validate and OK,
but we have a password recovery link, where you have to type the username in order
to send you the email, in both case we called the same page: login, but we a parameter: <a href="login?expire=1" class="btn btn-ic btn-link pkg-photo">Olvide mi clave</a>
this is the function called:
if (Get<bool>("expire"))
{
if (!Empty(Username))
{
ExecuteRow("sp_sopv2_EnviarCorreoClave " + Username);
SuccessMessage = "Se a enviado un correo a su cuenta de email que tiene registrado con nosotros favor verificar.Una vez acceda a su cuenta debe cambiar su clave por seguridad";
}
else{
WarningMessage = "Favor de escribir el Usuario!";
}
}
the problem: the username field it passed with no value, only has value if you press submit
Here de login.cshtml:
<div class="box box-primary login-box ewLoginBox">
<div class="login-box-body">
<p class="login-box-msg">@Html.Raw(Language.Phrase("Login"))</p>
<div class="form-group">
<div><input type="text" name="username" id="username" class="form-control ewControl" value="@_login.Username" placeholder="@Language.Phrase("Username")" autocomplete="username"></div>
</div>
<div class="form-group">
<div><input type="password" name="password" id="password" class="form-control ewControl" placeholder="@Language.Phrase("Password")" autocomplete="current-password"></div>
</div>
<div class="checkbox">
<label for="rememberme"><input type="checkbox" name="type" id="rememberme" value="a" @Html.Raw((_login.LoginType == "a") ? " checked" : "")>@Html.Raw(Language.Phrase("RememberMe"))</label>
</div>
<button class="btn btn-primary btn-block ewButton" name="btnsubmit" id="btnsubmit" type="submit">@Html.Raw(Language.Phrase("Login"))</button>
@if (Config.Authentications.Count(kvp => kvp.Value.Enabled) > 0){
<div class="social-auth-links text-center">
<p>@Html.Raw(Language.Phrase("LoginOr"))</p>
@foreach (var kvp in Config.Authentications.Where(kvp => kvp.Value.Enabled)){
<a href="ExternalLogin?provider=@kvp.Key" class="btn btn-block btn-social btn-flat btn-@kvp.Key.ToLower()">class="fa fa-@kvp.Key.ToLower()">@Html.Raw(Language.Phrase("Login" + kvp.Key))</a>
}
</div>
}
<a href="login?expire=1" class="btn btn-ic btn-link pkg-photo">Olvide mi clave</a>
Here the login.cs
Username = "";
string password = "";
if (IsLoggingIn()) {
Username = Session.GetString(Config.SessionUserProfileUserName);
password = Session.GetString(Config.SessionUserProfilePassword);
LoginType = Session.GetString(Config.SessionUserProfileLoginType);
validPassword = Security.ValidateUser(ref Username, ref password, false);
if (validPassword) {
Session[Config.SessionUserProfileUserName] = "";
Session[Config.SessionUserProfilePassword] = "";
}
} else {
if (!Security.IsLoggedIn)
Security.AutoLogin();
Security.LoadUserLevel();
bool encrypted = false;
if (!Empty(Post("username"))) {
Username = RemoveXss(Post("username"));
password = RemoveXss(Post("password"));
LoginType = RemoveXss(Post("type"));
.
.
.
if (Get<bool>("expire"))
{
if (!Empty(Username))
{
ExecuteRow("sp_sopv2_EnviarCorreoClave " + Username);
SuccessMessage = "Se a enviado un correo a su cuenta de email que tiene registrado con nosotros favor verificar.Una vez acceda a su cuenta debe cambiar su clave por seguridad";
}
else{
WarningMessage = "Favor de escribir el Usuario!";
}
}
Any help.
|
|
|
|
|