Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Tuesday, November 27, 2018

ASP.NET MVC Mono

Settings at 11/2018

.Net Framework 4.5.2 using project properties
Mysql.Data.Entity using NuGet(6.10.8)

Setup Web.config

<!--Added--> 
<configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> 
<connectionStrings> 
  <add name="ferredb" connectionString="server=127.0.0.1;Port=3306;Database=ferre;Uid=root;Pwd=Microsoft;" providerName="MySql.Data.MySqlClient"/> </connectionStrings> 
<!--Added--> 
<entityFramework> 
<providers> 
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
  </provider> 
</providers> 
</entityFramework> 
<!--Added--> 
<system.data> 
<DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/> 
 </DbProviderFactories> 
</system.data>

Fix version of entry System.Web.Mvc.MvcWebRazorHostFactory at views/Web.config


Classes

//Ado
using System;
using System.Data.Entity;
using MySQLEntity.Models;

namespace MySQLEntity.Entity
{

public class MyDb : DbContext
{
public MyDb() : base("ferredb")
//public MyDb() : base(nameOrConnectionString: "ferredb")
{
}
public DbSet<Usuario> Usuarios { get; set; }
}


}


//Entity
using System;
//Added
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;


namespace MySQLEntity.Models
{
        [Table("Users")]
        public class Usuario
        {
            [Key]
            public string usuario { get; set; }
            public string apenom  { get; set; }
        }

}



Controller Snippet code

public ActionResult Index()
{
  MyDb db = new MyDb();
  var Model=db.Usuarios.ToList();
  return View(Model);
}

View Snippet code


@foreach (var item in Model)
{


<div> @item.usuario @item.apenom </div>
}

Action results
Types

References:
[1] MySQL EntityFramework web.config https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/
[2] Action results
https://www.c-sharpcorner.com/article/different-types-of-action-results-in-asp-net-mvc/
[3] ViewBag better than DataView http://www.tutorialsteacher.com/mvc/viewbag-in-asp.net-mvc


Friday, September 27, 2013

Asp.Net Insecure Session Cookie Handling Vulnerability

Add next code in c:\inetpub\wwwroot\web.config


    <system.web>
      <httpCookies
             httpOnlyCookies="true"
             requireSSL="true" />
    </system.web>


References:
[1] http://www.codeproject.com/Articles/291562/Asp-net-web-application-Security-Review-Dos-Dont
[2] http://forums.asp.net/t/1756774.aspx
[3] http://www.enterprisenetworkingplanet.com/netsecur/ten-tips-to-make-your-ssl-secure.html
[4] https://www.owasp.org/index.php/HttpOnly
[5] http://xss.cx/examples/dork/programming/ssl-cookie-without-secure-flag-set-example.html#1.7


IIS Custom Errors



1. Make html with custom message, and save that on any directory
    c:\inetpub\wwwroot\custom_errors\404.html
    c:\inetpub\wwwroot\custom_errors\500.html

2. Alter web.config of c:\inetpub\wwwroot, add next content.

<system.webServer> 
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL">
  <clear />
  <error statusCode="404" path="/custom_errors/404.html" responseMode="ExecuteURL" />
  <error statusCode="500" path="/custom_errors/500.html" responseMode="ExecuteURL" /> 
</httpErrors> 
</system.webServer> 



References:
[1] http://stackoverflow.com/questions/434272/iis7-overrides-customerrors-when-setting-response-statuscode
[2] http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404-in-asp-net-mvc
[3] http://stackoverflow.com/questions/717628/asp-net-mvc-404-error-handling

Firefox open multiple private window

    /opt/firefox/firefox-bin --profile $(mktemp -d) --private-window www.google.com www.bing.com