Welcome to ASP.NET Guild

Be sure to come back often and tell others. If you have any tips, tricks, examples, please email them to me at chris.williams@techguilds.com and I will post them. Check out our ASP.NET QuickStart and C# QuckStart Libraries. Below is my latest articles.

Friday, December 15, 2017

Reading and Writing files to Google Drive

It has been a while since I posted but I have been playing with Google Drive and accessing it from a console application and had to search in a few places to find the right way to do it. The documentation tells you to download the .JSON file and that is helpful.  You can find the sample on how to get a list of files from Google Drive in a Console application.

This is a good start but I was getting errors related to the Certificate:

"At least one client secret (Installed or Web) should be set"

The problem is that the code provided has you using UserCredentials and some funky streaming stuff.  The credentials can be read from the stream like this into a Google Credentials object.

            GoogleCredential credential = null;

            using (var stream = new FileStream(credentialsFileName, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream);
                credential = credential.CreateScoped(scopes);
            }

You then use that Google Credentials along with your application name to get the service:

            // Create Drive API service.
            return new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = applicationName,
            });

Now after that fix, the original example works. I am assuming that since the article was written this has changed and the article has not been updated.  After applying this I do get the list of files from the article.

Scopes

A scope is what determines what the calls made using the service can do. In general there are 2 scopes: Read-Only and Full Access. There are other scopes you can use as well.

If you want to do more than read from the drive then you will need to change your scope.  

        string[] ReadOnlyScope = { DriveService.Scope.DriveReadonly }; // Read Only
        public static string[] FullAccessScope = { DriveService.Scope.Drive }; // Full Access


Permissions

It took a while to find how permissions work but I did find an article on Managing Shares that does go into it. It boils down to 2 types of permission: user and domain. A user permission assigns an individual user access. A domain permission assigns a domain access eg. "sitecore.net".  A permission has a role. The article describes the roles as "reader" and "writer".  This is a text string so possibly there are other roles as well.

Now personally, I have got the user permissions to work but when I try domain permissions I get an error. If you have successfully got domain working can you provide an example or take a look at the functions on GitHub for Domain Permission to see if there is something I am doing wrong?  I am passing "readwatchcreate.com" as domain. 

GitHub Libraries

I have created a GoogleAPIs public repository on GitHub. There are 2 folders. One for those still using .NET Framework which will not be updated and a DotCore folder with the new version built on .NET Standard and .NET Core. This includes a base library that has the code to connect to the API, a library that wraps some Google Drive functions to help you, and a unit test console app that will show sample calls and do positive and negative testing of the library. As I continue my learning of Google APIs, I will be adding more libraries for GoogleSheet and other API sections.


Monday, May 01, 2017

Introducing the ASP.NET Facebook Login QuickStart

Logging into Facebook is actually quite simple especially if you use our new ASP.NET Facebook Login Quickstart.

If you do not have a copy already email chris.williams@readwatchcreate.com to get instructions on how to access.

Installation

The first step is setting up your database.


  1. Open the database scripts in the QuickStart zip that start with CREATE_TABLE_.  Ensure they table names match your application prefixes for consistency.
  2. Open the database scripts in the QuickStart zip that start with CREATE_PROC_.  Ensure the table names match the tables in the CREATE_TABLE_ scripts in step 1.  
  3. Rename the procs to match your application prefixes for consistency. 
  4. Add the appSetting entries from the web.config in the Quickstart in the Web.Config file for your project. Make sure you change the stored procedure names in the appSettings to match your stored procedure names.
The second step is configure your ASP.NET application to use the plug-in.

  1. Add standard button or link button to page and implement click event.
  2. Call the LoginToFacebook function on this class with a call similar to the following but replace {my_site_name} with your site url.

    You may also want to change the access you desire:

    ASPNET.Authentication.Facebook.FacebookLogin.LoginToFacebook(ConfigurationManager.AppSettings["FacebookAppId"], "http://{my_site_name}/fb.aspx", "offline_access, email, user_likes, friends_likes");
  3. Create a page called fb.aspx and on load add the following code:

    if (Request["code"] != null) Session["AccessToken"] = FacebookLogin.GetAccessToken(ConfigurationManager.AppSettings["FacebookAppId"], ConfigurationManager.AppSettings["FacebookAppSecret"], Request["code"], ConfigurationManager.AppSettings["FacebookReturnUrl"]);
  4. Next you need to add the configuration keys to the web.config in teh appSettings section. These are provided by Facebook when you register your application:

    <add key="FacebookReturnUrl" value="http://{my site}/fb.aspx"/>
    <add key="FacebookAppId" value="{Likely a 15 digit number}"/>
    <add key="FacebookAppSecret" value="{This is a guid with no dashes}"/>
  5. Use the code returned to get the profile info back in JSON then use the helper functions to get each attribute you wish:

    string userProfileJSON = CXFacebook.GetUserProfile(Session["AccessToken"].ToString());
    ///     string id = CXFacebook.GetUserProfileId(userProfileJSON);
    ///     string name = CXFacebook.GetUserProfileName(userProfileJSON);
    ///     string firstName = CXFacebook.GetUserProfileFirstName(userProfileJSON);
    ///     string lastName = CXFacebook.GetUserProfileLastName(userProfileJSON);
    ///     string email = CXFacebook.GetUserProfileEmail(userProfileJSON);
    ///     string birthday = CXFacebook.GetUserProfileBirthday(userProfileJSON);
    ///     string link = CXFacebook.GetUserProfileLink(userProfileJSON);
    ///     string locale = CXFacebook.GetUserProfileLocale(userProfileJSON);
    ///     string quote = CXFacebook.GetUserProfileQuotes(userProfileJSON);
    ///     string userName = CXFacebook.GetUserProfileUserName(userProfileJSON);
    ///     string timeZone = CXFacebook.GetUserProfileTimezone(userProfileJSON);




Sunday, February 28, 2016

MVC RedirectToAction Explained for Beginners

RedirectToAction should be simple but sometimes they are confusing to beginners.  There are 3 ways to call RedirectToAction
  1. If you are already on a page within a controller you can use the shortest one which is only the caption and the action.

    eg. RedirectToAction("MyActionName")
  2. If you are referencing another controller or you want to include parameters.

    IMPORTANT: It may seem redundant but you need to list the action name twice. Notice Login is listed twice. 

    eg. RedirectToAction("Login", new RouteValueDictionary(new { controller = "Account", action = "Login", returnUrl = "/PersonalizedLearn" }));
I hope this clears up how RedirectToAction calls work.

If you have any questions feel free to email me at chris.williams@readwatchcreate.com



MVC Html.ActionLinks Explained for Beginners

Html.ActionLink should be simple but sometimes they are confusing to beginners.  There are 3 ways to call @Html.ActionLink:


  1. If you are already on a page within a controller you can use the shortest one which is only the caption and the action.

    eg. @Html.ActionLink("Click Here", "MyActionName")
  2. If you are referencing another controller or you want to include attributes on the link such as the css class

    eg.

    @Html.ActionLink("Click Here", "Index", "Home", null)

    @Html.ActionLink("Click Here", "Index", "Home", new { @class = "myHrefClass" })
  3. If you need to pass parameters to your action then you need to use the full version.

    IMPORTANT: If you are NOT Specifying a class, you still need to pass NULL or it will assume that the parameters you are passing are actually the attributes like in the version in the section way above.

    eg.

    @Html.ActionLink("Click Here", "Index","Home", new { paramName = value, param2Name = value}, null)

    @Html.ActionLink("Click Here", "Index","Home", new { paramName = value, param2Name = value}, new { @class = "myHrefClass" })


I hope this clears up how ActionLink calls work.  If you have any questions feel free to email me at chris.williams@readwatchcreate.com



Thursday, May 28, 2015

Redirect Url using IIS



Taken from https://support.microsoft.com/kb/324000

When you use Apache, you can redirect URLs by using the Redirect directive to point a folder or a location to a different folder on either the same Web site or a different Web site. You can also alias a folder to another location by using the Alias directive. If you use IIS, you can perform the same tasks by using the URL Redirection functionality.

To redirect a folder or file IIS:

  1. Log on to the Web server computer as an administrator.
  2. Click Start, point to Settings, and then click Control Panel.
  3. Double-click Administrative Tools, and then double click Internet Services Manager.
  4. Right-click the Web site or the folder, and then click Open.
  5. Right-click the folder display, point to New, and then click Folder.
  6. Return to Internet Services Manager.
  7. Right-click the folder that you just created, and then click Properties.
  8. Click the Directory tab, and then click A redirection to a URL.
  9. To redirect the folder to another URL, click the URL of the folder or the Web site that is described in step 4, and then type the complete URL to the new site in the Redirect to box.
  10. To redirect the folder to another folder within in this folder (for example, Projects to Sections/Departments/Projects), click A directory below this one, and then type the new folder in the Redirect to box.
  11. To mark the redirection type as a permanent redirection (and not a temporary redirection), click A permanent redirection for this resource. 
    If you use this setting, bookmarks and other details are automatically updated on some browsers.
  12. Click OK to save the changes.

Monday, May 18, 2015

ASP.NET Bootstrap Template Quickstart - Part 2: Using Email Address as UserName

When you first generate your application, the registration page insists on a UserName and Email Address from your clients, however it is more common to reduce the number of fields the user has to fill in as it increases registration.  The Email Address is much more valuable than the UserName as you can interact with it.

There are a couple changes you must make to use Email Address as the UserName:
  1. Change the UserName field to Email Address.
  2. In the control open tag you must add RequiresEmail=false
    If you forget to set this you will get the error message: 

    RegisterUser: CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Email for the e-mail, this is required if RequireEmail = true.

  3. Next you will want to add a validator to your username field to ensure it is in email format.  There are a few ways to do it.  You can use the RegEx Validator as a minimum or extend it to do a DNS lookup depending on your needs. Below is a sample I got from a StackOverflow article:

    <asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="tbEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
If you have any tips, tricks or resources you would like to share with the guild email me at chris.williams@readwatchcreate.com

ASP.NET Bootstrap Template Quickstart - Part 1: Creating a new application

When you create your next project, choosing the WebForms application will do a lot more for you than previous versions. For example, you now get a solution built on Bootstrap, it uses friendly names for links eg. /About instead of /About.aspx. It provides you with two master pages: one for regular sites and one for mobile. To start using this template follow these steps:


  1. Open Visual Studio and choose to File -> New Project
  2. In the left panel Click on Visual C# -> Web -> Visual Studio 2012
  3. On the center panel choose ASP.NET Web Forms Application
  4. At the bottom choose where to put your project and give your project a name
Voila, you have yourself a great application to build on top of.  You can start applying your design and customization. 

In our followup articles we will cover some of the functional changes you may want to make to to this template to suit your needs.  



If you have any tips, tricks or resources you would like to share with the guild email me at chris.williams@readwatchcreate.com

Sunday, July 06, 2014

Cannot find Microsoft.Web.Administration.dll

If you are getting this error, the most likely cause is that you do not have IIS 7 installed on your computer.\
Here are the steps involved to install IIS 7 on Windows 8.1

Click on the start menu and type Control Panel. When the choices come up choose Control Panel


Click on Programs

Click on Turn Windows features on or off

Click on Internet Information Service and click OK


Windows will apply the changes.  Windows will tell you when its complete.  Click Close on the dialog.

You should now be able to reference the Microsoft.Web.Administration.dll

If you are getting started with IIS 7 and would like assistance getting started check out the ASP.NET IIS 7 QuickStart.

Sunday, April 13, 2014

Experience with version 4 of .Net (No version 1.5 or 2.0

I saw an odd job listing today it wanted someone with the following:
  • Experience with version 4 of .Net (No version 1.5 or 2);
I thought it was kind of odd.  Why do they prefer someone without 1.5 or 2.0 experience.  I did some Google and found a basic rundown of the differences.   The job post does not list WCF experience or LINQ or Entity Framework or MVC.

.Net 2.0
1.CLR Features
2.Delegates
3.Other basic concepts

.Net 3.0
1.WCF
2.WPF
3.WF

.Net 3.5 - Enhanced Feature of .Net 3.0
- LINQ

.Net 4.0 
1.Parallelism
2.Entity Framework

For more details you could always look through these but that is not really the point of my article.

.NET 4.0
.NET 3.5
.NET 2.0

At first I thought it was odd but then it clicked. This kind of reminds me of the article written by Ryan O'Connell about all the things you would have different opinions on.

if-you-were-born-in-the-90s

So I am guessing that rather than a technology requirement in as much as its a personality requirement.  If you started with .NET 4.0 you don't know any of the sloppy hacks we had to do regarding stuff as simple as reading the config file.  Remember the including of a separate DLLto read the web.config in 2.0 as opposed to 1.1 having it native in the DLL.  I guess if you remember that you don't qualify for this job.

I look forward to hearing other your comments.  I know I would prefer someone who has been through the trenches than one who just arrived as a new private but that is just my opinion how about you.

If you have more insight then please email me at chris.williams@threepointturn.com or dennis.augustine@threepointturn.com

Tuesday, September 18, 2012

Ever wonder what you would do without technology...

JJ Abrams does a decent job showing the results of technology disappearing. Yes its not 100% realistic but if it was NBC would not be able to show it.

However from watching this episode, it gives you an idea of what would happen to that rich guy at Google.

Check out the pilot episode available on NBC.

Monday, August 13, 2012

.NET Postback loads Internet Explorer 7 Stylesheet on Postback in Chrome or FireFox

When using the Telerik AJAX Panel, on postback you may find that the updated controls will use the wrong stylesheet. Here is an article detailing the issue:

.NET Postback makes other browsers load ie conditional comments

The article mentions no workaround, however, since you are working in a .NET environment you do have the option of server side browser detection and then push the proper CSS for the browser. This would bypass the bug in the conditional comments.

Another option which is recommended in the link above is using HeadJS which will detect browser and apply the correct styles.

If you have any tips, tricks or resources you would like to share with the Guild, please email them to Chris Williams at chrisw_88@hotmail.com and we will post them here.

Wednesday, July 11, 2012

Debugging on 64 bit Windows 2008 With Visual Studio 2010

When trying to attach to process in Windows 2008 R2 64 bit you may get breakpoints that say they do not have symbols or cannot load symbols. I found a forum article where someone lists the fix:
By the way, for anyone else finding this article based on the same error message (at least in my case) was to modify the app pool in IIS. Go to advanced settings, change "Enable 32-Bit Applications" to True. VS2010, Win 7 64 bit.

You can check out the actual forum post at :
http://stackoverflow.com/questions/708323/visual-studio-2008-with-asp-net-3-5-debuging-using-attach-to-process-is-not-work

Friday, July 06, 2012

New Dynamics CRM Blog

For those Guild Members who are looking at Dynamics CRM or are looking at revolutionary and out of the box ways of getting the most out of it, there is a new blog starting up that will be providing a wealth of information on just those topics.

The Dynamics CRM Unleashed Blog is written by someone with hands on experience working with large scale and cloud based CRM.

I know I will be reading it on a regular basis, so I thought I would pass it on to you as well.

If you have any tips, tricks or resources you would like to share with the Guild please email them to Susan Fischer at susan@clinchportal.com or Chris Williams at chrisw_88@hotmail.com

Friday, June 22, 2012

IIS Crashes and you get Could not load type System.ServiceModel.Activation.HttpModule

All the sudden IIS crashes and you get the following error:

Could not load type System.ServiceModel.Activation.HttpModule


The error does not tell you much however if you were playing with IIS sometime around the crash it may be as simple as a module you added that broke it. Here is an article on a possible solution for this error:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/39571e42-aca7-469d-8c68-aa59c2da4fcc


Friday, May 25, 2012

Social Auth.NET - Platform supporting login using Social Media Apps

The library can be found at: http://code.google.com/p/socialauth-net/

If you require the source you can get it in in svn at: http://socialauth-net.googlecode.com/svn

When you access the login page and click one of the buttons to login you may get this error:

Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

If you do please install the You will need to install the Windows Identity Foundation and reference the Microsoft.Identity.Model dll in your web application project.

NOTE: If you are using XP then you cannot use the Microsoft Identity Foundation.

Thursday, April 12, 2012

MVC Razor Engine

The Razor engine is a new engine for MVC.  Here is an article I found on it.  As I research it I will be putting more information here on it.

Scott Gu's Blog: Introducing Razor
Razor Engine Codeplex

By The Way, If you use Sitecore, be sure to check out Glass  recently it has beta support for the Razor Engine.

If you have any tips, tricks or gotchas related to Razor Engine please share them with the Guild.

Wednesday, November 24, 2010

Sitecore Guild

I would like to take this opportunity to invite the Sitecore Guild to the family.
You can access the Sitecore Guild at:

http://sitecoreguild.blogspot.com

You may also follow them on Twitter at: http://twitter.com/SitecoreGuild

Sitecore is an amazing CMS built on ASP.NET. It is flexible as it includes full source code but is also easy for an end user to edit and publish content. For those who have not checked it out yet you need to. You will be amazed.

The next user group meeting for Sitecore in Toronto is in February. Check out the Sitecore Guild often for information on the next user group and for tips on using Sitecore.

If you have any tips, tricks or resources you would like to share please email Susan Fischer at susan@clinchportal.com



Friday, May 21, 2010

Login and Registration Tips and Tricks

Although this is not specific to porting, this link provides tips and best practices for creating
user management pages for your sites. Since this blog is about asp.net I thought you might find it useful.

http://www.getelastic.com/registration-usability-tips-ecommerce/


Thursday, April 09, 2009

Session keeps timing out when debugging iis7

I found out why this is happening. In IIS7 on the Application Pool, there are ping settings that will kill a session if it gets not response. This is great for production as it keeps iis running slim but when debugging in Visual Studio and stopping on a breakpoint that is nasty.

I found an article that explains how to disable the ping or extend the timeout period.

Application Pool Ping setting in IIS
http://technet.microsoft.com/en-us/library/cc725836.aspx

If you come across any tips, tricks or resource you think the group will find helpful please email them to Susan Fischer at susan@clinchportal.com and we will post them here.

Tuesday, March 31, 2009

Required permissions cannot be acquired

If you get the following error message then this link provides you with the step by step to resolve it

http://marcoscavaleiro.blogspot.com/2006/11/failed-to-grant-minimum-permission.html

An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error
and where it originated in the code. Exception Details:
System.Security.Policy.PolicyException: Required permissions
cannot be acquired. Source Error: An unhandled exception was generated during
the execution of the current web request. Information regarding the origin and
location of the exception can be identified using the exception stack trace
below. Stack Trace: [PolicyException: Required permissions cannot be
acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence,
PermissionSet
reqdPset, PermissionSet optPset, PermissionSet denyPset,
PermissionSet&
denied, Boolean checkExecutionPermission) +2770052
System.Security.SecurityManager.ResolvePolicy(Evidence evidence,
PermissionSet
reqdPset, PermissionSet optPset, PermissionSet denyPset,
PermissionSet&
denied, Int32& securitySpecialFlags, Boolean
checkExecutionPermission) +57
[FileLoadException: Could not load file or
assembly
'Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Design,
Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. Failed to grant minimum permission requests. (Exception from
HRESULT: 0x80131417)] System.Reflection.Assembly._nLoad(AssemblyName
fileName,
String codeBase, Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection) +0

If you have any tips, tricks or resources that you think would assist the group please email them to Susan Fischer at susan@clinchportal.com and we will post them here.

Are you a .NET Developer or Contractor interested in working with Sitecore or Dynamics CRM?

Apply for our Mentorship Program. If accepted, we will mentor you on Sitecore and provide you with project to help you build your skills and make some money at the same time. If you are interested send your resume with details on why you want to work with Sitecore or Dynamics CRM to: Chris Williams - chris.williams@techguilds.com or Dennis Augustine - dennis.augustine@techguilds.com We look forward to working with you to achieve your goals.