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
Sab669
Sep 24, 2009

Any of you guys happen to have any good resources for learning MS Composite Application block? I suppose it's kind of a long shot since it's so old, but figured I'd ask anyways.

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Any of you guys know what would be the easiest way to downgrade an MSBuild installation? Having some issues with a handful of scripts on my machine that work on a coworkers, my version of MSBuild is slight newer and we're pretty sure that's the issue.

Sab669
Sep 24, 2009

I've inherited a really, really sloppy application at work and I have done virtually no *real* web development to speak of. The application has an <asp:GridView> that gets its data source bound when the user clicks a Search button.

ViewEditProjects.aspx.cs:
code:
    private void Search()
    {
        DataSet dsGridView = new SqlDataAdapter();
        SqlConnection conn = new SqlConnection(myConnectionString);
        SqlDataAdapter daGridView = new SqlDataAdapter();

        daGridView = new SqlDataAdapter(mySQLstatement);
        daGridView.Fill(dsGridView);

        myGridView.DataSource = dsGridView
        myGridView.DataBind();
    }
ViewEditProjects.aspx:
code:
    <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="false"
         onpageindexchanging="myGridView_PageIndexChanging" >
    //bunch of columns manually written out
    <asp:BoundField DataField="myCol" HeaderText="myCol" SortExpression="myCol" />
    //more columns 
    </asp:GridView>
this 'myCol' BoundField can display 3 values: "Yes", "No", or "Select" (it's not a Mandatory field so whoever originally wrote this just writes Select to the DB). I'd just like to show an empty string in place of "Select" in the grid, is that possible?

I know BoundField has a NullDisplayText and DataFormatString property but I can't seem to achieve what I'm looking for with that.

Sab669
Sep 24, 2009

e; nevermind stupid type-o. Thanks Bognar :D

Sab669 fucked around with this message at 16:33 on Feb 20, 2015

Sab669
Sep 24, 2009

edit; never mind. Finally sort-of fixed it and it's good enough for now.

Sab669 fucked around with this message at 21:03 on Jun 11, 2015

Sab669
Sep 24, 2009

I have what I feel like is a dumb question, but me and my coworkers are all stumped as to what the gently caress is going on here.

I have an ASP page with 3 DataGrids on it.

The user enters some search parameters, clicks Search and it populates one Grid. The user single-selects a row (It has an ASP:radiobutton template column that gets databound to a unique ID) which postsback and populates the remaining two grids.

The remaining grids also have template columns, but with HTML checkbox input controls, which are also DataBound to a unique ID.

Based on their selection of data from these three grids, the application is supposed to display a value from one of the columns in a label on the page.

The problem I'm having is that the application saves the grids' data sources to an XML file / loads them back into the grid between postbacks, but the Checked state of the radio button / checkbox isn't being saved correctly- the field is always written as a 0 to the XML file for some reason. Even if I change it to a 1, when it gets loaded it still doesn't appear checked.

I think it has something to do with how the template columns are bound but I am so inexperienced with web dev I'm not fully sure what's going on. Anyone know if that's an actual problem / concern? Can't get to SA on my work computer so I can't really post code.

At this point I'm considering just rewriting this entire drat page, I have no idea who wrote it but it was so sloppy-- and that's coming from me, here. But even still I don't really know what's the best way to approach this to try and fix it.

Edit; should mention I tried using ASP: checkboxes but again I was having so many issues with how this page loads data that for some reason the checkboxes were behaving like radio buttons, or the UI simply wasn't reflecting their checked state at all.

Sab669 fucked around with this message at 20:10 on Jun 15, 2015

Sab669
Sep 24, 2009

http://stackoverflow.com/q/31457372/1189566

Anyone by chance able to explain this? :psyduck:

Sab669
Sep 24, 2009

biznatchio posted:

You're not messing with the Controls collection on the TabControl directly anywhere else in your code are you? Looking at the reference source for TabControl, it seems getting an item by index directly pulls from an internal list of TabPages, whereas removing by index simply removes from the Controls collection by index -- directly poking at the Controls collection would get those two collections out of sync with each other.

Removing an item by TabPage reference (as opposed to by index) calls the Controls.Remove overload with the object reference as well, which would explain why that works to remove the right page when RemoveAt wouldn't. It really sounds like an extra item is in your Controls collection.

The method that mkves tabs from Active / Archived takes two TabControls and an index. So this is most likely it.

TabPage tp = source.TabPages[index]
destination.TabPages.Add(tp)

is the jist of it. Sorry for no formatting, on mobile.

Sab669 fucked around with this message at 19:11 on Jul 16, 2015

Sab669
Sep 24, 2009

The Wizard of Poz posted:

One of my favourite ReSharper features that I think really needs to be in the base Visual Studio is the 'go to implementation'. When using DI it's basically a necessity, and I'm struggling without it.

This alone is worth paying for, IMO.

Wish I ever worked anywhere that used it :(

Sab669
Sep 24, 2009

I have an ASP page with a regular old HTML button on it. This button has its click event set dynamically based on the value of a hidden field. Basically it just calls 1 JavaScript method and passes a different parameter depending on that hidden field.

Is it possible to create a custom control that'd encase most of this logic for me?

I created a control which inherits from System.Web.UI.WebControls.Button, added a String member and a constructor that takes a String, which I assign to the private member.

In the ascx page I put a regular old HTML input button and copied over the logic that sets its click event and display text based on the private string defined in MyCustomButton.ascx.VB

On my actual page, I drop an instance of this button into the page and in the code behind I declare MyCustomButton1 / pass a String with the constructor.

When I run the application however, I just see a blank button with no text on it and it does nothing when clicked.

Not sure if I'm doing something wrong, or if this isn't really do-able.

Wasn't sure if the custom control needed to include the JavaScript files, or if it'd be able to call methods on it since the page in which the control is placed includes it too. But this did not make a difference.

Sab669
Sep 24, 2009

edit; never mind...

Sab669 fucked around with this message at 13:12 on Oct 14, 2015

Sab669
Sep 24, 2009

(sorry for formatting, posting from my phone)

Hey goons, I have an asp mvc-4 application that uses jquery to send an ajax request that passes a string back to the server which then is supposed to write that string to a file.

Problem is under certain conditions, the string is pretty long. 4 million characters or more. Once the request is sent, the server throws this error:

quote:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the steering exceeds the value set on the maxJsonLength property

This gets thrown by System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)

The breakpoint I've set in my controller's method I'm trying to invoke over ajax doesn't get triggered, the server is throwing this exception before MyController.SaveToFile() gets called.

I've Googled around and found a handful threads on StackOverflow citing this error, but the suggestions did not work for me.

I've tried adding <jsonSerialization maxJsonLength="2147483644" /> to my <system.web.extensions> node in the web.config, and I've also tried <add key="aspnet:MaxJsonSerializationMembers" value="2147483644" /> to the <appSettings> node.

I've tried with just one, then the other, they both.

Our application was recently just rewritten by some Indian company. Used to be a lovely VB ASP.net application which only used plain old vanilla JS and had only a vague sense of any sort of architectural foresight. Now it's a mediocre C# app that uses jquery, C#, and MVC. I say this because I noticed in the web.config there was this key: <add key="JSONMAXJSONLENGTH" value="2147483644" />. I tried removing this but it made no difference. I also googled for simply "asp.net key JSONMAXJSONLENGTH" and got a whopping 10 results -- 1 of which is a question I posted on SO the other day.

But yea. So I'm absolutely clueless as to why the internal serializer class isn't respecting my web.config value.

Anyone have any ideas? :(

Sab669 fucked around with this message at 13:45 on Oct 13, 2016

Sab669
Sep 24, 2009

Bognar posted:

Just to make sure, did you have it in this exact format?


Yea that's the format I used. Just a pain to type it all out on my phone :v:

quote:


If it's still not working, then you could cheat and just accept the json as a string parameter. Then you can deserialize it yourself instead of having MVC do it.


This might be a dumb question but how would I do that? I'm still pretty new to ajax, we just call $.ajax({ async, cache, data, dataType, type, url, contentType, traditional, headers, beforeSend, success, error, complete})

Where data is my multimillion character string, url is myController/SaveToFile, then beforeSend, success, error and complete are just a few functions that do the following: validate a token, perform some validation on the results, log the error, and do whatever is needed to the UI respectively.

data is initially just a single dimension array with 4 strings: "FileName", "FileNameValue.rtf", "RtfErrorList", "The four million character string to be written to the file"

We call JSON.stringify and pass this array. What we get back is sent as the data object in the ajax request.

Is this what you're saying I should change?

Sab669
Sep 24, 2009

Thanks for the explanation, I'll at least give it a shot.

SaveToFile actually returns void, it creates the file from the object passed it an argument and stores it in a session variable. The function defined by the success parameter just shows a pop-up for them to then save it.

So that should be fine, right? I guess I'd just need to change the type of the parameter and handle the parsing of the data myself.

Sab669 fucked around with this message at 17:05 on Oct 13, 2016

Sab669
Sep 24, 2009

Bognar posted:

Yeah that should work - return type doesn't have any effect on the parameter binding.

Well, with your route I no longer get the deserializer error, but the value passed to my controller is null.

In the JavaScript I can see the value contains what I expect, but get nothing on the other side.


I've tried adding processData: false as well as mimeType: "multipart/form-data" to the actual ajax message, and creating a FormData object in the JS to pass instead of just the stringified object like i was before: data = new FormData("myData", JSON.stringify(data));

No dice :(

Sab669
Sep 24, 2009

Just following up with my issues last week; I was able to figure it out and send the data using FormData; just needed change up how I was trying to access it on the server side. Thanks for the help Bognar!

Sab669
Sep 24, 2009

Have any of you guys used third-party code analysis tools? My boss has me trying to compare the analyzer built into Visual Studio versus things like HP Fortify / IBM Security AppScan

All I can find is businesses-speak marketing bullshit. Can't find any actual reviews that tell me what they offer over the VS tool.

Sab669
Sep 24, 2009

I'll check out Sonar, saw it mentioned a few times while trying to find anything to read in other tools. thanks.

Sab669
Sep 24, 2009

Edit: Disregard, our DBA is an overconfident fuckwit. Not a .NET problem.

Sab669 fucked around with this message at 22:06 on Nov 16, 2016

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...

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.

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

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.

Sab669
Sep 24, 2009

So last month I did basically nothing but dick around with an array of static code analyzers. Particularly looking for Security vulnerabilities in our flagship product.

Very few security issues were found, except for 1 rule which says methods which return a ActionResult object should be marked with [HttpGet], or in a select few cases it suggested [HttpPost].

Problem is, the analyzer doesn't take any consideration of how the javascript / cshtml is written and invokes any of these methods. So sometimes an ajax request gets sent as Post from 1 page but sent as a Get from another. So loving nothing works because such-and-such method doesn't exist when you try to do anything [because of the Http* attribute on it].

I have absolutely no idea what the gently caress to do :suicide: Trying to unravel this and correct it is going to take forever, and even then I have no idea if this will do gently caress all for the security of the application.

Sab669
Sep 24, 2009

The issue is that we paid some Indian firm to rewrite our entire application last year. It's pretty large. And it's basically just me that maintains it.

So I have no idea what they did. Not intimately familiar with ASP MVC, although I understand MVC principals. Third party controls I've never used before.A handful of custom controls that I have minimal understanding of how it was cobbled together. The entire application is all stitched together so that page virtually never fully reloads, it just makes Ajax calls and updates the HTML of one div. So since the URL in the address bar never changes I don't really get how / why anything should ever be sent as a Get request in our case.

Sab669
Sep 24, 2009

jony neuemonic posted:

Apologies if this is something you already have a handle on but, just for clarity: You know that AJAX calls can send GET or POST (or PUT or DELETE or whatever...) requests totally independently of what's in the URL bar yeah?

I do, yes, I just don't have any understanding of why the people who wrote it did things the way they did is all.

Sab669
Sep 24, 2009

You're absolutely right, and that's the problem. poo poo quality control and then a sole junior/mid level developer to maintain it :toot:

Sab669
Sep 24, 2009

Just reading up more on cross site request forgeries, I found an article on asp.net, as well as a few other random blogs, that talks about simply using @Html.AntiForgeryToken to prevent these types of attacks along with the [ValidateAntiForgeryToken] attribute. The code analyzer I used recommended the [HttpVerb] attributes as a solution.

I understand their purpose, so that a method can only be invoked by the designated request. But I'm not clear on how those attributes could really do much? Like hypothetically, say for some reason your Change Password page used a get request to update data... Whether it's attributed correctly or not, that's still kind of a giant security concern.

Are these attributes more of just a "good practice on top of other security / not poo poo code", or am I missing something? It seems like using the forgery token is more common / way loving easier. All of our views do make use of the antiforgery token, although searching the code for [ValidateAntiForgeryToken] yields exactly one result :v:

Sab669
Sep 24, 2009

Anyone able to recommend a library for working with HTML in C#?

My company has an old-rear end web forum which we are looking to replace. The problem is that it uses a proprietary Database, so we can't export threads/posts/users to the new system.

So I'm trying to write a scraper, essentially. Just something that will go and collect:

* Thread Title and author
* Messages within each thread and author

At least that way we can preserve some stuff.

I saved the HTML from 1 thread, then saved a copy which I ran through one of those "Pretty Print" utilities.

Trying to reinvent the wheel by just using File.ReadAllLines() combined with some logic which dictates where the actual thread contents begins and ends is pretty easy when working on a fine I ran through Pretty Print. But trying to deal with the "raw", unformated HTML is awful because you have 30 different things all crammed into 1 line.

I found this "HTML Agility Pack" but I'm not entirely sure it's what I want, but maybe I'm not using it correctly. No documentation :v:

Sab669 fucked around with this message at 21:27 on Jan 27, 2017

Sab669
Sep 24, 2009

Drastic Actions posted:

You want this. You can look at some of my Awful Forum Reader source code to get a feel for how it works, but basically it's loading the HTML, selecting the elements you want, and iterating over it, picking up individual elements and extracting data from it.

:toot: Got everything working this morning. I know it's not the most complex thing but that was actually a fun little project to work on... And more importantly, it was for a request from the CTO and annual reviews are coming up in a few weeks, so it's good to look good right now.

---
Editing my post so as not to double post:

Is there any reason, other than obvious resource consumption, why I shouldn't store a fairly large object in a session variable?

There's an uncommon bug in our software. If a user attempts to import data and it fails, they can view a report which explains why a specific record in their file failed to be imported. They can also download this report as a .rtf

99% of the time this all works fine. However, of they try to import an exceptionally large number of invalid records, they cannot download the report. I forget the exact exception it's throwing, but basically it's too big to be transmitted via JSON. I've scoured StackOverflow and none of the solutions for increasing JSON message size worked for me.

I was thinking of simply storing the report data in a session variable once it gets generated, then read it from the session of they try to download it.

I'm not certain which form of encoding this would be in, so I tried out these two lines:

code:

int uniSize = System.Text.ASCIIEncoding.Unicode.GetByteSize(someFiveMillionCharString);

int asciiSize = System.Text.ASCIIEncoding.ASCII.GetByteSize(someFiveMillionCharString);

Using a file provided by a client who actually reported this bug, uniSize has the value 10,622,964 and asciiSize has the value of 5,311,482.

So ya... Any reason I might want to avoid storing a 5-10MB string in a session variable?

Sab669 fucked around with this message at 15:30 on Feb 1, 2017

Sab669
Sep 24, 2009

This is purely speculation, but I assume it's probably because there are still a lot of old computers in use. So they just make it default to the behavior that will make your application run fine on x86 or x64.

But yes, I've definitely had my share of issues where I say, "Why the gently caress isn't this wor-- oh god drat it, wrong DLL"

Sab669
Sep 24, 2009

I'm not really sure how exactly to word this question, but there's a design decision that irritates the hell out of me with my company's code. Maybe it's also just a matter of personal preference.

It's laid out like this:

code:

public MyObject foo(MyObject myObj)
{
    MyBusinessObject mbo = new MyBusinessObject();

    myObj = mbo.SomeMethod(myObj);

    return myObj;
}

Then the business layer passes that whole object to the data layer, which uses a single property from the object to call a stored procedure l.

I suppose an argument could be made that "it's consistent"; you always pass in the whole object and get the whole thing back.

But when I'm debugging unfamiliar code and have an object with two or three dozen properties, it's annoying adding a watch for the whole object and having to expand it to figure out what single property got changed -- if anything at all. Or step into the methods manually and hunt it down.

I'm of the mindset that you should never pass more than is needed. If the method in the data layer is just passing the UserID to determine privileges or something, then I would write it so that the layers only accept and return that integer / string / whatever type and assign that value to myObj.SomeSpecificProperty.

Am I wrong? Is it common practice to 'expose' the entire object throughout the Controller / Business / Data layers?

I was working on those static code analyzer changes earlier this year, doing a lot of "code cleanup" now -- adding the XML comments for method descriptions / parameters / return types etc. and it's really annoying me now.

Also not to mention no use of static methods anywhere.

Sab669 fucked around with this message at 21:49 on Mar 10, 2017

Sab669
Sep 24, 2009

How can I get the EdgeHTML version from a Winforms application? It's a ClickOnce project and it uses a WebBrowser control.

For IE we've simply been checking a registry key but Edge doesn't keep that info in the registry.

I suggested having the site which hosts the ClickOnce project write a cookie to the user's machine and then try to check that from the Winforms application but I'm not sure if that'd work... And I'm not actually on the team trying to solve this so I can't really test anything myself.

The only relevant question I found on stackoverflow seemed to me like the person already knew the user agent string, but was having trouble "keeping track" of the value as they do things in the software.

Edit: Alternative idea I just had would be to create a process that tries to launch Edge and then immediately closes it. If that throws an exception then Edge probably isn't installed... But that seems like a really ghetto work around.

Sab669 fucked around with this message at 21:25 on Apr 19, 2017

Sab669
Sep 24, 2009

That would give me the version of Edge itself, rather than the actual renderer version, right?

Simply determining if Edge exists might work, I'll suggest it to the guy working on the project.

But I think ultimately they want to be able to get the specific EdgeHTML version so that way, hypothetically, if a user has a newer version of Edge but using the older renderer engine then we could tell them to go update it.

Sab669
Sep 24, 2009

Edit: I figured it out. Didn't realize you can use the Matrix view to cherry pick individual classes to graph. :krad:

Sab669 fucked around with this message at 16:20 on May 12, 2017

Sab669
Sep 24, 2009

Dumb Question: What exactly does Microsoft's Reference Source site show me?

I wanted to do some research for a question on stack overflow pertaining to an issue with the ZipArchive object, which exists in System.IO.Compression as stated here: https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive(v=vs.110).aspx


If I pull up the online source reference: https://referencesource.microsoft.com/#q=ZipArchive

And search for "ZipArchive" I get one Class result with a different namespace and different members. Like MSDN lists a constructor which takes a Stream object but the Source site does not define any constructors, for example.

Clearly I must be misunderstanding something, but I don't know what. I very rarely use the online source reference so I'm not very familiar with it.

Where (if at all) can I find the source code for the object as defined on MSDN?

Sab669
Sep 24, 2009

I did see that but I didn't think it was the same thing. The constructor defined on MSDN I'm referring to only takes 1 parameter, whereas that defines 4.

So if you were to write:

var x = new ZipArchive(myStreamObj)

I don't really understand how that would end up calling the static OpenOnStream method. There's also a definition for private ZipArchive() which takes the same 4 args plus an additional bool.

But ok, then where is the implementation for the Entries property or CreateEntry method?

If internal static ZipArchive OpenOnStream is a constructor, then what is private ZipArchive? Why does the former include a return type as well as the name whereas the later only has the return type?

The private ZipArchive method is what I'm "used to" for a constructor; you give it a scope and it returns an instance of itself. Why does the former have scope, return type and a name if it's a constrictor?

Sab669 fucked around with this message at 17:44 on Jun 1, 2017

Sab669
Sep 24, 2009

Edit; never mind...

Sab669 fucked around with this message at 21:06 on Jun 19, 2017

Sab669
Sep 24, 2009

Do any of you guys use Visual SVN's sever tool? My boss asked me to look into it as we're upgrading all of our servers, but I've never managed a version control sever so I don't really have anything to compare its features to :shrug:

Reviews seem well and good, but we're a small company with 5 programmers supporting 3 main products so I don't know if any of it really matters to us.

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Edit, never mind

Sab669 fucked around with this message at 18:55 on Mar 30, 2018

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