Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:44:58+00:00 2026-05-25T18:44:58+00:00

Recently I’ve managed to get the Razor parser working under .NET 3.5 and hosted

  • 0

Recently I’ve managed to get the Razor parser working under .NET 3.5 and hosted by SQL Server 2008. At the moment, it’s really just an experiment to see what is feasible. This is working, including dynamic compilation of razor template assemblies which are then loaded into the AppDomain (that was a mission!).

Because SQLCLR does not allow you to use Assembly.Load() in any SQLCLR hosted code, even with PERMISSION_SET = UNSAFE. My workaround for this is to register the assembly directly after compilation using sp_executesql which I build the CREATE ASSEMBLY statement. When I dynamically render these template assemblies, I do so with PERMISSION_SET = SAFE to ensure they don’t do anything outside what is permitted for safe assemblies.

Now the tricky part is, these razor templates are running in the context of the connected user, so they have access to the database, e.g., in my template, I could do:

@import System.Data.SqlClient
@{
    using (var conn = new SqlConnection("Context Connection = true"))
    {
        conn.Open();
        // Execute something against the database
    }
}

PERMISSION_SET = SAFE will allow for this, as that is one of the reasons SQLCLR even exists, but in these template assemblies I want to introduce some additional security that would allow me to prevent users from executing anything against the database.

Does anyone know of a way to disable types, such as SqlConnection or SqlCommand, perhaps using Code Access Security or another method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:44:59+00:00Added an answer on May 25, 2026 at 6:44 pm

    SqlClientPermission can be used to prevent use of SqlConnection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently just upgraded to SQL Server 2008 R2 Express. When I attempt to create
Recently I have been working with a SQL Server database and I was trying
Recently, I started changing some of our applications to support MS SQL Server as
Recently started with ASP.NET and MVC and have a few questions on working with
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently we got a new server at the office purely for testing purposes. It
Recently I've noticed that on occasion I do not get a mayorship notification when
Recently we started working with Database project in Visual Studio 2010. I have added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.