.Net Code Monkey RSS 2.0
 Saturday, November 15, 2008

I have recently experienced a JavaScript errror incident when I started using Roles and Membership in a website for the first time.

IE6 reported a syntax error at Line 5 after adding a SiteMapDataSource and Asp.Net Menu controls to the page. The menu would not work I guess due to the JavaScript error.

A quick Google, led me to this page which led me to try adding the following code into my web config

  </system.web>
  
  <!-- Prevent JavaScript Errors, caused by web resource can't be accessed by current user. -->
  <location path="webresource.axd">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location> 

</configuration>

This appeared to remove the error, I am assuming by allowing the web resource JavaScript to be accessed by all users.

 

Saturday, November 15, 2008 10:54:42 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.Net | Asp.Net | Authorization | Config Files | Errors | JavaScript | Membership | Roles
 Saturday, April 12, 2008

I'm sure many of you are aware that you can override the connection string settings in your DataAccess layer of your web application with connection string settings in your Web.Config. We found this out recently and found it very useful in an intranet application at work recently. However this week one of the other developers required that he could override a setting the BusinessEntity layer of his application from the App.Config in the console layer.

A quick chat with Mr Google didn't turn up a solution for this, so with this in mind all three of us quickly tried to return a working solution. I'm going to try to give an example of what we did, incase it something others may find of use. First we create a solution with two class library projects within it. The first will simulate the DataAccess layer and the second will simulate the BusinessEntity layer in an application. In the BusinessEntity project we will create a reference to the DataAccess project.

Starting with the DataAccess project we will add an App.Config file by creating a setting called "MySetting" in the Settings tab of the project Properties. The setting scope will be set to Application.

This creates a new sectionGroup called applicationSettings and a new section in the App.Config file and places the new setting in their too.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" 
type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="Playground.ConfigurationOverride.DataAccess.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" /> </sectionGroup> </configSections> <applicationSettings> <Playground.ConfigurationOverride.DataAccess.Properties.Settings> <setting name="MySetting" serializeAs="String"> <value>Setting in DataAccess</value> </setting> </Playground.ConfigurationOverride.DataAccess.Properties.Settings> </applicationSettings> </configuration>

Next we will add a simple class to the DataAccess project with a single static method that will return the value of the setting we have just created.

using System;

namespace Playground.ConfigurationOverride.DataAccess
{
    public static class SettingsHelper
    {
        public static string GetMySetting()
        {
            return Properties.Settings.Default.MySetting;
        }
    }
}

Next we will create anothe simple class, SettingsGetter, in the but in the BusinessEntity layer this time. It will just return the value returned from the SettingsHelper class in the DataAccess layer.

using System;

namespace Playground.ConfigurationOverride.BusinessEntity
{
    public static class SettingsGetter
    {
        public static string GetDataAccessSettingValue()
        {
            return DataAccess.SettingsHelper.GetMySetting();
        }
    }
}
Next we need to create a presentation layer. So first off we will create a small web application and add it to the solution, and grab a reference to the BusinessEntity layer. Set the web site as the startup project. We will also add a Label to the default webform and a Button. In the Page_Load handler method populate the label text from the business entity method.
protected void Page_Load(object sender, EventArgs e)
 {
     uxSettingsLabel.Text = 
         Playground.ConfigurationOverride.BusinessEntity.SettingsGetter.GetDataAccessSettingValue();
 }

...and run the application, and allow the Web.Config file to be created. The value of the setting in the DataAccess App.Config file should be displayed.

 

More to follow soon...

Saturday, April 12, 2008 7:03:24 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
.Net | Asp.Net | C# | Config Files | XML
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Blogroll
 Clemens Vasters
 Harry Pierson
Passion * Technology * Ruthless Competence
 Joshua Flanagan
A .NET Software Developer
 Michael Schwarz's Blog
Developing applications on the Microsoft platform since Windows 3.1!
 Omar Shahine
Yet another Microsoft blogger
 Scot GU
Scott Guthrie lives in Seattle and builds a few products for Microsoft
 Scott Hanselman
Programming Life and the Zen of Computers
 Tom Mertens
Tom's corner
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
Duane Wingett
Sign In
Statistics
Total Posts: 26
This Year: 0
This Month: 0
This Week: 0
Comments: 28
Themes
Pick a theme:
All Content © 2010, Duane Wingett
DasBlog theme 'Business' created by Christoph De Baene (delarou)