How to make code run differently depending on the platform it is running on?

How to make code run differently depending on the platform it is running on?

I have a challenge for you.

I have an ASP.NET Web Application built in C# with Microsoft Visual Studio 2017.  There is a line of code that we have had to include in order for it to run on a localhost when debugging by attaching it to a running process in a web browser.

Here is the issue.  That line of code is not necessary when the process is running on the server.

I can remove that line when I submit the code in TFS.  But it would be great if we could make the code somehow ignore that line depending on what platform it is running on.

How can you think this could be done?

Comments

  • edited April 2019
    Complete, you might be looking for something like HttpRequest.IsLocal (https://docs.microsoft.com/en-us/dotnet/api/system.web.httprequest.islocal) or a build-time configuration change with something like SlowCheetah.

  • NET is a popular modular platform for creating web, mobile applications of any complexity of web and mobile applications. Cross-platform compatibility allows developing programs for Windows, Linux and Mac OS X. .Net is a relevantly new framework that offers efficient fulfillment of requirements of the widest range of software development needs. Building platforms in .Net provides language interoperability, great memory management, and third-party integrations. Projects of any size can be built in .Net, and it perfectly suits medium and large size applications. .Net has favourable opportunities to widen development services for software engineers. Hope it was helpful :)
  • This is a good post, thanks for sharing this info tellthebell
Sign In or Register to comment.