Thursday, April 30, 2015

how to quickly enble impersonated current user to consume the Dynamic AX web service?

My web app is running under the Application Pool assoicated with a specific account, it is perfectly fine to consume the Dynamic AX web serivce.

However, the records were created in the Dynamic AX by the service account after we call the web service to send data to Dynamic AX. if we want to show the record was created the people who run the web application. we can use LogonAsUser property from the CallContext Object. we have to modify the web application by adding following line of code. i highlighted this line of code in Bold

FreeTextInvoiceService2012Http.CallContext context = new FreeTextInvoiceService2012Http.CallContext();
context.LogonAsUser = "YourDomain\\userName";
 textInvoiceService.ClientCredentials.Windows.ClientCredential.UserName = GetAppSettingsValue("UserName"); //which is the serivce account that allow to consume the dax web service
textInvoiceService.ClientCredentials.Windows.ClientCredential.Password = GetAppSettingsValue("Password");


in the Dynamic side,we must configure this service account to be allow impersonation. and grant the user name a role that allow to access the Dynamic AX.

when you check the TextFreeInvoice Tabale in dynamic AX, you should be able to see the user ID instead of the service account ID in the CreatedBy columns

Happy Programming.





Monday, April 27, 2015

How to fix "CS0103: The name 'Scripts' or 'Content' does not exist in the current context" Error in MVC Share Assembly

when i try to integrate a MVC share assembly(which is running under Web Razor View Engine) into a MVC web project which runing with WebForm view engine.

i go the following error message :Compiler Error Message: CS0103: The name 'Styles' does not exist in the current context




the solution is to follow the steps.

1. add  <add namespace="System.Web.Optimization" /> to the web.config file under the Views folder in the MVC Share Assembly project.

2. install "Mincrosoft Asp.net Web Optimization Framework" package via the Manage NuGet Package Window to the MVC share assembly project.



 3. added Bundle Configuration Logic to Global.asax in the MVC WebForm Project

 protected void Application_Start()
        {
            MvcRazor.SetupMvcRazor.Setup();

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            RegisterBundles(BundleTable.Bundles);
        }

        protected void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }

then you will see MVC share assembly page from the MVC Web Form Application.