Debugging your code execution for anonymous users in SharePoint

Tobias Zimmergren
Tobias Zimmergren
💡🤖TIP: Check out the guidance for AI adoption on Azure!

Often when developing solutions that has anonymous users enabled, it can be hard to debug them from your local machine – because when you reach a point in your code where permissions higher than anonymous is required, SharePoint automatically tries to identify the user.

This means that if you’re running local development, and is browsing as an anonymous user – everything can be fine until you hit a line of code in your application that requires authentication, you are then automatically logged in.

This makes it rather hard for anyone to truly debug their solutions in anonymous mode.

With this article I’m laying out the tips that I’m using to debug application requiring anonymous users, and making sure that I don’t step up my privileges if the application needs to – I will now get an access denied instead.

Enable Remote Desktop on your development machine

If it is a virtual machine, you’ll also need to give it access to the internet or at least the local network so you can RDP to it using Remote Desktop.

Hook up your Visual Studio debugger to the IIS worker process so your breakpoints can hit

Use the web browser on your LOCAL machine (not the development machine) to browse your site (remember, it has to be an IP reachable from the local machine – make sure your network settings are valid)

This ensures that whenever you hit a point in your code that doesn’t allow anonymous users, it can not impersonate the account of the logged in user, which will result in an access denied exception. (Yes, this is where your breakpoints and debugging skills come in)

Now, when the breakpoint has hit – simply remote to your development machine (or use the lagged-out funked-up VPC console.. (no, use RDP!!)) and step through the code, as the breakpoint has hit!

Summary

Debugging anonymously accessible code can be a bit of a pain, but following my mentioned recommendations should make it a bit easier.

I tend to use this technique whenever I’m playing around with anonymous access, least-privilege code and things like that.

Hope it can help someone.

SharePoint

Tobias Zimmergren Twitter

Hi, I'm Tobias! 👋 I write about Microsoft Azure, security, cybersecurity, compliance, cloud architecture, Microsoft 365, and general tech!

Reactions and mentions


Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments

Mastodon