Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
EssOEss
Oct 23, 2006
128-bit approved

ModeSix posted:

The connectors are quite well done

ModeSix posted:

it won't store strings longer than 256 characters

This type of "oh it works great, except for the front falling off" attitude is something I see a lot in recent times with the new .NET and the .NET Core things. It boggles my mind how such mass hypnosis is possible.

Adbot
ADBOT LOVES YOU

darthbob88
Oct 13, 2011

YOSPOS

raminasi posted:

Maybe I'm misunderstanding, but that comparator smells wrong, specifically: using the one field for equality but not comparison. When you're implementing a comparator, equality is when an object is neither less than nor greater than another object; shortcuts via object identity can lead you off cliffs.
Yeah, but on the other hand I want the comparator to return equal if two objects are the same, not just if they have the same product. {x=4, y= 10} is not equal to {x=2, y=5}, even though x/y is the same for both. Plus, AFAIK GUIDs are useless for anything other than equality.

raminasi
Jan 25, 2005

a last drink with no ice

darthbob88 posted:

Yeah, but on the other hand I want the comparator to return equal if two objects are the same, not just if they have the same product. {x=4, y= 10} is not equal to {x=2, y=5}, even though x/y is the same for both. Plus, AFAIK GUIDs are useless for anything other than equality.

But you still need to provide some ordering of two objects with different GUIDs but the same product, and if you haven't thought about it specifically, your code might be doing something arbitrary, which could explain your problem.

jony neuemonic
Nov 13, 2009

EssOEss posted:

This type of "oh it works great, except for the front falling off" attitude is something I see a lot in recent times with the new .NET and the .NET Core things. It boggles my mind how such mass hypnosis is possible.

I've been willing to deal with churn and brokenness for a bit because untangling .NET from Windows and getting things like ASP.NET Core onto NuGet and out of the framework itself will be worth it in the long run. I expect things will start settling down after VS2017 and .NET Standard 2.0, if they don't then yeah probably time to reevaluate how much time I want to invest in this stuff.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

raminasi posted:

But you still need to provide some ordering of two objects with different GUIDs but the same product, and if you haven't thought about it specifically, your code might be doing something arbitrary, which could explain your problem.

Yes, having a non consistent sort could definitely have that sort of result.

darthbob88
Oct 13, 2011

YOSPOS

raminasi posted:

But you still need to provide some ordering of two objects with different GUIDs but the same product, and if you haven't thought about it specifically, your code might be doing something arbitrary, which could explain your problem.
I did think about it specifically, and it is doing something arbitrary. Can't fix it right now, but that probably is the issue. Thx.

Furism
Feb 21, 2006

Live long and headbang
Speaking of .NET Core, since ASP.NET upgraded to 1.1 it now takes 1 minute to build my project (when it only took seconds before). Some people on the corefx GitHub repo said they had the same, and removing the reference to the framework SDK in global.json fixed the problem, but not for me. Before I open an issue there and look stupid, does anybody have any suggestion as to how I could fix/investigate this?

EssOEss
Oct 23, 2006
128-bit approved
Use Process Monitor to find out what exactly is happening during that missing minute. It shows all the filesystem operations done by apps - while it may not be related to filesystem, getting an understanding of where the delay lies in the app's lifecycle can give useful hints to solving the problem.

ModeSix
Mar 14, 2009

EssOEss posted:

This type of "oh it works great, except for the front falling off" attitude is something I see a lot in recent times with the new .NET and the .NET Core things. It boggles my mind how such mass hypnosis is possible.

Your example is pretty heinous, however my issue could be that I am not implementing it correctly. I'm pretty new at using this ecosystem (maybe 3 months now) and still have a lot of learning to do. But what I've used is sure as poo poo a lot easier/better than the corresponding javascript framework answers (node.js/angular/react) for backend/frontend communication and authentication.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

EssOEss posted:

This type of "oh it works great, except for the front falling off" attitude is something I see a lot in recent times with the new .NET and the .NET Core things. It boggles my mind how such mass hypnosis is possible.

I admit I don't fully understand how this stuff all clicks together, but isn't the connector a responsibility of the MySQL folks? Surely it has nothing to do with the .NET team or .NET Core?

Furism
Feb 21, 2006

Live long and headbang
I've had problems with the MySQL connector myself when using .NET Core. Works fine on Linux but on Windows I get lots of issues (like connection pooling not working) so I just switched to pgSql for development (I'm going through an ORM so it doesn't make much difference to me at this point in the development process) and now it's all great.

ModeSix
Mar 14, 2009

The Wizard of Poz posted:

I admit I don't fully understand how this stuff all clicks together, but isn't the connector a responsibility of the MySQL folks? Surely it has nothing to do with the .NET team or .NET Core?

I'm pretty sure this is correct actually.

EssOEss
Oct 23, 2006
128-bit approved

The Wizard of Poz posted:

I admit I don't fully understand how this stuff all clicks together, but isn't the connector a responsibility of the MySQL folks? Surely it has nothing to do with the .NET team or .NET Core?

It's the attitude to accepting broken code as normal that I associate with .NET Core.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

ModeSix posted:

I use it (.net core only) with MySQL and Postgres. The connectors are quite well done and easy to implement, at least in my experience. Is there something I don't know that I should be aware of?

The only problem I've come across so far, using MySQL, is that for some reason it won't store strings longer than 256 characters, no matter what I try. I might need to submit a bug report to the maintainers of the mysql connector, because this is a big issue that I haven't successfully been able to solve thus far.

EF was built with SQL Server in mind, and afaik it's the only provider that's actually maintained by MS. The providers that communicate with other databases like Postgres or MySQL will work in 99% of cases (selects, wheres, etc.), but it's when you get into weird edge cases things can fall apart (special indexes, complicated aggregation queries, etc.).

The situation has likely gotten better since I last played with it. The main difference is that I have confidence that all EF features will work with SQL Server, but it's not guaranteed for other databases.

Furism
Feb 21, 2006

Live long and headbang
Now that you can get SQL Server for Linux I might just switch to that honestly. Is there any downside to use SQL Server vs MariaDB/PostgreSQL if you don't care whether or not the code is open source?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



EssOEss posted:

It's the attitude to accepting broken code as normal that I associate with .NET Core.

I kind of expect stuff to break when big changes happen, but I also see how it's pretty weird for official .Net libraries to have so many issues :shrug:

Calidus
Oct 31, 2011

Stand back I'm going to try science!
So I am reading up on .NET Core 1.0 and everything seems very positive when compared to ASP.NET Core 1.0 . Everything I am reading generally just views .NET Core as clearly better than ASP.NET Core 1.0. Maybe I am just paranoid but there has to be some downsides besides having to learn some new right?

http://www.mithunvp.com/difference-between-asp-net-mvc6-asp-net-mvc5/

https://infogr.am/difference_between_aspnet_mvc_5_and_aspnet_core_mvc_10

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Furism posted:

Now that you can get SQL Server for Linux I might just switch to that honestly. Is there any downside to use SQL Server vs MariaDB/PostgreSQL if you don't care whether or not the code is open source?

Does "don't care whether or not the code is open source" include paying potentially lots of cash for licenses?

Feature-wise, both MSSQL and Postgres have sexy features that the other one doesn't (say, temporal tables vs JSONB columns) but you might not be interested in either. Comparing major RDBMSs in general is an extremely complex affair, since they're practically heavy industrial machinery even if you happen to be using them for running trivial CRUD statements over tiny sub-GB databases. This could be a good place to start I guess? It's aimed at OLTP but I'm kind of assuming by default that that's what you're doing.

NihilCredo fucked around with this message at 21:31 on Dec 12, 2016

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

EssOEss posted:

It's the attitude to accepting broken code as normal that I associate with .NET Core.

Those people are everywhere, it has nothing to do with any specific language. Look at the poo poo PHP devs and JavaScript devs put up with.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!

Calidus posted:

Everything I am reading generally just views .NET Core as clearly better than ASP.NET Core 1.0.

Do you mean ASP.NET MVC 5 vs ASP.NET Core 1.0? ASP.NET Core 1.0 is a library that runs on .NET Core 1.0. If so, I think that ASP.NET Core is pretty much just better if you're starting a new web application; the big problem is just that it isn't compatible.

Calidus
Oct 31, 2011

Stand back I'm going to try science!

Asymmetrikon posted:

Do you mean ASP.NET MVC 5 vs ASP.NET Core 1.0? ASP.NET Core 1.0 is a library that runs on .NET Core 1.0. If so, I think that ASP.NET Core is pretty much just better if you're starting a new web application; the big problem is just that it isn't compatible.

Yes, they keep messing around the with names.

http://www.hanselman.com/blog/ASPNET5IsDeadIntroducingASPNETCore10AndNETCore10.aspx

Sab669
Sep 24, 2009

I've got an ASP / MVC web application.

In every single cshtml view, we us this pattern:

code:

<div id="someID>
    @using (Ajax.BeginForm("someID", "", new AjaxOptions() {HttpMethod = "Post"}, new {id = "frmSomeID"}))
    {
        @Html.AntiForgeryToken();

         //rest of the actual view
    }
</div>

It is always Post, never Get.

So basically everything it the application does will be done via a Post request, right? But what about if a JavaScript file contains a method which makes an AJAX request where the type is defined as Get?


Basically my concern is this: I'm learning to use a Code Analysis tool on our application and I've got hundreds of these warnings that say any given method in a controller is susceptible to a CSRF attack, and they recommend :

1) Add the [HttpGet] attribute to the method in question. OR...
2) Add both [HttpPost] and [ValidateAntiForgeryToken]


So my question is, if the form in the view is defined as post, does that matter for which attributes I apply to the controller's methods?


I'm not really sure what I should be doing. I suppose probably add the appropriate request-type attribute depending on what the type is in the actual ajax call in the JS? This is going to be a long, tedious next month if so. I've got thousands of these warnings from the Analyzer...

darthbob88
Oct 13, 2011

YOSPOS

darthbob88 posted:

I did think about it specifically, and it is doing something arbitrary. Can't fix it right now, but that probably is the issue. Thx.
Update: Fixed the comparator so it'd properly acknowledge two objects with the same product as "equal", and found another problem. SortedSets are still sets, so I can't add duplicate items, even if those items are only "duplicates" in that the comparator says they're equal. So I just added a line to the comparator to sort on timestamps and it seems to work fine now.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Sab669 posted:

I've got an ASP / MVC web application.

In every single cshtml view, we us this pattern:

code:

<div id="someID>
    @using (Ajax.BeginForm("someID", "", new AjaxOptions() {HttpMethod = "Post"}, new {id = "frmSomeID"}))
    {
        @Html.AntiForgeryToken();

         //rest of the actual view
    }
</div>

It is always Post, never Get.

So basically everything it the application does will be done via a Post request, right? But what about if a JavaScript file contains a method which makes an AJAX request where the type is defined as Get?


Basically my concern is this: I'm learning to use a Code Analysis tool on our application and I've got hundreds of these warnings that say any given method in a controller is susceptible to a CSRF attack, and they recommend :

1) Add the [HttpGet] attribute to the method in question. OR...
2) Add both [HttpPost] and [ValidateAntiForgeryToken]


So my question is, if the form in the view is defined as post, does that matter for which attributes I apply to the controller's methods?


I'm not really sure what I should be doing. I suppose probably add the appropriate request-type attribute depending on what the type is in the actual ajax call in the JS? This is going to be a long, tedious next month if so. I've got thousands of these warnings from the Analyzer...

Unless I'm misunderstanding the situation, you want [HttpGet] on the action that initially DISPLAYS the form. [HttpPost] and [ValidateAntiForgeryToken] go on the action that the form SUBMITS TO. Is that all you were after or have I misunderstood? Happy to clarify if I can.

Sab669
Sep 24, 2009

I think that's it. Suppose I'll just have to try it out and see if I run into any problems.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



You should also only POST to forms that modify data, so probably not a search form, for example. Not everyone thinks this, but some people just like to be wrong :)

Mr Shiny Pants
Nov 12, 2012

Munkeymon posted:

You should also only POST to forms that modify data, so probably not a search form, for example. Not everyone thinks this, but some people just like to be wrong :)

Whats the rationale behind this?

B-Nasty
May 25, 2005

Mr Shiny Pants posted:

Whats the rationale behind this?

It's certainly a debatable rule, and it would largely depend on how your search functions. That being said, the POST verb from a pure REST perspective is only used to create an item(s) and is not idempotent. A search would be idempotent and safe (can be replayed by the browser, e.g. 'Back/Forward'), so it should be a GET. Ideally, this would be reflected in the URL bar as well, so that one could bookmark or send a search to someone else.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



You can also hit refresh without the browser pestering you about form re-submission because POST is assumed to be unsafe and GET safe, as B-Nasty mentioned.

Mr Shiny Pants
Nov 12, 2012

B-Nasty posted:

It's certainly a debatable rule, and it would largely depend on how your search functions. That being said, the POST verb from a pure REST perspective is only used to create an item(s) and is not idempotent. A search would be idempotent and safe (can be replayed by the browser, e.g. 'Back/Forward'), so it should be a GET. Ideally, this would be reflected in the URL bar as well, so that one could bookmark or send a search to someone else.

Thanks, makes sense.

chippy
Aug 16, 2006

OK I DON'T GET IT
I keep seeing this piece making the rounds recently, lots of sites re-posting it.

http://www.yegor256.com/2016/12/13/mvc-vs-oop.html

I know this isn't strictly a .NET issue, but I was wondering what you guys make of it. I sort of see what he's getting at, but I don't think that using MVC necessarily stops you from applying good OOP principles. I like to build a well encapsulated core application and expose the behaviour of it to my controllers, rather than having the controllers manipulate the data directly. Keeping the controls thin and the domain model rich, basically. I think this dude's making the common mistake of thinking of the model as just the data, rather than all the behaviour and business logic too.

chippy fucked around with this message at 11:55 on Dec 16, 2016

john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.
The issue arises from people thinking that MV(C/VP) is a complete application architecture instead of just being an architecture for your UI layer.

SirViver
Oct 22, 2008

chippy posted:

I think this dude's making the common mistake of thinking of the model as just the data, rather than all the behaviour and business logic too.
:yeah:

Che Delilas
Nov 23, 2009
FREE TIBET WEED

chippy posted:

I think this dude's making the common mistake of thinking of the model as just the data, rather than all the behaviour and business logic too.

I don't really blame him for thinking this, either. Most official and unofficial tutorials and getting-started style examples put all the logic in the controller (because the logic is so simple) and the only thing that goes in the model is the database objects (often EF entities). They focus on explaining all the .NET-specific MVC stuff like where you configure routes and what all the Attributes do, and don't sufficiently emphasize or define what the Model should really be. It took me a while to clear that mental block.

Sab669
Sep 24, 2009

This is sort of a dumb question, but is there any consensus on whether or not you should always include a default case in a switch statement?

For example, in the following code would (should?) you add a default case?

code:

for (int i = 0; i < 4; i++)
{
    switch (i)
    {
        case 0:
            DoOneThing();
        case 1:
            DoAnotherThing();
        case 2:
            DoYetAnotherThing ();
        case 3:
             DoThisLastThing();
    }
}

We should never not hit one of our defined cases, so why bother?

Sab669 fucked around with this message at 17:59 on Dec 19, 2016

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Sab669 posted:

This is sort of a dumb question, but I'd there any consensus on whether or not you should always include a default case in a switch statement?

For example, in the following code would (should?) you add a default case?

code:
for (int i = 0; i < 4; i++)
{
    switch (i)
    {
        case 0:
            DoOneThing();
        case 1:
            DoAnotherThing();
        case 2:
            DoYetAnotherThing ();
        case 3:
             DoThisLastThing();
    }
}
We should never not hit one of our defined cases, so why bother?

I would include it just to ensure it throws a WhatTheFuckJustHappenedException. If someone makes it i < 5 and doesn't add a case for it, I'd rather immediately know than have it fall through.

EssOEss
Oct 23, 2006
128-bit approved
Right. The idea is not to do some "default action" that is supposed to make sense but to raise the alarm because some other part of the code was changed without the appropriate modification being done to the switch statement.

Sab669
Sep 24, 2009

Good point. Working my way through the thousands of items found by these static code analyzers and there were ~60 switches with no default.

I suggested to my boss simply just throwing an exception, if no "obvious" logic should be done, but I wasn't sure if there was any official MSDN guidelines or anything.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Not having a correct or expected value is an exceptional case, and I would much rather have that fail loudly than to silently misbehave.

Adbot
ADBOT LOVES YOU

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

chippy posted:

I think this dude's making the common mistake of thinking of the model as just the data, rather than all the behaviour and business logic too.

In MVC the model actually is just the data, but the thing he's missing is that for a proper application you would also have various services to handle business logic rather than lumping it all in the controller.


john donne posted:

The issue arises from people thinking that MV(C/VP) is a complete application architecture instead of just being an architecture for your UI layer.

This explains it better than I can. I usually even use two projects (or more). One that is just my MVC project and just has models, views and controllers, then I build services in a separate code library project (in the same solution) and reference it, and that's where all the business logic sits.

So a "create post" controller action might look something like:

code:
public class PostsController : Controller
{
    private readonly PostsService _postsService;

    public PostsController(PostsService postsService)
    {
        _postsService = postsService;
    }

    [HttpPost]
    public ActionResult Create(CreatePostViewModel viewModel)
    {
        // Turn the CreatePostViewModel into a compact dto to send to the PostsService
        _postsService.Create(createPostDto);
       
        // Return a success view or whatever.
    }
}
I should mention though that I've had to teach myself mostly by reading millions of articles across the web, so this might not be the bestest possible way of structuring things, but I've found it works well for our needs.

putin is a cunt fucked around with this message at 00:48 on Dec 21, 2016

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply