Can't Get Enough RSS 2.0
 Saturday, December 22, 2007

I found a great post on dmitryr's blog on how to find the current trust level for your ASP.NET application, it is practical if you are hosting your site on a hosting company as the hosting company can set the trust level for your application in their machine.config file, and set it un-overridable.

Here is how to check the trust level:

Create an aspx page and place a Label:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckTrustLevel.aspx.cs" Inherits="CheckTrustLevel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>

</form>

</body>

</html>

 

 

 

In code behind...

 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class CheckTrustLevel : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = GetCurrentTrustLevel().ToString();

}

AspNetHostingPermissionLevel GetCurrentTrustLevel()

{

foreach (AspNetHostingPermissionLevel trustLevel in

new AspNetHostingPermissionLevel[] {

AspNetHostingPermissionLevel.Unrestricted,

AspNetHostingPermissionLevel.High,

AspNetHostingPermissionLevel.Medium,

AspNetHostingPermissionLevel.Low,

AspNetHostingPermissionLevel.Minimal

})

{

try

{

new AspNetHostingPermission(trustLevel).Demand();

}

catch (System.Security.SecurityException)

{

continue;

}

return trustLevel;

}

return AspNetHostingPermissionLevel.None;

}

}

 

 

Run the page and it will tell you what trust level your application has.

Saturday, December 22, 2007 4:07:36 AM UTC  #    Comments [0] -
ASP.NET | C#
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Navigation
Categories
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Ghazi Sarhan
Sign In
Statistics
Total Posts: 13
This Year: 0
This Month: 0
This Week: 0
Comments: 4
Themes
Pick a theme:
All Content © 2010, Ghazi Sarhan
DasBlog theme 'Business' created by Christoph De Baene (delarou)