Sunday, May 30, 2021

Implementation of Windows Azure Authentication in Asp.net MVC

Windows Azure Authentication in Asp.net

How we implement windows azure authentication in asp.net web applications?




















Code in Home View


@{
    /**/

    ViewBag.Title = "Windows Azure Athentications";
}

<h2>Index</h2>
@if (Session["UniqueName"] != null)
{<text>
        Windows Azure Authentication -  Given Name:   @Session["UniqueName"].ToString() </text>
}

@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
    <input type="submit" value="Login" />
    
}


Code in Home Controller

        private static string clientId = WebConfigurationManager.AppSettings["ClientId"];
        private static string appKey = WebConfigurationManager.AppSettings["AppKey"];
        private static string aadInstance = WebConfigurationManager.AppSettings["AADInstance"];
        private static string tenant = WebConfigurationManager.AppSettings["Tenant"];
        private static string redirectUri = WebConfigurationManager.AppSettings["RedirectUri"];


        public static readonly string Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);

        // GET: AADAuth
        public ActionResult Index()
        {

            return View();
        }
        public ActionResult Login()
        {
            AuthenticationContext authContext = new AuthenticationContext(Authority);
            AuthenticationResult result = null;
            Uri uri = new Uri(redirectUri);
            result = authContext.AcquireTokenAsync("https://graph.windows.net", clientId, uri, new PlatformParameters(PromptBehavior.SelectAccount)).Result;
            Session["UniqueName"] = result.UserInfo.GivenName;
            return RedirectToAction("Index", "Home");
        }

       

        public void GetAuthorizationCode()
        {
            JObject response = new JObject();

            var parameters = new Dictionary<string, string>
                {
                    { "response_type", "code" },
                    { "client_id", clientId },
                    { "redirect_uri", redirectUri },
                    { "prompt", "login"},
                    { "scope", "openid"}
                };

            var requestUrl = string.Format("{0}/authorize?{1}", EndPointUrl, BuildQueryString(parameters));

            Response.Redirect(requestUrl);

        }


        public string AcquireTokenWithResource(string resource)
        {
            var code = Request.Params["code"];
            Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ac = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(string.Format("https://login.microsoftonline.com/{0}", tenant
                                  ));
            ClientCredential clcred =
                new ClientCredential(clientId, appKey);
            var token =
                ac.AcquireTokenByAuthorizationCodeAsync(code,
                           new Uri(redirectUri), clcred, resource).Result.AccessToken;

            return token;
        }


        private string BuildQueryString(IDictionary<string, string> parameters)
        {
            var list = new List<string>();

            foreach (var parameter in parameters)
            {
                list.Add(string.Format("{0}={1}", parameter.Key, HttpUtility.UrlEncode(parameter.Value)));
            }

            return string.Join("&", list);
        }

        protected string EndPointUrl
        {
            get
            {
                return string.Format("{0}/{1}/{2}", "https://login.microsoftonline.com", tenant, @"oauth2/");
            }
        }

    }

 This is code for the implementation of  Azure authentication.

Saturday, September 1, 2018

Asp.net MVC and Asp.net Core

Build and run cross-platform ASP.NET apps on Windows, Mac, and Linux Built on .NET Core, which supports true side-by-side app versioning New tooling that simplifies modern Web development Single aligned web stack for MVC and Web API Cloud-ready environment-based configuration Integrated support for creating and using NuGet packages Built-in support for dependency injection Ability to host on IIS or self-host in your own process

Thursday, February 9, 2017

Project ideas

Team of professional software Engineer, we are helping candidates for final year as well as semester project related to IT and Software Engineering in lowest possible cost with high quality. For Details please contact: tahiriet007@gmail.com/umairkhalid401@yahoo.com

Wednesday, February 1, 2017

Create Setup Projects in windows Forms Applications VS 2010

Follow the below steps

Create a new setup project

  1. On the File menu, point to Add, then click New Project.
  2. In the resulting Add New Project dialog box, in the Project Types pane, open the Other Project Types node, open Setup and Deployment Projects, and select Visual Studio Installer.
  3. In the Templates pane, choose Setup Project for a standard setup, or Web Setup Project for a Web application.

 Add in an existing setup project 

  1. On the File menu, point to Add, then click Existing Project.
  2. In the resulting Add Existing Project dialog box, browse to the location of the setup project and click Open.
Click on Solution and ad then new




















Friday, January 20, 2017

Windows form applications C#

My First Application in windows Forms C#

We are going to make first application in windows forms.Follow as in images























Rename the name and select your location where you want to save it.

After Creating application blank form is created as shown in screenshot.






















 Now add controls on forms from toolbox.









    Solution Explorer on the right side of visual studio screen...


 Project have properties and references....
Now View the code view





View code in C# like that..

I will upload details in next post..




Friday, January 13, 2017

Download IDM with key

Get registered IDM by clicking link below :

https://drive.google.com/file/d/0B76ydpTFiZQbSXVDMkdCdWM4VEU/view?usp=sharing

Difference between Visual Studio 2015,2013 and 2012

Visual Studio 2015

Visual Studio 2015 has been finally released including several incredible features that enhanced the way we look at development from desktop and web to mobile applications.
  • Improved Code Editor: The Code Editor has been already replaced with the so called “Roslyn” compiler to provide you an improved and exciting code editing experience. A light bulb is shown when you have to include some code fixes , so anytime you see a light bulb, click it and you will get suggestions that is based upon the analyzed code.
  • Custom Layout: The full potential of this feature can be used on multiple devices. Let’s say you are about to use a Surface Pro to develop on your bus ride home and a 24″ monitor from the comfort of your home. In order to quickly switch devices go to Window – Apply Window Layout. Keyboard shortcuts is also supported so that the user can quickly navigate to any familiar layout.
  • Shared Project: Probably you have been a witness of an event when you wanted to use a Shared Project option right outside of Windows Universal Application, now IT IS A REALITY. After a quick search you will find the Shared Project in the list of the new project window.
  • Single Sign-In: This one is undoubtedly much awaited feature. As these days, we developers, are using cloud services for multiple purposes. So, managing these services with different sign-in details in Visual Studio was annoying as authentication alerts were required for accessing these integrated cloud services. With Visual Studio 2015 single Sign-In support is provided, so once we are authenticated with first cloud service, no more authentication needed (Coooool…..).
  • Smart Unit Tests: IntelliTest in Visual Studio 2015 has the capability to explore our code to generate test data and a suite of unit tests with much improved code coverage.
  • Emulator for Android: No doubt the Android Emulator is a true relief as you can use it in Visual Studio 2015 as a cross-platform project or VS Tools for Cordova. It supports a variety of sensors and simulations, also GPS Location, Screen Rotation,  Accelerometer, SD Card, Zoom, Multi-touch, Camera and access to network also.
  • Renaming Enhancement: Before the user renames a variable or an object, Visual Studio will highlight all affected instances making it easy to identify all the changes to be made. Also there is a new dialog window that shows the number of changes or even conflicts for a renaming operation.
  • Editor Touch Support: There is an enormous boom of touch sensitive devices and monitors nowadays, so Visual Studio 2015 had to come up with touch based support. You can use the touch screen for scrolling, gesture zooming, line selecting and also a new functionality was added to bring up the Editor context menu.
  • Support for JavaScript Editor: Working as a web developer on Microsoft Platform, it’s always been difficult to work with JavaScript within Visual Studio. Although Visual Studio 2013 has improved it’s editor for JavaScript but in Visual Studio 2015, JavaScript editor has been updated with number of amazing features as:
    • Intellisense support for object literal
    • Expand/Collapse JavaScript code sections
    • New Navigation Bar for navigating between elements in JavaScript
    • Support for New JavaScript Features (ES6 version)
    • and many more…
  • Custom Window Layouts: Most developers are familiar with their own window configuration. Let’s say you work on a JavaScript based project, then you will need a much larger code editor window whilst with a web project you may want to open the solution explorer window.
These are many other features introduced with latest version of Visual Studio. You can get a complete list of these Online at Visual Studio Website. If you are more interested, you can get good reference books on Visual Studio 2015 here.

Visual Studio 2013

Top Features of Visual Studio 2013

  • Throw-away applications: In Visual Studio 2013, the new project window looks a little different. If you want to create a new project, the name and the location no longer have to be set immediately. It is a good option when you are about to test something and delete the project right away, so you don’t waste time.
  • Code-lens: A feature that is available only in the Ultimate Edition. A real time saver, as by default, it shows the number of times a method or property is referenced in your code. Especially useful feature in larger project where you are not familiar with the entire source code.
  • Customizing Scroll Bar: The possibility to customize the scroll bar just gives the user a much better overview of larger files. A user can set the scroll bar to show breakpoints, errors and much more.
  • ALM (Application Life Cycle Management) features including agile portfolio management, web-based code comments, web-based test case management, change-sets and commits etc.
  • Creating Azure Website from within Visual Studio 2013 by installing Azure SDK and connecting to Azure.
  • Live debugging in Azure
  • Live Tracing from Azure
  • With .NET framework 4.5.1, just like 32-bit Edit and Continue, now we have with 64-bit also.
  • Better Navigation & Search
  • Open a method definition by using Peek a Definition feature.
  • Handy feature of resolving type by resolve menu.

Visual Studio 2012

Top Features of Visual Studio 2012

  • While the Visual Studio 2010 already included an emulator for Windows Phone devices, the Visual Studio 2012 Simulator is much more powerful. It enables debugging apps for various scenarios that you just don’t have natively on your own machine.
  • You can also develop Windows 8 apps that strictly require some hardware support such as touch, rotation and different target resolution.
  • It is unimaginable to build quality applications without good IntelliSense. Therefore, the developers put enough effort in Visual Studio 2012 to make it more efficient and productive.
  • An even more important feature is the JavaScript Console. The good news is, that you can play with the source code modifications while the application is running.
  • Runtime Debugging Tool i.e. DOM Explorer for debugging HTML/CSS.
  • Asynchronous Support in C#/VB
  • Team Foundation Explorer Window
  • Code Clone Detection
  • Project File Compatibility with Visual Studio 2010

Visual Studio 2010

Top Features of Visual Studio 2010

  • IntelliSense improvement: One of the most important and time saving feature. It is so comforting to wonder how many hours a programmer can save thanks to IntelliSense. For those who don’t know, it is that wonderful drop down list that automatically completes existing member names or type names. This feature can amazingly speed up your work as you don’t have to type so much on your keyboard.
  • Toolbar Items can be easily found: Each new version of Visual Studio has an exponential increase of items in the Toolbox. Until the release of VS 2010, the items where categorized into collapsible sections and searching was managed manually by the user. Fortunately, the new version of Visual Studio offers a search via keyboard.Simply click on the Toolbox so that it is focused and just start typing.
  • Improvement in Searching: Visual Studio always supported different search features , but the fact is that it was a little clunky. In other words, the search feature was limited to searching for specific string in files. This feature was still available but a new one was added. A search window called Navigate To. You can navigate anywhere in your project by typing in the name of a method, class, an event or even a file name.
  • Multiple monitors: It is statically proven that using multiple monitors can improve a programmers efficiency by 50%. So, visual Studio 2010 has feature for detaching window outside the IDE.
  • Highlighting References feature in Visual Studio 2010 can highlight all calls to a specific method or member variables.
  • Improved Loading Time for Assemblies in “Add Reference”.
  • Support for Targeting multiple .NET Framework during Application Development.
Hopefully this Web Development Tutorial helps to understand how Visual Studio evolve in recent years and what are the most exciting features introduced with every version. Now Visual Studio 2015 is available having lots of cool features that will definitely increase developers productivity in many ways.