Google
Web Netomatix

Silverlight Cross Domain Web Service Access Error - This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place

by Admin 9. March 2010 08:46

Here is some error that most of Silverlight developers run into at some point.


An error occurred while trying to make a request to URI 
'http://nave-pc/SilverGridWeb/GridDataService.asmx'.
This could be due to attempting to access a service in a cross-domain way 
without a proper cross-domain policy in place, or a policy that is unsuitable 
for SOAP services. You may need to contact the owner of the service to publish 
a cross-domain policy file and to ensure it allows SOAP-related 
HTTP headers to be sent. This error may also be caused by using internal types 
in the web service proxy without using the InternalsVisibleToAttribute attribute. 
Please see the inner exception for more details.

I had developed cross-domain access web services for Silverlight in the past and all work like a charm. This morning I ran into this issue again while developing a new web service for a new Silverlight application. I knew that I needed to add CrossDomain.xml or ClientAccessPolicy.xml at root of my web application. So I copied those files from existing application to this new one. To my surprise it did not resolve the issue. I tried all kind of tricks and options but nothing seemed to help. Finally I decided to look at Silverlight documentation and see if there is anything new that has been done for Silverlight 3. Last time I did this was for a Silverlight 2.0 application. I could not find anything different in the description of what needed to be done. But then there was something in the sample XML file content for these files that caught my eye and looked different that what I had.


<allow-from http-request-headers="SOAPAction" >

Notice the underlined section. Previously the value in the allowed headers used to be *. Well, that does not seem to work any more. So I replaced it and everything worked fine.

There are some other important points I am going to discuss in this post. A lot of users do not seem to be clear where these cross domain policy files should be placed.

Location of CrossDomain.xml and ClientAccessPolicy.xml

As the documentation states, these should be placed at the root of the application. Although the statement is very clear but it causes lot of confusion about what is root? There are two ways you create a site in IIS, Virtual Directory and Web Application. So if you have a web site foo.com created as a web site in IIS, then the folder containing the content of this site is root of the application. So your policy files go in that folder. If you have created a virtual directory Bar under this web site where your web service is hosted, then the root of the site is still foo.com and not foo.com/bar. To verify it, open IIS log of your application and look for entries for Crossdomain.xml and ClientAccessPolicy.xml. From those entries you can figure out where those files should be located. If the caller is not finding those files, then you should 404 errors in your log file. For example here are entries from my log file.


1.17.30.170 GET /clientaccesspolicy.xml - 80 - 1.17.30.162  404 0 2 1
1.17.30.170 GET /crossdomain.xml - 80 - 1.17.30.162 404 0 2 1

This is very important. If you are hosting your web service in a web application that is created as a virtual directory in Default Web Site then you need to copy these files in wwwroot folder or whatver folder is configured to be default folder for your IIS installation. Copying policy files in your virtual directory is not going to help. You can also verify the location by looking at traffic in fiddler for your web service access.

Content for CrossDomain.xml and ClientAccessPolicy.xml

I have copied the content of these two files below. These files work for me on my my servers for cross domain access from silverlight.

ClientAccessPolicy.xml


<?xml version="1.0" encoding="utf-8"?>
 <access-policy>
  <cross-domain-access>
  <policy>
  <allow-from http-request-headers="SOAPAction ">
  <domain uri="*"/>
  </allow-from>
  <grant-to>
  <resource path="/" include-subpaths="true"/>
  </grant-to>
  </policy>
 </cross-domain-access>
</access-policy>

CrossDomain.xml


<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
 <allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>

Views: 90

Tags: ,

Silverlight | Web Service

How to add paging to DataGrid in Silverlight

by Admin 24. February 2010 10:37

Download Sample Project (367.89 kb)

paging in silverlight datagrid

In one of my previous posts How to use DataGrid in Silverlight I showed a very simple usage where data grid was bound to a list of products. Now let us take one more step in customizing use of this data grid. When I executed my method to get list of products from AdventureWorks database, it returned me about 1000 records. And then datagrid was bound to that list, i got a huge page with grid showing all the records. I am sure at this point you are looking for way to add some kind of paging to your data grid so that user can navigate the list easily.

Silverlight has a control named DataPager that comes in very handy to add paging functionality to any control that you use to display lists. From the name is it obvious that this control is a pager. Following XAML shows how I added paging functionality to my datagrid.


<StackPanel x:Name="ContentStackPanel" Orientation="Vertical">
 <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" 
     Text="Products"/>
  <data:DataPager x:Name="ProductsPager" 
    PageSize="10" 
    DisplayMode="Numeric" 
    AutoEllipsis="True" 
    HorizontalAlignment="Left" />
  <data:DataGrid x:Name="ProductsGrid">
   <data:DataGrid.Columns>
   <data:DataGridTemplateColumn>
   <data:DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
   <StackPanel>
   <Button x:Name="UpdateButton" Content="Update" 
     Click="UpdateButton_Click"></Button>
   </StackPanel>
   </DataTemplate>
   </data:DataGridTemplateColumn.CellTemplate>
   </data:DataGridTemplateColumn>
   </data:DataGrid.Columns>
   </data:DataGrid>
</StackPanel>

You can read more about different ways to customize the display of datapager from the documentation. For this discussion you can see that I have set PageSize, DisplayMode, AutoEipsis and HorizontalAlignment properties of pager and the screen shot shows how it looks. I will talk more about customization of DataPager in detail in next post. For now I just want to keep it to simple use.

PageViewCollection

This is the collection object that drives the functionality for DataPager. In general you need a collection that implements IPagedViewCollection interface. No, you do not have to do any more implementation to get DataPager to work. We already have list of products obtained from previous web service call. You can simply wrap that list into PagedViewCollection object and set it as Source for DataPager object. And then set the source for DataGrid as this PagedViewCollection object and we are all set to go. Following code shows simple change I made in code from previous sample project.


void GetProductsCompleted(object sender, GetProductsCompletedEventArgs e)
{
 _products = e.Result;
 if (null != _products)
 {
  _pagedProductsView = new PagedCollectionView(_products);
  ProductsPager.Source = _pagedProductsView;
  ProductsGrid.ItemsSource = _pagedProductsView;
 }
}

Add References

PagedViewCollection is defined in System.Windows.Data assembly. So you will need to add reference to this assembly in your Silverlight project and then add using directive for the namespace in your source code to refer to the classes in this namespace and assembly.

Adding Paging to DataGrid in Silverlight is as easy as that.

Views: 228

Tags: ,

DataGrid | Silverlight

How to use DataGrid in Silverlight?

by Admin 5. February 2010 07:49
DataGrid is one of the most important control when it comes to displaying tabular kind of data. We all implement rendering of such data in some of table format. Developers who has been using ASP.Net are very familiar with controls like DataGrid and GridView. Good news is that there is equivalent DataGrid control for Silverlight as well. And for most part it is used the same way as you do in ASP.Net but with different syntax and different way of customizing display of it. In this post I am going to show a very plain and simple use of DataGrid control in Silverlight and then in subsequent posts I will build on top of this post to show some more advanced uses of DataGrid control.

Silverlight Tool Kit

You may already know this and already has it on your development machine, but I will mention it for sake of completness. You are going to need Silverlight Toolkit to use DataGrid. Yes, the control is not part of core Silverlight. Microsoft has developed it as part of the tool kit that has lot of usefull controls. You can read more about this tool kit and controls on the site. For now, down the toolkit and install it on your machine.

Reference assemblies

In your Silverlight project, you will need to add reference to System.Windows.Controls.Data assembly. This is the assembly where DataGrid control is defined. Now you can include DataGrid control on your XAML file. If you tried to add mark up like below on your page, you are going to get error telling you that DataGrid is not recoganized.


<DataGrid x:Name="MyGrid" />

You have to treat DataGrid control like a UserControl in ASP.Net where you have to specify a tag prefix and assembly on top of your page to indicate use of that control. In Silverllight you do this my including xml namespace tag for that silverlight control. In my case I have the following xmlns entry on my XAML file.


xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

This tells the application that I am going to use prefix data for the controls that are present in assembly System.Windows.Controls.Data. Based on this you can now add the following like of mark up on XAML file to include DataGrid on your page.


<data:DataGrid 
  x:Name="CommentsGrid" 
  Height="300" 
  AutoGenerateColumns="True" 
  IsReadOnly="True">
</data:Grid>

Attach To Data Source

Now that we have included DataGrid control on the page, we need to attach it to some data source to show some results. Very much like ASP.Net, you will attach an enumeration to this control. The difference is that here it is done through property name ItemSource. Following line of code shows how it is done for silverlight DataGrid control.


List _unmoderatedComments = new List();

void BindGrid()
{
 CommentsGrid.ItemsSource = _unmoderatedComments;
}

As you can see that DataGrid is bound to a List of Comment objects. So far so good, very much like your ASP.Net DataGrid or GridView.

Columns to Display

In the mark of DataGrid above, I have explcitly set AutoGenerateColumn property to true. This actually is default value. What this means is that when DataGrid is bound to the collection, it will generate column for each data field or property for the objects in the collection and display them. Thsi is same behavior you see in ASP.Net data grid.

Explcitly specifying Columns

When you are dealing with some real application most of the time you control the columns you want to display and how you want to display them. Silverlight DataGrid does allow you to do so. Fisrt, you will set AutoGenerateColumns property to false. Following mark up shows how you will specify the columns that you want to display.


<data:DataGrid x:Name="CommentsGrid" Height="300" 
  AutoGenerateColumns="False" IsReadOnly="True">
 <data:DataGrid.CellStyle>
  <Style TargetType="data:DataGridCell">
  <Setter Property="VerticalAlignment" Value="Top"></Setter>
  </Style>
 </data:DataGrid.CellStyle>
 <data:DataGrid.Columns>
  <data:DataGridTextColumn Header="Comment Date" 
    Binding="{Binding CommentDate}"></data:DataGridTextColumn>
  <data:DataGridTextColumn Header="Comment Text" Binding="{Binding Text}">
  <data:DataGridTextColumn.ElementStyle>
  <Style TargetType="TextBlock">
   <Setter Property="TextWrapping" Value="Wrap"/>
  </Style>
  </data:DataGridTextColumn.ElementStyle>
 </data:DataGridTextColumn>
 <data:DataGridTemplateColumn>
  <data:DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
    <StackPanel Orientation="Horizontal">
     <Button x:Name="ApprovedButton" Content="Approved" 
       Click="ApprovedButton_Click" Height="30" Margin="3"></Button>
     <Button x:Name="DeleteButton" Content="Delete" 
        Click="DeleteButton_Click" Height="30" Margin="3"></Button>
     <Button x:Name="SpamButton" Content="Mark Spam" 
       Click="SpamButton_Click" Height="30" Margin="3"></Button>
   </StackPanel>
   </DataTemplate>
  </data:DataGridTemplateColumn.CellTemplate>
 </data:DataGridTemplateColumn>
 </data:DataGrid.Columns>
</data:DataGrid>

You will need to add Columns section under your DataGrid control definition and then specify each column that you would want to display. And to bind the column to particular property or field, you will use Binding property. For this post I am going to keep the dicussion to simple binding of the column to property of the object. I will discuss more advanced use in subsequent posts. You can see it is very similar to how you are used to doing things in ASP.Net.

And to accomodate more customized view of the column, you will use DataGridTemplateColumn where you can layout the template of the view of that column. This is also similar to template column in ASP.Net.

More...

For this post I am going to leave this discussion to this simple display of data. I will be discussing more about use of Silverlight DataGrid in subsequent posts. This post should get you started with use of it now.

Views: 606

Tags: ,

DataGrid | Silverlight

How to add pushpin and datagrid to Bing Map Silverlight control

by Admin 6. January 2010 07:58
Bing map silverlight control sdk

In one of my earlier posts Convert IP Addresss To Geo Location, I discussed how you can query a web service or database to get geo-location of that internet service provider. Now what do you do with that geo-location or spatial information. For one of the current Data Visualization projects I am working on, I had to show these locations on the map as well. The application is a Silverlight application so obvious choice was to find a control or component that I could drop in silverlight. And you pretty much have the answer, Use Bing Map Silverlight Control.

In this post I am going to discuss some of the following topics.

  • How to use Bing Silverlight Map Control?
  • How to add push pins to bing map?
  • How to add legends or some text to Silverlight Bing Map?
  • How to add regular silverlight controls on Bing Map control?

The documentation for Bing Map Silverlight control is still maturing and lacks lot of details. So most of the discussion in this post is based on personal experience and conversations I had through news groups and forums.

Set up development enviroment

Before you can start developing your silverlight application using Bing Map Silverlight control, you will need to do following things.

  • Create a developer account at Bing portal
  • As part of registration process, you will also be required to a credential key that is used with each request that you send to Bing web service to access data.
  • Download Bing Map Control SDK and install on your development machine.

Create Project and lets roll

Microsoft has provided a good walk through on Creating a Basic Application Using the Silverlight Map Control. I will strongly recomment going through it if its first time for you in Bing Map development.

Adding PushPin to Bing Map

Now that you have a vanilla implementation of map showing in your application. Next I want to add indicztors on the map to show location of internet service providers for which I have geo corodinates. There are few ways you can do. The most basic thing that you need to keep in mind is that Bing Map control is like any other silverlight control and can act as a container for other silverlight control. That means that I can just draw any shapes or objects at given corodinates. Well, you got it. Bing Map SDK provides some of these indicator controls out of the box. And one of them is PushPin. So what you need to do is crate instances of PushPin objects, set their longitude and latitude and add them as children of map control. Following code snippet shows how I added a collection of PushPin objects to my map control.

foreach(var loc in locations)
{
	var pp = new Pushpin() 
	  {Location = new Location(loc.Latitude, loc.Longitude)};
	UserLocationsMap.Children.Add(pp);
}

Adding DataGrid to Bing Map

Next task I had to do was to provide some summary of the data on the map itself. More precisely, I wanted to show how many service provides from each country I have in my database. For demo purposes I just needed to show name and count. I decided to add a DataGrid to map to show this data. Later on I am going to handle click events in this grid to have some interaction with the map as well. Since I already knew where I wanted to place the grid and what columns needed to be shown, I could just add this through XAML file itself. Following XAML snippet from the application shows how I have added a text block and data grid to Bing Map control as children.


<m:Map CredentialsProvider="xxxxxxxxxx" Name="UserLocationsMap">
 <m:Map.Children>
  <o:ShadowText x:Name="MapTitleText" ForegroundTop="Black" ForegroundBottom="Orange"
      Text="ISP Locations" FontFamily="Verdana" FontSize="24"
      HorizontalAlignment="Left" Margin="20,75,50,10"/>
	<StackPanel x:Name="CountryListPanel" Margin="20,250,50,10" Orientation="Vertical">
	 <data:DataGrid x:Name="CountryCountGrid" Width="150" Height="250"
	   AutoGenerateColumns="False" HorizontalAlignment="Left">
	  <data:DataGrid.Columns>
	   <data:DataGridTextColumn Header="Country" Width="SizeToHeader" Binding="{Binding Name}" />
	   <data:DataGridTextColumn Header="Count" Width="SizeToHeader" Binding="{Binding Count}" />
	  </data:DataGrid.Columns>
	 </data:DataGrid>
	</StackPanel>
	</m:Map.Children>
</m:Map>

Postioning on Map control

This is something you will have to play very close attention to. There is a difference between how controls or objects placed on map control. You must have noticed that when I added PushPin to map, I used longitude and latitude to position them on the map. But when I added DataGrid and ShadowText controls, I used Margin to control the placement. Most of the indiccator or layer objects that are provided in Bing Map SDK use gro-location values (longitude and latitude) to place object. But when you add regular silverlight controls on map, then you will control the position using Margin relative to origin of map control.

Views: 1179

Tags: ,

Silverlight | Bing Map

How to programatically set meta tags on ASP.Net page

by Admin 5. November 2009 06:34

When we are creating a web site, one of the main goal we all have is that out site should be listed on first page of search engines like Google, Bing, Yahoo, Baidu etc. As we all know that in SEO world, one of the first thing we all look for in the page is meta tags in header of the page. In the past there was no direct way to set the meta tags on a page programatically when developing ASP.Net web site. We all used the work around of adding metaelements in header element of the page. You can read my previous post Adding meta tags to asp.net page dynamically about that technique. With ASP.Net 4.0 microsoft has introduced following two properties on that allow you to set the meta tags on a page.

  • MetaDescription
  • MetaKeywords

Following code snippet shows how it is used in your code.


public partial class _Default : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
  SetMetaTags();
 }
 private void SetMetaTags()
 {
  Title = "Hello Meta";
  MetaDescription = "This is description of my ASP.Net 4.0 page.";
  MetaKeywords = "ASP.Net,.Net4.0,Meta";
 }
}

And it works. You can see from the source of the page as shown below.

<head>
<title>Hello Meta</title>
<meta name="description" content="This is description of my ASP.Net 4.0 page." />
<meta name="keywords" content="ASP.Net,.Net4.0,Meta" />
</head>

Views: 1190

Tags:

.Net | ASP.Net

Where is Documents and Settings folder in Windows 7

by Admin 10. August 2009 05:26

If you try to access Documents and Settings folder in Windows 7, you will get the following message box thrown at you.

[Window Title]
Location is not available

[Content]
C:\Documents and Settings is not accessible.

Access is denied.

[OK]

First, Documents and Settings folder is not visible when you look in system drive. In my previous post How to set folder view options, i discussed how you can change the options to make system files and folders visible. Now you have the folder visible but its not accessible even when you are logged in as administrator. Now Documents and Settings is actually a link to another folder Users in your system drive. Yes, this is the folder where all the users related data is stored. Under this folder you will find folders for all users who have ever logged into the system and some of default system users as well. You can access individual users folders. This is where you will find folders like My Documents, My pictures, Favorites etc. You will notice a lot of these folders have a blue curved up-arrow icon with it. Yes, this indicates that these folders are shortcut or links to actual physical location of the folders. And you will not be able to access these folder from these links. If you have change the folder options to view hidden files and folders, you will be able to see actual folders like My Documents, Local Settings etc. You can access these folders to get to physical location of data. One other important folder that you need to know about it Local Settings. This is also a link to actual location in user folder. There is no hidden Local Settings folder. You will find another hidden folder AppData. Click on this folder and you will find following sub-folders.

  • Local
  • LocalLow
  • Roaming

This is where you will find the folders that you are used to seeing under Local Settings and Application Data folders. In general you if you are looking for folders that used to be in Documents and Settings folder, look in the following folder (assuming you have installed operating system in C drive).

C:\Users\{user name}

This little piece of information about folder structure in Windows 7 should help you get started in exploring more folders that you may otherwise think have been removed since Windows XP.

Views: 4864

Tags:

Windows 7

How to add remove programs in Windows 7

by Admin 9. August 2009 09:12

If you are moving from Windows Vista to Windows 7, then there is no much change in how to add remove programs and applications. But for users migrating from Windows XP, there is some change in how Add/Remove Programs works in Windows 7. Following is step by procedure that will show to add or remove programs in Windows 7.

Add/Remove Programs in Windows 7

  1. Click on the Start button and you will notice Control Panel item in right pane. See the picture below.
  2. Click on Control Panel option and it will bring up new dialog box Adjust your computer's settings. There is a option named Programs. Click on it.
  3. Clicking on Programs option will bring up new window that has section Programs and Features as shown below. You will notice that this section has few moe options to perform various tasks related to adding or removing programs.
    add remove programs in windows 7
    • Uninstall a program

      Clicking on this option will bring up list of all programs that are currently installed on your machine. Click on the one that you want to uninstall or update, click on that program. And then click on Uninstall/Change link in the bar to perform the action.

    • Turn Windows features on or off

      Clicking on this option will bring up list of all windows features that are currently turned on or are available to be turned on. You can go through the list of features and decide which ones you need to alter. Usually you will not need to access this option unless you are developing some applications or need to turn on or off or some windows behavior.

    • View installed updates

      Clicking on this option will bring up list of all the updates to various windows components have been installed on your machine. You will notice that they have been nicely arranged by component categories. If you know that any of these updates is causing unwanted effects, you can click on that update and then click on Uninstall to remove that update.

Views: 10192

Tags:

Windows 7

How to install and activate IIS on Windows 7

by Admin 9. August 2009 09:04

After installing Windows 7 Ultimate on my development workstation, it was time to install my development tools like SQL Server, Visual Studio, Fiddler and all that good stuff. If you are doing web development, you have to make sure that you have IIS and ASP.Net installed and activated on your machine. If you are moving to Windows 7 from Windows XP, you will notice that somethings and wizards to install IIS have changed in Windows 7. Following step by step procedure will explain how to install IIS.

Like Windows XP, IIS installation is still part of Windows feature turning on or off. In my previous post How to add remove programs in Windows 7 I described how you can add or remove programs. In the section Turn Windows features on or off, I mentioned that this was the place where you will toggle windows features. IIS is part of windows features. So this is the place where you will be turning on some switches.

  • Bring up Turn Windows features on or off dialog box. And you will notice an item in the list named Internet Information Services. This is what you will need to turn on.
  • Expand this item in the tree and you will see three nodes for this item in the tree, FTP Serer, Web Management Tools and World Wide Web Services. You can expand these three nodes to see what all features are available and what you need to turn on.

FTP Server

If you are doing any development related to FTP service or want to turn your machine into a FTP server, then you will need to check FTP Service option on. You can turn on FTP Extensibility if you want to do some custom FTP publishing using custom extension. Otherwise you can leave it off.

Web Management Tools

By default Windows 7 does not install IIS management console or any other tools to manage web applications. This is the node where you will turn on components and features to manage web applications.

World Wide Web Services

This is important part of IIS installation. By default ASP.Net and ASP is not enabled in IIS. It will only serve static content. You will need to turn them on under Application Development Features. When you expand this node, you will notice options for ASP,ASP.Net,CGI etc. Depending on your development and deployment needs you can turn them on or off accordingly. If you do not turn on these features, you will get server run time errors or the dynamic content will not be served.

Other important feature under World Wide Web Services is Performance Features.

To optimize and reduce download time of your pages on client browsers, it is important that you compress as much content as possible. You can turn that feature on or off from this Performance Features option. You will notice that Static Content Compression is turned on by default.

Last node under World Wide Web Services is Security and the most important part of your web application to ensure security of your content and data.

From this node you can control what security features are turned on off for your applications. You will need to use this section depending on needs of your individual applications.

Need to restart?

In the previous build of Windows 7, i did not have to restart my machine to turn on IIS after making the changes. But when i tried this with latest RTM release on my laptop, the configuration change did not take into affect immediately. And the wizard did not prompt me to restart my machine either. but after I restarted my machine, IIS was enabled and I was able to serve ASP.Net applications from the machine. So, if you run into similar situation, try restarting your machine.

Views: 3948

Tags: ,

Windows 7 | IIS

Windows 7 Installation on Development workstation

by Admin 8. August 2009 21:33

I have been involved with beta testing of Windows 7 for quite some time now. Yes, I am one of those who did not use Windows Vista because of all the stories you heard about it. I bought a new Dell Latitude laptop two months ago and even on that I opted for installation of Windows XP. I have been happy with Windows 7 performance since day 1. The beta release of the operating system used to run much better than retail version of Windows XP. So I have been waiting for Windows 7 to go RTM. Now finally it has been made available for download from MSDN as well. I spent my weekend to upgrade all my development workstations from Windows XP to Windows 7. Needless to say all the installations went very smooth. I did not run into any major issues with. On of my older Dell Precision laptops it did not install latest drivers for NVIDIA video card and did not recoganize my wireless card as well. But that was not a big issue. I was able to quickly use my driver CD for Windows XP for my laptop and got all taken care of.

My overall experience has been satisfactory with installation of Windows 7 on desktop as well as laptops. Now I am working on installing my development tools like SQL Server, Visual Studio etc. And I will post my experience about those as well in next few days.

Views: 851

Tags:

Windows 7

ASP.Net version set to 4.0 in IIS manager on Windows XP

by Admin 6. August 2009 06:07

I have been working with VS2010 and ASP.Net 4.0 for quite some time now. Every time i create a web application, I just use the handy feature of Visual Studio of creating virtual directory for web application. Last week I was manually creating virtual directory for a web application using IIS manager. Since the application was targeting ASP.Net 2.0, so from ASP.Net tab of IIS, I selected V2.0 framework. Now there is a confirmation dialog box that comes up when you change ASP.Net framework.

Changing the Framework version requires a restart of the W3SVC service. Alternatively, you can change the Framework version without restarting the W3SVC service by running: aspnet_regiis.exe -norestart -s IIS-Viirtual-Path Do you want to continue (this will change the Framework version and restart the W3SVC service)?

Everything is good so far. Moment i accessed the application in browser, I got the following error message.

Server Error in '/Foo' Application.
The application domain or application pool is currently running version 4.0 or later of the .NET Framework. This can occur if IIS settings have been set to 4.0 or later for this Web application, or if you are using version 4.0 or later of the ASP.NET Web Development Server. The <compilation> element in the Web.config file for this Web application does not contain the required 'targetFrameworkMoniker' attribute for this version of the .NET Framework (for example, '<compilation targetFrameworkMoniker=".NETFramework,Version=v4.0">'). Update the Web.config file with this attribute, or configure the Web application to use a different version of the .NET Framework.

I was little surprised because I never configured virtual directory for this application to use ASP.Net 4.0. I fired up IIS manager and went to ASP.Net tab. There it was, the application was configured to use ASP.Net 4.0. So I changed it back to use ASP.Net 2.0. Accessed the application in browser and got the same error again. I experimented with the dropdown box for ASP.Net version in IIS manager. The application will get configured to use ASP.Net 4.0 no matter what option I picked from the dropdown box. It seems that this is some bug in beta version of Visual Studio 2010 installation.

For now the work around I have been using is to let Visual Studio create virtual directory for my web application. It targets the correct ASP.Net version and modifies IIS meta data correctly.

Views: 841

Tags: , ,

ASP.Net | Visual Studio