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
Calidus
Oct 31, 2011

Stand back I'm going to try science!
Is there a good resource for using json, ajax and js with MVC and .Net? I have been doing some MVC development off and on but it was mostly bootstrap html/css for the views and c# on the back end. I feel kind stupid when i come across simple stuff like using json and an ajax get for cascading combo-boxes which would have made my life so much easier months ago. Ajax partial page post backs were also a eye opener. There has to be a resource with more stuff like this.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Calidus posted:

Is there a good resource for using json, ajax and js with MVC and .Net? I have been doing some MVC development off and on but it was mostly bootstrap html/css for the views and c# on the back end. I feel kind stupid when i come across simple stuff like using json and an ajax get for cascading combo-boxes which would have made my life so much easier months ago. Ajax partial page post backs were also a eye opener. There has to be a resource with more stuff like this.

My experience lately has been that the industry is moving away from ASP .NET MVC and more toward single-page applications using frameworks like angular or knockout, because "front end" is becoming its own sub-discipline with its own specialized developers and toolchain. I talk to a lot of different companies, and nearly every one working on a greenfield project is using angular/web API.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Calidus posted:

Is there a good resource for using json, ajax and js with MVC and .Net? I have been doing some MVC development off and on but it was mostly bootstrap html/css for the views and c# on the back end. I feel kind stupid when i come across simple stuff like using json and an ajax get for cascading combo-boxes which would have made my life so much easier months ago. Ajax partial page post backs were also a eye opener. There has to be a resource with more stuff like this.

JSON, AJAX, and JS are going to be the same regardless of your backend technology. With ASP.NET, the easiest (and recommended) way to handle JSON is to use Web API. There are some decent tutorials on the ASP.NET website that will get you started.

Chill Callahan
Nov 14, 2012
Does anybody have a way to test if a remote private MSMQ exists that I have minimal permission to (usually just peek). This code BSODs machines if I try and run it. I've tried multiple machines and multiple remote queues.

code:
        private void TestMsmq()
        {
            var queue = new MessageQueue(@"FormatName:Direct=OS:<machine-name>\private$\<queue-name>", QueueAccessMode.Peek);
            try
            {
                queue.PeekCompleted += MessageQueue_PeekCompleted;
                queue.BeginPeek(new TimeSpan(0, 0, 1));
            }
            catch(Exception e)
            {
                MsmqOk = false;
            }
        }

        private void MessageQueue_PeekCompleted(object sender, PeekCompletedEventArgs e)
        {
            MsmqOk = true;
        }

zerofunk
Apr 24, 2004

Chill Callahan posted:

Does anybody have a way to test if a remote private MSMQ exists that I have minimal permission to (usually just peek). This code BSODs machines if I try and run it. I've tried multiple machines and multiple remote queues.

Have you already tried just using MessageQueue.Exists()? I don't have much MSMQ experience, but everything I've done so far has used that to check for existence of a queue before creating it. Seems weird that you're a BSOD though.

Chill Callahan
Nov 14, 2012

zerofunk posted:

Have you already tried just using MessageQueue.Exists()? I don't have much MSMQ experience, but everything I've done so far has used that to check for existence of a queue before creating it. Seems weird that you're a BSOD though.

Unfortunately the MSDN documentation says that specifically doesn't work on remote private queues.

quote:

Exists(String) cannot be called to verify the existence of a remote private queue.

E: I found the method GetPrivateQueuesByMachine("<machine-name">) which works. It correctly gets the queues and I can print out the queue names, but if I try and inspect a queue in VS then it BSODs my machine with ATTEMPTED EXECUTE OF NOEXECUTE MEMORY. Nonetheless I got what I needed, but it's still odd.

Chill Callahan fucked around with this message at 16:57 on Mar 12, 2015

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
So I was tasked with updating MonkeyWrench (A mono based build server) with support for Google Oauth2. Currently it uses OpenID, and since Google is getting rid of support for it (and because we auth with Google for our business accounts) they want to switch.

Now, here are the problems with doing that. If you look through their source code, you can see that this:

  • Is a Webforms project. :cry:
  • Contains forked versions of ServiceStack and Json.NET. (The fork of ServiceStack only has the OpenID parts.)
  • Is based on .NET 4.0.
  • Is a goddamn mess.

We can't use the built in user account system, because it stores passwords in plain text. So we need to add something. We plan on leaving MonkeyWrench, so they don't want an "elegant" solution, Just something to use as a stopgap we can get off of it. But I'm not sure where to start, and no one else seems to have any ideas. If I want, I can retarget the app to a higher version of .Net, and I can use Nuget. But then I need to make sure I don't break any other part of the app in the process. :suicide:.

I'm tempted to just add a salt/hash to the password field and call it a day. Anyone have any ideas?

xgalaxy
Jan 27, 2004
i write code
Hey,

Can any one point me to some useful articles on how to properly implement certificate pinning with HttpWebRequest?
The application will distribute some pinset data with the application but I would also like to allow adding additional pinning data through a trusted url.

My particular hangups are there seems to be a couple of different api hooks where you are able to validate a certificate and I'm wondering which ones I need to implement or all of them or what?
The api hooks I'm talking about are:
- ICertificatePolicy.CheckValidationResult
- HttpWebRequest.ServerCertificateValidationCallback
- HttpWebRequest.ServicePoint.ServerCertificateValidationCallback
- HttpWebRequest.ServicePoint.Certificate
- HttpWebRequest.ServicePoint.ClientCertificate

What is the difference between these?

xgalaxy fucked around with this message at 20:09 on Mar 12, 2015

Mr Shiny Pants
Nov 12, 2012

Drastic Actions posted:

So I was tasked with updating MonkeyWrench (A mono based build server) with support for Google Oauth2. Currently it uses OpenID, and since Google is getting rid of support for it (and because we auth with Google for our business accounts) they want to switch.

Now, here are the problems with doing that. If you look through their source code, you can see that this:

  • Is a Webforms project. :cry:
  • Contains forked versions of ServiceStack and Json.NET. (The fork of ServiceStack only has the OpenID parts.)
  • Is based on .NET 4.0.
  • Is a goddamn mess.

We can't use the built in user account system, because it stores passwords in plain text. So we need to add something. We plan on leaving MonkeyWrench, so they don't want an "elegant" solution, Just something to use as a stopgap we can get off of it. But I'm not sure where to start, and no one else seems to have any ideas. If I want, I can retarget the app to a higher version of .Net, and I can use Nuget. But then I need to make sure I don't break any other part of the app in the process. :suicide:.

I'm tempted to just add a salt/hash to the password field and call it a day. Anyone have any ideas?

Time to do your username proud! :haw:

epswing
Nov 4, 2003

Soiled Meat

quote:

// TODO: Encrypt passwords somehow, not store as plaintext.

As least they're aware of their own silliness.

zerofunk
Apr 24, 2004

Chill Callahan posted:

Unfortunately the MSDN documentation says that specifically doesn't work on remote private queues.

Ahh, sorry. Didn't check the documentation. I've only been working with local queues myself, so that hasn't been an issue. I can't even remember the last time I saw a BSOD. I might try testing that out tomorrow. I'll need to work with remote queues at some point soon although probably not private ones.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Drastic Actions posted:

I'm tempted to just add a salt/hash to the password field and call it a day. Anyone have any ideas?

Abandon ship. You're already planning on leaving it... don't even try to enhance it. Your time would be better served getting a new build environment running and migrating off of that shitheap.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

epalm posted:

As least they're aware of their own silliness.

It also tells you when you're making an account that the passwords are stored in plain text. But it's not that hard to put basic encryption in there, and the fact it's been like this for years... :(

EDIT:

Ithaqua posted:

Abandon ship. You're already planning on leaving it... don't even try to enhance it. Your time would be better served getting a new build environment running and migrating off of that shitheap.

Now if you can convince Miguel de Icaza of this, that would be awesome. It has been a few days of banging my head against a wall of all the issues I have to overcome to somehow hack Oauth2 into something that won't support it without breaking everything else. I got a meeting with my boss tomorrow, so I'm gonna have to say I just can't do it. Not in any sane way. They got a month to get their poo poo over to another build system (I think they're going with Jenkins), so they'll live with plain text passwords.

Drastic Actions fucked around with this message at 22:02 on Mar 12, 2015

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

JSON, AJAX, and JS are going to be the same regardless of your backend technology. With ASP.NET, the easiest (and recommended) way to handle JSON is to use Web API. There are some decent tutorials on the ASP.NET website that will get you started.

MVC has like, a whole suite of Ajax helpers, I think. But yeah, I've been using Angular on new projects too.

Mr Shiny Pants
Nov 12, 2012
Another MVVM question:

I have my View and View Model setup. With help from you guys my NotifyPropertyChanged is working like it should and commands work as they should. My XAML is binded dynamically and I have almost no code in the code behind files.

So far so good you would say, but I have a hard time with the following:

Now where does the model come into play? I have a big class that represents my model data. It is a hierarchical structure of data that represents one work item in our business.

The ViewModel has extraneous properties like currently selected item and the like, this is not "business data" so I get why business data is stored in the model.

But how do I update the model and make the viewmodel aware of the changes? Do I need to make InotifyPropertyChanged properties on the model?

This would just make the ViewModel a proxy for the model without the extraneous properties? It feels like DB -> DAL -> DTO -> ViewModel all over again :( Unpacking classes and repacking them again.

This does not seem right to me. Is there something I am missing?

Mr Shiny Pants fucked around with this message at 09:07 on Mar 13, 2015

ninjeff
Jan 19, 2004

Mr Shiny Pants posted:

Another MVVM question:

I have my View and View Model setup. With help from you guys my NotifyPropertyChanged is working like it should and commands work as they should. My XAML is binded dynamically and I have almost no code in the code behind files.

So far so good you would say, but I have a hard time with the following:

Now where does the model come into play? I have a big class that represents my model data. It is a hierarchical structure of data that represents one work item in our business.

The 'model' in MVVM generally isn't a specific object as such, it's just the rest of your program not related to dealing with WPF.

Mr Shiny Pants posted:

The ViewModel has extraneous properties like currently selected item and the like, this is not "business data" so I get why business data is stored in the model.

But how do I update the model and make the viewmodel aware of the changes? Do I need to make InotifyPropertyChanged properties on the model?

This would just make the ViewModel a proxy for the model without the extraneous properties? It feels like DB -> DAL -> DTO -> ViewModel all over again :( Unpacking classes and repacking them again.

This does not seem right to me. Is there something I am missing?

In my experience the viewmodel is what's telling the model to change (in response to viewmodel property changes, commands, etc.), so it can update itself according to the results of the model changes. If this ends up making your viewmodels too complex then you can introduce controller classes to coordinate between the model and viewmodel, making a kind of MVCVM.

Mr Shiny Pants
Nov 12, 2012

ninjeff posted:

In my experience the viewmodel is what's telling the model to change (in response to viewmodel property changes, commands, etc.), so it can update itself according to the results of the model changes. If this ends up making your viewmodels too complex then you can introduce controller classes to coordinate between the model and viewmodel, making a kind of MVCVM.

This sounds reasonable. Thanks.

chippy
Aug 16, 2006

OK I DON'T GET IT
Does anyone know--- if you call a method that does ADO.NET stuff, from inside a 'using x as TransactionScope' block, does the stuff in the called method get done within the transaction scope too?

e: Looks like yes.

chippy fucked around with this message at 10:35 on Mar 13, 2015

Boz0r
Sep 7, 2006
The Rocketship in action.
How do I learn .NET as fast as possible? I have a job interview next week :D

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Boz0r posted:

How do I learn .NET as fast as possible? I have a job interview next week :D

Write some code. It would also help if you specified a language -- the advice for someone learning F# or PowerShell is going to be a lot different than if you're learning C#. .NET is just a framework, there are a ton of languages built on top of it.

Boz0r
Sep 7, 2006
The Rocketship in action.
I think it's going to be C#.

Dietrich
Sep 11, 2001

Boz0r posted:

I think it's going to be C#.

There really isn't a way to learn the entire .net framework in a week. Do you know Java at least?

Boz0r
Sep 7, 2006
The Rocketship in action.
Yeah. I know C# too from programming in Unity3D. I'm just got my master's in computer science, so I'm into all that OOP and poo poo, so I just need a quick and dirty version, I think.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Boz0r posted:

I think it's going to be C#.

What are you doing with it though? Web development? WinForms? WPF? WinRT?

Dietrich
Sep 11, 2001

I would check out the content at http://www.microsoftvirtualacademy.com/ to at least start getting your feet wet.

Boz0r
Sep 7, 2006
The Rocketship in action.

Drastic Actions posted:

What are you doing with it though? Web development? WinForms? WPF? WinRT?

I think it's going to be web service, WinForm and WPF.

Dietrich posted:

I would check out the content at http://www.microsoftvirtualacademy.com/ to at least start getting your feet wet.

I watched a video there but I found the hosts unbearable. Maybe I should give it another shot, though.

Dietrich
Sep 11, 2001

Boz0r posted:

I think it's going to be web service, WinForm and WPF.


I watched a video there but I found the hosts unbearable. Maybe I should give it another shot, though.

Oh, the hosts are terrible. Content is good though.

epswing
Nov 4, 2003

Soiled Meat
My ASP.NET/razor app lets users save and display messages. When a user saves a message, it contains newlines (the input is a multi-line textarea). When I want to display the message, I want to replace "\n" with "<br/>" so the message shows newlines (breaks) in html. But I don't want the whole message to be raw html, because I don't want users to save messages with iframes/divs/spans/etc.

How do I partially html-ify a string?

Edit: I guess I can split the string on "\n" and join it back together again in html pieces.

"Hello\nWorld" => <span>Hello</span><br /><span>World</span>

epswing fucked around with this message at 16:17 on Mar 13, 2015

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

epalm posted:

My ASP.NET/razor app lets users save and display messages. When a user saves a message, it contains newlines (the input is a multi-line textarea). When I want to display the message, I want to replace "\n" with "<br/>" so the message shows newlines (breaks) in html. But I don't want the whole message to be raw html, because I don't want users to save messages with iframes/divs/spans/etc.

How do I partially html-ify a string?

Is storing it as Markdown an option?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

epalm posted:

My ASP.NET/razor app lets users save and display messages. When a user saves a message, it contains newlines (the input is a multi-line textarea). When I want to display the message, I want to replace "\n" with "<br/>" so the message shows newlines (breaks) in html. But I don't want the whole message to be raw html, because I don't want users to save messages with iframes/divs/spans/etc.

How do I partially html-ify a string?

Edit: I guess I can split the string on "\n" and join it back together again in html pieces.

"Hello\nWorld" => <span>Hello</span><br /><span>World</span>

You could use the white-space CSS property: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space. You probably want pre, pre-line, or pre-wrap.

Bognar fucked around with this message at 16:36 on Mar 13, 2015

epswing
Nov 4, 2003

Soiled Meat

Dr. Poz posted:

Is storing it as Markdown an option?

This is probably The Right Thing To Do (tm).

Bognar posted:

You could use the white-space CSS property: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space. You probably want pre, pre-line, or pre-wrap.

404! E: Oh it's just the period at the end.

This works in the interim:
code:
@helper NewlineToBreak(string s)
{
    foreach (var fragment in s.Split(new char[] { '\n' }))
    {
        <span>@fragment</span>
        <br/>
    }
}

Munkeymon
Aug 14, 2003

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



You could also just squirt the string into a https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code

GoodCleanFun
Jan 28, 2004

Mr Shiny Pants posted:

Another MVVM question:

I have my View and View Model setup. With help from you guys my NotifyPropertyChanged is working like it should and commands work as they should. My XAML is binded dynamically and I have almost no code in the code behind files.

So far so good you would say, but I have a hard time with the following:

Now where does the model come into play? I have a big class that represents my model data. It is a hierarchical structure of data that represents one work item in our business.

The ViewModel has extraneous properties like currently selected item and the like, this is not "business data" so I get why business data is stored in the model.

But how do I update the model and make the viewmodel aware of the changes? Do I need to make InotifyPropertyChanged properties on the model?

This would just make the ViewModel a proxy for the model without the extraneous properties? It feels like DB -> DAL -> DTO -> ViewModel all over again :( Unpacking classes and repacking them again.

This does not seem right to me. Is there something I am missing?

If you implement IDataErrorInfo on your viewModel, you can instance your model in your viewModel and then in your validation handling of your viewModel you would set your models properties after doing UI validation. If you want to do further business validation on your model, you can implement IDateErrorInfo on your model and then make a call to that validation after your UI validation completes.

Straight forward example from the champ himself:
https://joshsmithonwpf.wordpress.com/2008/11/14/using-a-viewmodel-to-provide-meaningful-validation-error-messages/

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Boz0r posted:

Yeah. I know C# too from programming in Unity3D. I'm just got my master's in computer science, so I'm into all that OOP and poo poo, so I just need a quick and dirty version, I think.

If you know programming but want to learn what makes C# standout I suggest C# In Depth. It goes over all of the changes in .NET 2/3/4/4.5 (generics, LINQ, async/await) which is what makes .NET standout from Java/C++. It also goes into a lot of the things that can be odd unless someone told out like LINQ being lazy evaluated. As far as learning WinForms, WCF, WebForms, MVC, Web API, etc. you are screwed but the employer knows that.

Also, the Microsoft Virtual Academy has some hit or miss classes. I wouldn't dismiss all of them if you didn't like the one you saw.

crashdome
Jun 28, 2011
General WPF/MVVM question!

I've made some decent applications which are pretty much devoted to WPF and no other 'View' framework. I know for Dialogs "NavigationServices" for Web/MVC are typically used. To simplify my development and avoid using reflection when handling confirmation dialogs and such, I've taken to just using parameters in my view models when responding to dialog commands. My view passes itself as a parameter on a command I specify so that the "owner" of the new dialog can be determined without reflection. This requires I specify:

In XAML:
code:
 <Button Command="{Binding DeleteCommand, Mode=OneWay}" CommandParameter="{Binding ElementName=window, Mode=OneWay}" /> 
In VM:
code:
public RelayCommand<System.Windows.Window> DeleteCommand { get; set; }
Having a reference to System.Windows in my ViewModels is breaking some rules about "View" - I know. It's just easy, requires a single static set of methods to open and close dialogs and deal with results because I know... it's always going to be Wpf and Windows.

I'm thinking about implementing an IDialogService<TOwnerBase> which would allow me to handle various types and not just WPF/WinForms Windows. My new service class would be a WpfDialogService which inherits IDialogService<System.Windows> and injected into the VM So the Command in my VM would get type injection and change to something akin to:

code:
public RelayCommand<TOwnerBase> DeleteCommand {get; set;}


actual command code might be something like:

code:
DeleteCommand = new RelayCommand<TOwnerBase> ((p) => if (_injectedDialogService.RequestConfirmationDialog(p, "Are you sure you want to Delete?")) then actuallyDeleteItem(););
So the DialogService handles things like DialogResult type, handling close events, etc.. etc.. and the ViewModel only passes the View to the service and handles a Boolean (or void) return value.

At least that's my thought... Haven't got around to doing anything yet.

I'm wondering if it's better to keep ViewModels coupled more towards frameworks (WPF, etc..) building a new set of VMs for each different 'View' framework and not worry about it? OR should I have a single ViewModel which can work in Wpf/WinForms/ASP.NET whatever???

How is this handled normally when you want to swap out or add multiple UIs in a 'small' application?

Captain Capacitor
Jan 21, 2008

The code you say?
For Asp.net WebAPI and getting JSON as input (with whatever SPA framework you want), it's both painless and painful to receive data from the client.

You could let the framework handle it:

code:
public class QueryDTO
{
    public string Query;
    public DateTime Start;
}

public class QueryController : ApiController
{
    [Route("/foo/bar"), HttpPost]
    public string DoQuery([FromBody] QueryDTO query)
    { ... }
}
Or get fancy and let the DLR work some magic.

code:
public class QueryController : ApiController
{
    [Route("/foo/bar"), HttpPost]
    public string DoQuery(dynamic query)
    { return query.Query; }
}

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

crashdome posted:

...

How is this handled normally when you want to swap out or add multiple UIs in a 'small' application?

I really like this approach (and think something like it should have been in WPF by default):

http://www.codeproject.com/Articles/35553/XAML-Dialog-Control-Enabling-MVVM-and-Dialogs-in-W

You define a dialog in XAML, then control opening it through a binding to your ViewModel.


That said, in my current Xamarin application that uses the MVVM pattern, I have an IDialogService with async Alert() and Confirm() methods. The implementation of the interface is different for each platform (iOS, Android, WinPhone). However, those dialogs don't require an owner so I haven't quite run into your problem.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Captain Capacitor posted:

Or get fancy and let the DLR work some magic.

code:
public class QueryController : ApiController
{
    [Route("/foo/bar"), HttpPost]
    public string DoQuery(dynamic query)
    { return query.Query; }
}

I would argue this is less fancy and more detrimental to the maintainability of your application.

Sedro
Dec 31, 2008

crashdome posted:

I'm wondering if it's better to keep ViewModels coupled more towards frameworks (WPF, etc..) building a new set of VMs for each different 'View' framework and not worry about it? OR should I have a single ViewModel which can work in Wpf/WinForms/ASP.NET whatever???
Generally speaking, the purpose of the view-model/controller is to translate your (e.g. pre-existing, domain-specific) model into a form which is easily consumable from a given UI technology. So yes, it would be normal to have different view-models.

Adbot
ADBOT LOVES YOU

crashdome
Jun 28, 2011

Sedro posted:

Generally speaking, the purpose of the view-model/controller is to translate your (e.g. pre-existing, domain-specific) model into a form which is easily consumable from a given UI technology. So yes, it would be normal to have different view-models.

That's what I figured.
So many opinions flying around about MVVM it's hard to stay grounded sometimes to the root ideas.


Bognar posted:

I really like this approach (and think something like it should have been in WPF by default):

http://www.codeproject.com/Articles/35553/XAML-Dialog-Control-Enabling-MVVM-and-Dialogs-in-W

You define a dialog in XAML, then control opening it through a binding to your ViewModel.


I will read this. It will definitely come in handy. Thanks!

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