How secure is database code in a Razor file?

Posted on 2011-10-17
Last Modified: 2012-05-12
I have never used Razor to hold database code, and probably never would. But given that the C# resides on the server, is this a safe way to protect from the database code being visible to the user?


var db = Database.Open("SmallBakery"); 
var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
<h1>Small Bakery Products</h1> 
@foreach(var row in db.Query(selectQueryString))
<td aligh="right">@row.Price</td> 

Open in new window

Question by:newbieweb
    LVL 38

    Accepted Solution

    Open your page in a browser and you will see everything a user can see. And CSS and included js files are also seen client side. Anything in your aspx is safely server side. Make sure directory browsing is off and your default website is off. There are also more advanced steps to keep stuff safe but the short version is that anything serverside is safe.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
    In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now