Note that there are some explanatory texts on larger screens.

plurals
  1. POSecurityException: Request failed. - Entity Framework Code First (Sql Compact 4)
    text
    copied!<ol> <li>I created an <strong>assembly (dll)</strong> with the following classes:</li> </ol> <p><strong>Person.cs</strong></p> <pre><code>[Table("People")] public class Person { [Key] public int ID { get; set; } public string Name { get; set; } } </code></pre> <p><strong>DataContext.cs</strong></p> <pre><code>public class DataContext : DbContext { public DbSet&lt;Person&gt; People { get; set; } public DataContext() : base("name=DataConnection") { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;(); base.OnModelCreating(modelBuilder); } } </code></pre> <p><strong>Calc.cs</strong></p> <pre><code>public class Calc { public int Sum(int num1, int num2) { return num1 + num2; } } </code></pre> <p>Using Nuget installed the following package:</p> <blockquote> <p>Install-Package EFCodeFirst.SqlServerCompact</p> </blockquote> <ol start="2"> <li>I created a new <strong>site MVC 3</strong></li> </ol> <p>I added the dll reference to previously created</p> <p>I modified the following actions on <code>HomeController</code></p> <p><strong>HomeController.cs</strong></p> <pre><code>public ActionResult Index() { ViewBag.Message = "Sample Security Error"; return View(); } public ActionResult Sum(int num1, int num2) { ViewBag.Message = "Sample Security Error"; return View("Index", num1 + num2); } </code></pre> <p>Added a new controller</p> <p><strong>PeopleController.cs</strong></p> <pre><code>public ActionResult Index() { using (var db = new DataContext()) { var people = from p in db.People select p; return View(people.ToList()); } } </code></pre> <p>I changed the <code>View/Home</code> with the following code:</p> <p><strong>Index.cshtml</strong></p> <pre><code>@model int? @{ ViewBag.Title = "Home Page"; } &lt;h2&gt;@ViewBag.Message&lt;/h2&gt; @Html.ActionLink("Sum", "Sum", new { num1 = 2, num2 = 4}) @if (Model.HasValue) { &lt;p&gt;The value is: @Model.Value&lt;/p&gt; } else { &lt;p&gt;No value&lt;/p&gt; } </code></pre> <p>New <code>View/People</code></p> <p><strong>Index.cshtml</strong></p> <pre><code>@model IEnumerable&lt;Error.SecurityException.Model.Person&gt; @{ ViewBag.Title = "People"; } &lt;h2&gt;@ViewBag.Title&lt;/h2&gt; &lt;ul&gt; @foreach (var item in Model) { &lt;li&gt;@item.Name&lt;/li&gt; } &lt;/ul&gt; </code></pre> <p><strong>In Web.config I added the connection string</strong></p> <pre><code>&lt;connectionStrings&gt; &lt;add name="DataConnection" connectionString="Data Source=|DataDirectory|Data.sdf;" providerName="System.Data.SqlServerCe.4.0" /&gt; &lt;/connectionStrings&gt; </code></pre> <p><code>App_Data</code> folder created the database <code>Data.sdf</code> with the same structure as the <code>Person.cs</code> class.</p> <p>Using Nuget installed the following package:</p> <blockquote> <p>Install-Package EFCodeFirst.SqlServerCompact</p> </blockquote> <p><strong>Result</strong></p> <p>The code in local IIS worked perfectly!</p> <p><strong>Sum values</strong></p> <p><img src="https://i.stack.imgur.com/JnFYo.png" alt="Sum value"></p> <p><strong>Display persons</strong></p> <p><img src="https://i.stack.imgur.com/96PBg.png" alt="Dados do Data.sdf"></p> <p><strong>Error</strong></p> <p>When I published the site, while trying to display the persons, a security error message is displayed;</p> <blockquote> <p>System.Security.SecurityException: Request failed.</p> </blockquote> <p>The sum values is normally done!</p> <p>I published the project <a href="http://teste.sextaigreja.com.br/" rel="nofollow noreferrer">this</a> address.</p> <p>Clicking the <code>People</code> menu you can see the error!</p> <p>Compact the sample project and published at <a href="http://teste.sextaigreja.com.br/Error.SecurityExeption.rar" rel="nofollow noreferrer">this address</a>.</p> <p>I appreciate the help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload