Wednesday, December 31, 2014

Build an Application to Connect to MongoDB on Azure

http://docs.mongodb.org/ecosystem/tutorial/build-an-application-to-connect-to-mongodb-on-azure/

below is the connection string:

mongodb://user:password$@xxxx1.cloudapp.net,xxxx2.cloudapp.net/dbname?replicaSet=rsName


using RegMSW.Core;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RegMSW.Core.Models;

namespace RegMSW.Core
{
    public class MongoDbContext
    {
        private MongoDatabase db;
        private MongoServer server;
       
        public MongoDbContext(string database, bool safeMode = true)
        {
            string connStr = Properties.Settings.Default.connectString;
            var client = new MongoClient(connStr);
            server = client.GetServer();
            db = server.GetDatabase(database);
        }

MongoDb Authentication

http://docs.mongodb.org/ecosystem/tutorial/authenticate-with-csharp-driver/




















http://docs.mongodb.org/ecosystem/tutorial/authenticate-with-csharp-driver/
This page is a brief overview of authenticating to a MongoDB cluster with the MongoDB C# Driver using version 1.8 and above.

Internal Authentication

Internal authentication refers to accounts stored inside MongoDB. Currently, the only way to authenticate against internal accounts is to use the MongoDB Challenge Response mechanism, orMONGODB-CR. This is the default mechanism. To authenticate as the user “user1” with a password of “password1”, defined in the “test” database:
var credential = MongoCredential.CreateMongoCRCredential("test", "user1", "password1");

var settings = new MongoClientSettings
{
    Credentials = new[] { credential }
};

var mongoClient = new MongoClient(settings);
Alternatively, when you only need a single user, it is possible to specify this in the connection string.
var connectionString = "mongodb://user1:password1@localhost/test";

var mongoClient = new MongoClient(connectionString);
NOTE
If you do not specify a database in the the connection string, the default database is the “admin” database.
In some cases you may need to authenticate as multiple users in different databases. For example, imagine a map/reduce job that reads from the database “first” and writes the results to the database “second”. You may need to authenticate one user defined in the “first” database and another in the “second”:
var credentialFirst = MongoCredential.CreateMongoCRCredential("first", "user1", "password1");
var credentialSecond = MongoCredential.CreateMongoCRCredential("second", "user2", "password2");

var settings = new MongoClientSettings
{
     Credentials = new[] { credentialFirst, credentialSecond }
};

var mongoClient = new MongoClient(settings);
NOTE
As of the 2.4 MongoDB release, this is no longer necessary, since you are able to define a user in one database and delegate privileges for that user in another database.

External Authentication

External authentication refers to credentials validated outside of MongoDB. The external authentication provider currently used is Kerberos. To authenticate to a MongoDB cluster using Kerberos, you must specify the GSSAPI mechanism and a user name. On Windows, it is also possible to provide the password.
Fundamentally, the process for connecting with Kerberos is the same for Windows and Linux systems; however, Linux systems require the use of kinit to acquire the security credentials whereas Windows systems perform this action transparently using SSPI based on the account running the current process when a password is not used.
The below examples work on both Windows and Linux systems.
var connectionString = "mongodb://user%40REALM.COM@localhost/?authMechanism=GSSAPI";

var client = new MongoClient(connectionString);
NOTE
%40 is the url encoded representation of the ‘@’ character.
Alternatively, you can specify the authentication mechanism in the code, as in both of the following:
var credential = MongoCredential.CreateGssapiCredential("user@REALM.COM");

var settings = new MongoClientSettings
{
    Credentials = new[] { credential }
};

var mongoClient = new MongoClient(settings);

Linux Systems

Linux does not integrate Kerberos authentication in the operating system (unlike Windows) and requires the use of an external library. The MongoDB server and the .NET driver on Linux use the libgsasl to manage authentication.
Mono, the open source platform used to run the .NET driver on Linux, provides a way to map the hard-coded names of native libraries to their actual names, which can be different based on your distribution. Consider the documentation from the Mono project for this process.
Tor the .NET driver, you must map the libgsasl-7.dll library. An example configuration for ubuntu looks like this:
<configuration>
  <dllmap dll="libgsasl-7.dll" target="libgsasl.so.7" />
</configuration>
Name this file MongoDB.Driver.dll.config and save it in the same directory as theMongoDB.Driver.dll assembly. After mapping this library, always run kinit before or during your application startup process.

Tuesday, December 23, 2014

Could not load file or assembly ‘Antlr3.Runtime’ or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

http://www.cloud-developer.eu/blog/2013/06/26/could-not-load-file-or-assembly-antlr3-runtime-or-one-of-its-dependencies-the-parameter-is-incorrect-exception-from-hresult-0x80070057-e_invalidarg/


You have really no clue where to find, but one thing is for sure: it’s not in your code, because you didn’t changed anything.
It happened to me when developping an MVC 4 .net 4.5 webapp. After extensive search the solution is (as usual) simple:
empty your %TEMP% folder:
  • close all programs that you are using (the one in the system tray included)
  • Click the start button
  • click Run
  • type: %TEMP% in the box
  • click the OK button
Now a the directory for temporary files opens:
  • select all files ( CTRL – A)
  • press the DELETE key on your keyboard
  • acknowledge that you want to delete all files

Saturday, December 20, 2014

HaveIbeenpwned.com

network access list VM

http://michaelwasham.com/windows-azure-powershell-reference-guide/network-access-control-list-capability-in-windows-azure-powershell/

stackoverflow account

http://stackoverflow.com/users/3179030/gregchu

Microsoft virtual academy asp.net authentication

Individual authentication has to do migration to send local db to SQL server on Azure

Module 2 7 min
Enable- migrations
Update-database -Script -
15:30 min
Authorization role
[allowanonymous]
17:41 min
Form webconfig
Deny all users true

23:22 min
Change identify db

23:55 min
Application user class custom fields
Db changed error
Add migration
32:43 multiple role


Module 3
10:20 min
Facebook

Azure speed test

http://azurespeedtest.azurewebsites.net

Friday, December 19, 2014

Azure website brought up login.microsoftonline.com (Sign in with your work or school account)

http://stackoverflow.com/questions/27558332/azure-website-brought-up-login-microsoftonline-com-sign-in-with-your-work-or-sc/27558834#27558834


You are seeing the Azure AD login page because the website has been setup with Authentication / Authorisation to use Azure AD.
Log into the Azure Portal and find your Website instance > Click 'Configure' tab. Scroll down until you find the 'authentication / authorization' section and click on the 'Remove' button to disassociate your website with Azure AD.

Thursday, December 18, 2014

gcudublin2

https://social.msdn.microsoft.com/profile/gchudublin2/

AzureReadiness-DevCamp

C:\Users\chu_g_000\AzureReadiness-DevCamp\AzureReadiness-DevCamp.html

Azure web farm

http://michaelwasham.com/2012/08/13/publishing-and-synchronizing-web-farms-using-windows-azure-virtual-machines/

http://www.wadewegner.com/2013/03/using-windows-azure-virtual-machines-to-publish-and-synchronize-a-web-farm/



i, I have a website done in ASP.Net MVC which hosted in Azure and it will try to connect to a VM machine hosted on Azure which has MongodDB installed and running. tt will need to connect to port 27017. 
When I tested on my local machine, I can connect to the VM MondgoDB no issues, then I published to Azure web site and it brought up www.microsoftonline.com login, saying sign in the Azure Active directory on the title bar and prompted login for "sign in with your work or school account.
It seems to me Azure has certain fire wall or ??? to prevent port 27017 from the web server (xxxxx.azurewebsites.net). Any ideas?
Thanks
Greg

Tuesday, December 16, 2014

DevelopMentor: Building rich input forms in ASP.Net MVC

Below is a newer version Michael posted on youtube

https://www.youtube.com/watch?v=PDrlzgGSaSk

38.54 min save book done
47.13
52.10

LIDNUG & DevelopMentor: Building rich input forms in ASP.Net MVC


https://www.youtube.com/watch?v=6VhqQngYQ20

below is code to add "book"

In admin controller





add view



38.12 min missing category


(40.25 min) add the selectedListItem to array to the ViewBag, the name put in the ViewBag is case sensitive.


(40.54 min) add the SelectedListItem to array to the viewbag


add category to the book form




get book and cat id back and save the book then display the cat

the important thing here is the "selectedCategoryID" has to be in the parm (case does not matter), otherwise it will be null.








Friday, December 12, 2014

mongodDB document



IE private browsing

InPrivate Browsing


You can start InPrivate Browsing from the Safety menu, by pressing Ctrl+Shift+P, or from the New Tab page. Internet Explorer will launch a new browser session that won’t keep any information about webpages you visit or searches you perform. Closing the browser window will end your InPrivate Browsing session.

http://windows.microsoft.com/en-US/internet-explorer/products/ie-9/features/in-private

Thursday, December 11, 2014

mongo shell












16 MB limit for doc size

C:\WINDOWS\system32>mongo MongoDB shell version: 2.6.5 connecting to: test > show collections > db.foo.save({_id:1,x:10}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 1 }) > show collections foo system.indexes >
> db.bar.save({_id:1,x:10}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 1 }) > db.system.indexes.find() { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.bar" } >


cannot use array for id

> db.users.save({name:'Bob'}) WriteResult({ "nInserted" : 1 }) > db.users.find() { "_id" : ObjectId("548a0667444e0f70ac382dfd"), "name" : "Bob" }

> ObjectID().getTImestamp() 2014-12-11T16:05:07.710-0500 ReferenceError: ObjectID is not defined > ObjectId() ObjectId("548a0718444e0f70ac382dfe") > ObjectId().getTImestamp() 2014-12-11T16:05:33.088-0500 TypeError: Object ObjectId("548a071d444e0f70ac382df f") has no method 'getTImestamp' > ObjectId().getTimestamp() ISODate("2014-12-11T21:05:54Z") >

2nd doc with the same id replaced the first


insert is safer


no id used


use email as id




save is dangerous



upsert, insert if



update


update


inc x and add y no problem


remove a field


rename a wrong field


array





not array












sort ID ascending



return id 1 which matched the criteria