Reading / MailSettings / Smtp From Web.config In Medium Trust Environment?

Jan 5, 2011

I have some inherited code which stores SMTP server, username, password in the section of the Web.config.

It used to read them like so:

Configuration c = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
MailSettingsSectionGroup settings = (MailSettingsSectionGroup)c.GetSectionGroup("");
return settings.Smtp.Network.Host;

But this was failing when I had to deploy to a medium trust environment. So following the answer from this question, I rewrote it to use GetSection() like so:

SmtpSection settings = (SmtpSection)ConfigurationManager.GetSection(""); return settings.Network.Host;

But it's still giving me a SecurityException on Medium trust, with the following message:


View 1 Replies

Similar Messages:

Security :: CreateUserWizard In Medium Trust Environment?

Feb 22, 2010

We just moved our site (still in development) to a new hosting company, on a medium trust shared environment. We setup the databases, aspnet_users tables etc, but now our page that handles new people signing up doesn't work. It contains a simple standard <asp:CreateUserWizard> control. However, this page is not working since the move (the rest of our pages are working). We get this compiler error:

Request for ConfigurationPermission failed while attempting to access configuration section 'system.web/machineKey'. To allow all callers to access the data for this section, set section attribute 'requirePermission' equal 'false' in the configuration file where this section is declared.

Apparently the hosting company is using the default medium trust .NET settings. We have no idea how to get around this since we've always developed on full trust dedicated server environments. Is it simply a fact that the <asp:CreateUserWizard> control does not work in medium trust, or is there a way?

View 11 Replies

Security :: From High To Medium Level Trust Environment

Jan 8, 2010

i wrote all my code on my computer so i had a high trust level, after ftping my site and database to i realized they have a medium level trust enviroment.... i called the tech support and they said they were sorry but they couldnt change it for me... heres my code. any idea how to get it to work in medium level trust? I am trying to create a new directory where all of a users upload goes. The folder is created dynamically when the upload page loads.

string username = User.Identity.Name;
string UpPath;
UpPath = "~\Users\UserUploads\" + username + "\";
if (!Directory.Exists(UpPath))
Directory.CreateDirectory("~\Users\UserUploads\" + username + "\");

how to get this working in medium level security?

View 2 Replies

Configuration :: Logging SMTP Session In Medium Trust?

Jan 23, 2011

I have a script that send a daily email to a list of recipients from a database. I am having a couple of emails failing to send and the try/catch/ex.message & ex.stacktrace doesn't give me enough information to show what the actual problem is. I have tried to do some smtp session logging but that seems to not be doable since I am running under Medium trust. Is their either another way to get this code to work on medium trust or another way to get detailed SMTP log info.

This is what I tried to use in my web.config


View 2 Replies

How To Determine The C# Framework Version In A Partial/medium Trust Environment

Mar 18, 2010

I need to determine the clients .NET framework version in my web application. I'm running in partial trust so I can not read the filesystem or registry (Is there an easy way to check .net framework verison using C#?).

System.Environment.Version returns the runtime version, so I can not use that.

I cannot use javascript The only way I can think of at the moment is to try to load a .NET 3.5 dll and catch an exception, but this does not.


Request.Browser.ClrVersion and Request.Browser.GetClrVersions() will return the .NET framework version(s) installed on the client.

View 3 Replies

Security :: Email Attachment From Website In Medium Trust Environment?

Feb 10, 2010

The website is on a shared hosting server with the trust levels set to medium.

I am sending an e-mail from the website (to confirm a booking) and need to attach a PDF doc (directions) with the mail.

The server is rejecting the mail because of the trust level.

My code line for the attachment is:

//mail.Attachments.Add(new System.Net.Mail.Attachment("c:/Domains/"));

View 2 Replies

Web Forms :: Reading Resources And 'Medium Trust'?

Jun 24, 2010

I am trying to read resources values in a medium trust environment have am getting a security error. The resources are in the path of the root folder, i.e. not somewhere else. It works in a full trust.

All code I tried is giving the same error. How can I read a resource without getting this problem?

View 2 Replies

Security Exception Over Reading/writing Files On Medium Trust?

Nov 21, 2010

I'm working on a project in ASP.Net, and it requires reading/writing to files on my server. I'm hosted at GoDaddy, and they swear they've got me at Medium Trust. When I try to read or write files that are in my own domain, I get Security Exceptions. I've tried multiple ways of opening/saving the files and they all return security errors. Here's the most recent error and offending line of code (I didn't save them all, they're all pretty much the same thing):

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.MediaPermission, WindowsBase, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' failed.

PngBitmapEncoder pbe = new PngBitmapEncoder();
pbe.Frames.Add(BitmapFrame.Create(new Uri("ornament.png", UriKind.Relative))); <-- Error

I've also gotten the error when trying to read/write using FileStream, Bitmap.Save and new Bitmap("ornament.png"). Could there be a problem with my Web.config? Is read/write supposed to be blocked by medium trust? This is a time-sensitive project and this is a brick wall for me. The deadline is end of business day tomorrow and GoDaddy isn't responding.

View 2 Replies

Configuration :: Web.config Trust Level To Medium - Place Code?

Dec 29, 2010

My hosting provider just changed the trust level to medium but I cant figureout where to place the configuration on the web.config file! I have spent hours trying to figureout with no luck. here my web.config file


View 2 Replies

Run System.Web.DataVisualization In Medium Trust At On Rackspace Cloud Sites

Aug 4, 2010

I am having problems getting Microsoft Charting:


To work in the Medium Trust on Windows Server 2008 on IIS 7 Using .Net 3.5 In an environment at Rackspace on their Cloud Sites. I get this error message from the Rackspace hosting environment:

Security Exception

The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details:
System.Security.SecurityException: That assembly does not allow partially trusted callers. I have setup a site in our local staging environment to test the medium trust, and I get this message: Required permissions cannot be acquired.

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:
System.Security.Policy.PolicyException: Required permissions cannot be acquired.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[PolicyException: Required permissions cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +10239406
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +97
[FileLoadException: Could not load file or assembly 'System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190
[ConfigurationErrorsException: Could not load file or assembly 'System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11204104
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210
System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +76
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +283
System.Web.Compilation.BuildManager.CompileGlobalAsax() +50
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +676
[HttpException (0x80004005): Could not load file or assembly 'System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1012
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +1025
[HttpException (0x80004005): Could not load file or assembly 'System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11297830
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4336948
Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016
Rackspace will not install the MSChart.exe package on the Rackspace Cloud Sites servers.

View 1 Replies

Difference Between Medium Trust And Partial Trust ?

Feb 11, 2011

I have to host a wcf service in a medium trust environment.I want to know which bindings are supported while hosting WCF services in medium trust. There is a MSDN article which talks about partial trust. I am not sure is it the same as medium trust.

View 1 Replies

TransactionScope In A Medium Trust

Feb 3, 2010

Im running an ASP.NET MVC application hosted with Mosso, there are telling me that they cannot enable DTC because they run everything in medium trust.So when executing code that references: TransactionScope I get the following error. The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024)

Is there anyway to get around this?

View 1 Replies

Want To Know About Medium Trust Level ?

Sep 4, 2010

what Medium Trust level is ?And what does it mean :

"More and more ASP.NET hosting providers are enforcing a Medium Trust Policy on their servers.Therefore it is important to make your website work (as much as possible) in environments where medium trust is enforced."

View 1 Replies

C# - Can GhostScript Run In Medium Trust

Apr 23, 2010

I am using GhostScript to generate some thumbnails of PDF pages in an ASP.NET application. I have it wrapped in this library called GhostScriptSharp that just uses DllImport to call methods in the GhostScript DLL.It looks like this wont work on a medium trust hosting environment, either because of the fact that it is calling unmanaged code, or that it looks like the library is creating files all over the place (outside my virtual directory). I ran Process Monitor and saw it trying to Read, QueryNameInformationFile, CreateFile and QueryStandardInformationFile in places like:


Any ideas about whether this is "fixable" to run in medium trust? If I can't use GhostScript, is there another free/open source library that WILL work in Medium trust?

View 1 Replies

MySQL Run Under Medium Trust?

Jan 22, 2010

I am trying to get a simple prototype using ASP.NET S#arp-architecture (Sharp architecture) to run on a shared hosting site. This site runs in medium trust, which appears to give problems with this framework. At first I went off on a wild goose chase with the, but the latest version already supports partially trusted callers. The only way I found up until now is this blogpost, which basically describes re-compiling everything from the ground up, starting with the various Castle components. Is this the only way to get this to work, and more importantly, does this actually work?

I have had some good experiences with S#arp-architecture, and since I only have a few days to build this prototype, I figured S#arp-architecture would be a good match. So, my options are to stick with SA, or on the other end of the spectrum to hand-roll an MVC/NH/mySQL application.

View 1 Replies

Web Development - OleDbPermission And .NET Medium Trust?

Sep 1, 2010

I'm following this document in order to run my website in a medium trust environment. My web app uses OleDb, so I need to give it permission in medium trust. I've done everything that is in that article and it's still not working In my web_mediumtrust.config I've added the following security class:

<SecurityClass Name="OleDbPermission" Description="System.Data.OleDb.OleDbPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

And the following permission set:

<PermissionSet class="NamedPermissionSet" version="1" Name="ASP.Net">
<IPermission class="OleDbPermission" version="1" Unrestricted="true" />
</PermissionSet> [code].....

View 1 Replies

To Run A New Process From A Medium-trust .NET Application?

Oct 7, 2010

I'm building an ASP.NET MVC site where I want to use OpenSTV to conduct polls. To run results through OpenSTV, I'd have to run the executable. Is that allowed from a medium-trust ASP.NET application?

View 1 Replies

C# Pdf Generator That Runs On Medium Trust

Jan 17, 2011

I need to generate PDF reports on a server where full trust apps cannot run.(i cannot use PdfSharp and MigraDoc because of security exceptions when i say

PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = doc;
renderer.RenderDocument(); // <<< ex here

Message: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' i need to
have c# pdf generator that runs on Medium Trust or Low trust OR be able to pass values from c# to any php pdf generator.I am trying itextsharp-5.0.5,

View 2 Replies

C# - Compiling Code In Medium Trust?

Dec 21, 2010

Together with Ben (@BuildStarted), we've been building the RazorEngine project, which is designed to allow you compile and parse arbitrary templates outside of ASP.NET MVC. The project has had a couple of releases for a while now, and the feedback has been greatBut, we have encountered an issue: Medium trust.

Because we are using the CSharpCodeProvider to compile the Razor-generated classes (to load into the current AppDomain for execution), we encounter a SecurityException when trying to invoke it, due to the LinkDemand enforced on it. When a normal ASP.NET page is compiled (regardless of trust level), it does so through a BuildProvider which is normally GAC'd, and thus is implicity granted the appropriate permissions to compile. Hence ASP.NET WebForms works as standard in Medium trust.

Our code does not, and we need to target scenarios where our built library won't be deployed to the GAC and is running in Medium trust. So we considered building a BuildProvider specifically for it and defer compilation to the ASP.NET build system, but this seems overly complex and disjointed, and the provider itself requires both a mapping through a file extension, and a virtual path (which may or may not resolve to a physical file - think VirtualPathProvider). It all seems overkill, just to get the project working in Medium trust; not just that, but purely for ASP.NET projects as our engine also works outside of ASP.NETSo my question is this, does anyone know of any techniques or technologies for compiling C# code in a Medium trust environment?

View 1 Replies

Get Session Cookie Name In Medium Trust Level?

Nov 30, 2010

Is it possible to get session cookie name in medium trust level? The code below works in full trust, but throws a security exception in medium trust level.

string sessionCookieName = ((SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState")).CookieName;

View 1 Replies

C# - Reflection Permission Are Allowed In Medium Trust?

Jan 11, 2011

I want to ask that which methods/classes are allowed in Medium Trust.For example, whether these methods are allowed?


View 2 Replies

How To Load A File From Bin Folder In .NET In Medium Trust

May 27, 2010

I need to load an xML file from the bin folder in ASP.NET (MVC, not that it would count). I can't get the bin folder path nor load the file otherwise.. I need to feed the following method :

using(var file = System.IO.File.OpenRead(/* something */))


View 2 Replies

Trying To Get The Entity Framework Working In Medium Trust

Mar 8, 2010

I'm trying to get the entity framework working in medium trust. I've tried splitting the files and using a separate assembly but I seem to have one problem after another.I moved the EDMX to a separate assembly, which causes a single .dll to be outpit to the sites /Bin directory. I'm referencing this as below from web.config.

<add name="ApplicationDB" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Application.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> [code]...

Whenever I try to access one of the entity classes, I get an ArgumentException: 'An item with the same key has already been added.' It's critical this works with medium trust, but I seem to be running out of options.

View 2 Replies

NInject Work In Medium Trust Hosting?

Apr 11, 2010

I'm doing shared hosting with GoDaddy and I developed a sample ASP.NET MVC app using Castle Windsor and unfortunately, it didn't work in a medium trust setting. Specifically, I got this error: "[SecurityException: That assembly does not allow partially trusted callers"... etc. GoDaddy is sadly not flexible in their trust policy.

I'm not tied to Windsor and would like to try another one that will work under Medium Trust. I'd actually like to use NInject, but I've read people having mixed success. The only one I've read that works with no problem is Microsoft's Unity.My question is, does NInject work in medium trust? If not, what are my options?

View 2 Replies

Security :: How To Use SqlCacheDependency With Medium Level Trust

Aug 24, 2010

I am trying to use SqlCacheDependency in my web site.I got in touch with my hosting compnay and they said that they support cache but they set the trust level to medium and what I try to do needs full trust level whihch they cannot provide for me.

can someone show me a way or a code samples that use SqlCacheDependency with medium level trust?

the broker is enabled in the hosting sql server

this code raise the error that the hosting providers said that they cannot support in medium level:


I have the tables needed in my developer SQL server , but I don't know how or if I can set it in the hosting SQL server db

and this is my code to get the data from cache or from DB that works on my developer station:

If Cache("allitems") Is Nothing Then

View 2 Replies

Copyrights 2005-15, All rights reserved