[Webinar] Learn how to a build a cloud-first strategyRegister Now


How secure is database code in a Razor file?

Posted on 2011-10-17
Medium Priority
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 39

Accepted Solution

Aaron Tomosky earned 2000 total points
ID: 36983571
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

ID: 36989556

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

865 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