<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Adam Salvo (z) - Technology|Asp.Net MVC</title>
    <link>http://blog.salvoz.com/</link>
    <description>newtelligence powered</description>
    <language>en-us</language>
    <copyright>Adam Salvo</copyright>
    <lastBuildDate>Fri, 09 Jul 2010 18:02:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>adam@salvoz.com</managingEditor>
    <webMaster>adam@salvoz.com</webMaster>
    <item>
      <trackback:ping>http://blog.salvoz.com/Trackback.aspx?guid=64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b</trackback:ping>
      <pingback:server>http://blog.salvoz.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.salvoz.com/PermaLink,guid,64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b.aspx</pingback:target>
      <dc:creator>Adam Salvo</dc:creator>
      <wfw:comment>http://blog.salvoz.com/CommentView,guid,64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b.aspx</wfw:comment>
      <wfw:commentRss>http://blog.salvoz.com/SyndicationService.asmx/GetEntryCommentsRss?guid=64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>Today’s Task:</strong>
        </p>
        <p>
Add some Silverlight content to an existing Asp.Net MVC project. The MVC project contains
the standard CRUD for the application, while the Silverlight is meant to provide rich
visualization of the data.
</p>
        <p>
          <strong>Prerequisites:</strong>
        </p>
        <ul>
          <li>
VS 2010 
</li>
          <li>
An existing Asp.Net MVC 2.0 project 
</li>
          <li>
Expression Blend 4.0 (installs Silverlight 4 and Silverlight 4 SDK) 
</li>
          <li>
            <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=eff8a0da-0a4d-48e8-8366-6ddf2ecad801&amp;displaylang=en">Silverlight
4.0 tools</a> for Visual Studio 2010</li>
        </ul>
        <p>
          <strong>Creating the Project:</strong>
        </p>
        <p>
As stated in the opening and prerequisites, I am starting with an existing Asp.Net
MVC application. You should have Blend 4 installed, and have also installed the Silverlight
4 tools for Visual Studio.
</p>
        <p>
1) Right click on your web project and choose add new item (ctrl+shift+a). From the
add new Item window, click on Silverlight under Installed Templates and then select
the Silverlight Application. Name your Silverlight application appropriately. In my
example, I have named my project DataVisualization. Click Add
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb.png" width="244" height="171" />
          </a>
        </p>
        <p>
2) The next screen that comes up is the “Add Silverlight Application” screen. I accepted
the defaults with the follow exception, I changed the location from being a sub folder
of my MVC application to one level higher. The destination folder, ClientBin is still
created in your MVC application. Make sure that you select Silverlight 4 for the version.
Finally click Add.
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_1.png" width="244" height="225" />
          </a>
        </p>
        <p>
3) You should now have the following in your solution.
</p>
        <ul>
          <li>
Your existing Asp.Net MVC application 
</li>
          <li>
A new Silverlight 4 application named DataVisualization 
</li>
          <li>
A DataVisualizationTestPage.aspx in your MVC application 
</li>
          <li>
A DataVisualizationTestPage.html in your MVC application 
</li>
          <li>
A Silverlight.js in your MVC application</li>
        </ul>
        <p>
We will eventually remove the test pages, but for now we will leave them so that they
can serve their intended purpose. 
</p>
        <p>
4) Build the solution. You should see a DataVisualization.xap added to the ClientBin
folder in your MVC application.
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_2.png" width="244" height="235" />
          </a>  
</p>
        <p>
5) Right click on DataVisualization.html and choose view in browser. You should see
an empty page in the browser, but get no errors. Right clicking anywhere in the browser
window should bring up the Silverlight context menu.
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_3.png" width="244" height="208" />
          </a>
        </p>
        <p>
          <strong>
          </strong> 
</p>
        <p>
          <strong>Integrate the Silverlight Application</strong>
        </p>
        <p>
In this stage, we are going to make our new Silverlight application appear like it’s
part of the rest of our MVC application. Right now if you browse to it, it doesn’t
look like its part of anything. We also want to be able to allow our users to navigate
thru our web application so we need our existing menu to show up.
</p>
        <p>
1) Either create a new controller/view or re-use an existing controller/view in your
MVC application to house your Silverlight application. I’m going to reuse an existing
controller called Dashboard, which has one view, Index.
</p>
        <p>
2) Open up your view, and the DataVisualizationTestPage.aspx file. We need to move
some stuff over to our view so it displays our Silverlight application. I have some
pre existing styling and layout defined, so my view is going to look differently from
yours. I also store my java script files in a specific location, so I will be moving
the included silverlight.js as well. The screen shot below shows what I am starting
with in the view for reference.
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_4.png" width="244" height="121" />
          </a>
        </p>
        <p>
3) If you don’t have any existing standard for your JavaScript, you can place the
two script tags from the test page somewhere before the reference to the Silverlight
object. For example, place the two script tags just below the second content place
holder. Next, copy the form tag inclusive and paste it into your view. For me, I pasted
it into my div tag that I have setup to control my formatting. In the screen shots
below you can see my view, and resulting web page. We still have an empty Silverlight
control, but now it looks like its actually part of our website. 
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_5.png" width="343" height="186" />
          </a>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_14.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_6.png" width="244" height="187" />
          </a>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
4) Remove the DataVisualizationTest.aspx page, but keep the HTML page as we will need
it in the next section.
</p>
        <p>
          <strong>Working with Blend</strong>
        </p>
        <p>
The final step is to begin adding content to our Silverlight application. For this
we are going to switch to Blend to make sure that we are able to work in both tools. 
</p>
        <p>
1) Start up Blend and choose to open an existing project. Browse to the location of
your DataVisualization project (folder that contains DataVisualization.csproj) and
open it. You should see the content of your project listed on the left under the project
tab (assuming default Blend layout) and the empty MainPage.xaml in the middle. Notice
that we have a solution called DataVisualization, and that I did not open up my existing
MVC application solution. 
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_7.png" width="244" height="150" />
          </a>
        </p>
        <p>
2) Go to Project in the tool bar, and click Run Project (or press F5). You will see
that our empty MainPage is shown using the DataVisualizationTest.html page, and that
we are using the local Asp.Net development server. This is good enough for me. I’m
hoping that with this setup I can work independently of my MVC application, and more
importantly, a designer would be able to work independently as well. When deploying
my application to production, I can remove the DataVisualizationTest.html page. 
</p>
        <p>
          <a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_18.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_8.png" width="244" height="125" />
          </a>
        </p>
        <p>
3) TFS Integration – At this point I can’t figure out how to get Blend to work with
TFS. It’s possible since I downloaded the trial version that it does not include TFS
support, or I need to install Team Explorer on top of Blend. For now I can use the
Explorer add-in to get by. 
</p>
        <p>
          <strong>Conclusion</strong>
        </p>
        <p>
At this point we have a functioning Silverlight application, integrated with an existing
Asp.Net MVC application. We are able to work independently of the web application
in Blend and vice-versa. This is my first attempt at this type of solution, so I will
post a follow-up in the future to report back how well it worked, and if I needed
to make any changes. 
</p>
        <img width="0" height="0" src="http://blog.salvoz.com/aggbug.ashx?id=64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.salvoz.com">Adam Salvo</a>. 
</body>
      <title>Silverlight in an Existing Asp.Net MVC Project</title>
      <guid isPermaLink="false">http://blog.salvoz.com/PermaLink,guid,64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b.aspx</guid>
      <link>http://blog.salvoz.com/2010/07/09/SilverlightInAnExistingAspNetMVCProject.aspx</link>
      <pubDate>Fri, 09 Jul 2010 18:02:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;Today’s Task:&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
Add some Silverlight content to an existing Asp.Net MVC project. The MVC project contains
the standard CRUD for the application, while the Silverlight is meant to provide rich
visualization of the data.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Prerequisites:&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
VS 2010 
&lt;li&gt;
An existing Asp.Net MVC 2.0 project 
&lt;li&gt;
Expression Blend 4.0 (installs Silverlight 4 and Silverlight 4 SDK) 
&lt;li&gt;
&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=eff8a0da-0a4d-48e8-8366-6ddf2ecad801&amp;amp;displaylang=en"&gt;Silverlight
4.0 tools&lt;/a&gt; for Visual Studio 2010&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;Creating the Project:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
As stated in the opening and prerequisites, I am starting with an existing Asp.Net
MVC application. You should have Blend 4 installed, and have also installed the Silverlight
4 tools for Visual Studio.
&lt;/p&gt;
&lt;p&gt;
1) Right click on your web project and choose add new item (ctrl+shift+a). From the
add new Item window, click on Silverlight under Installed Templates and then select
the Silverlight Application. Name your Silverlight application appropriately. In my
example, I have named my project DataVisualization. Click Add
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb.png" width="244" height="171"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
2) The next screen that comes up is the “Add Silverlight Application” screen. I accepted
the defaults with the follow exception, I changed the location from being a sub folder
of my MVC application to one level higher. The destination folder, ClientBin is still
created in your MVC application. Make sure that you select Silverlight 4 for the version.
Finally click Add.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_1.png" width="244" height="225"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
3) You should now have the following in your solution.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Your existing Asp.Net MVC application 
&lt;li&gt;
A new Silverlight 4 application named DataVisualization 
&lt;li&gt;
A DataVisualizationTestPage.aspx in your MVC application 
&lt;li&gt;
A DataVisualizationTestPage.html in your MVC application 
&lt;li&gt;
A Silverlight.js in your MVC application&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We will eventually remove the test pages, but for now we will leave them so that they
can serve their intended purpose. 
&lt;/p&gt;
&lt;p&gt;
4) Build the solution. You should see a DataVisualization.xap added to the ClientBin
folder in your MVC application.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_2.png" width="244" height="235"&gt;&lt;/a&gt;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
5) Right click on DataVisualization.html and choose view in browser. You should see
an empty page in the browser, but get no errors. Right clicking anywhere in the browser
window should bring up the Silverlight context menu.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_3.png" width="244" height="208"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Integrate the Silverlight Application&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this stage, we are going to make our new Silverlight application appear like it’s
part of the rest of our MVC application. Right now if you browse to it, it doesn’t
look like its part of anything. We also want to be able to allow our users to navigate
thru our web application so we need our existing menu to show up.
&lt;/p&gt;
&lt;p&gt;
1) Either create a new controller/view or re-use an existing controller/view in your
MVC application to house your Silverlight application. I’m going to reuse an existing
controller called Dashboard, which has one view, Index.
&lt;/p&gt;
&lt;p&gt;
2) Open up your view, and the DataVisualizationTestPage.aspx file. We need to move
some stuff over to our view so it displays our Silverlight application. I have some
pre existing styling and layout defined, so my view is going to look differently from
yours. I also store my java script files in a specific location, so I will be moving
the included silverlight.js as well. The screen shot below shows what I am starting
with in the view for reference.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_4.png" width="244" height="121"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
3) If you don’t have any existing standard for your JavaScript, you can place the
two script tags from the test page somewhere before the reference to the Silverlight
object. For example, place the two script tags just below the second content place
holder. Next, copy the form tag inclusive and paste it into your view. For me, I pasted
it into my div tag that I have setup to control my formatting. In the screen shots
below you can see my view, and resulting web page. We still have an empty Silverlight
control, but now it looks like its actually part of our website. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_5.png" width="343" height="186"&gt;&lt;/a&gt; &lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_6.png" width="244" height="187"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
4) Remove the DataVisualizationTest.aspx page, but keep the HTML page as we will need
it in the next section.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Working with Blend&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The final step is to begin adding content to our Silverlight application. For this
we are going to switch to Blend to make sure that we are able to work in both tools. 
&lt;/p&gt;
&lt;p&gt;
1) Start up Blend and choose to open an existing project. Browse to the location of
your DataVisualization project (folder that contains DataVisualization.csproj) and
open it. You should see the content of your project listed on the left under the project
tab (assuming default Blend layout) and the empty MainPage.xaml in the middle. Notice
that we have a solution called DataVisualization, and that I did not open up my existing
MVC application solution. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_7.png" width="244" height="150"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
2) Go to Project in the tool bar, and click Run Project (or press F5). You will see
that our empty MainPage is shown using the DataVisualizationTest.html page, and that
we are using the local Asp.Net development server. This is good enough for me. I’m
hoping that with this setup I can work independently of my MVC application, and more
importantly, a designer would be able to work independently as well. When deploying
my application to production, I can remove the DataVisualizationTest.html page. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.salvoz.com/content/binary/WindowsLiveWriter/SilverlightinanExistingAsp.NetMVCProject_8B5E/image_thumb_8.png" width="244" height="125"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
3) TFS Integration – At this point I can’t figure out how to get Blend to work with
TFS. It’s possible since I downloaded the trial version that it does not include TFS
support, or I need to install Team Explorer on top of Blend. For now I can use the
Explorer add-in to get by. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
At this point we have a functioning Silverlight application, integrated with an existing
Asp.Net MVC application. We are able to work independently of the web application
in Blend and vice-versa. This is my first attempt at this type of solution, so I will
post a follow-up in the future to report back how well it worked, and if I needed
to make any changes. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.salvoz.com/aggbug.ashx?id=64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.salvoz.com"&gt;Adam Salvo&lt;/a&gt;. </description>
      <comments>http://blog.salvoz.com/CommentView,guid,64b6ac5d-b2fe-4ff2-afeb-4449adbfb03b.aspx</comments>
      <category>Technology/Asp.Net MVC</category>
      <category>Technology/Programming</category>
      <category>Technology/Silverlight</category>
      <category>Technology/Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://blog.salvoz.com/Trackback.aspx?guid=19b31023-5c88-4742-a7f2-22cdafea11de</trackback:ping>
      <pingback:server>http://blog.salvoz.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.salvoz.com/PermaLink,guid,19b31023-5c88-4742-a7f2-22cdafea11de.aspx</pingback:target>
      <dc:creator>Adam Salvo</dc:creator>
      <wfw:comment>http://blog.salvoz.com/CommentView,guid,19b31023-5c88-4742-a7f2-22cdafea11de.aspx</wfw:comment>
      <wfw:commentRss>http://blog.salvoz.com/SyndicationService.asmx/GetEntryCommentsRss?guid=19b31023-5c88-4742-a7f2-22cdafea11de</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <p>
        </p>
        <p>
Back in March, I posted about <a href="http://blog.salvoz.com/2009/03/14/PartialSSLAndAuthorizationWithAspNetMVC.aspx">creating
a custom authorization filter</a> to enable Partial SSL. While using the filter on
an application I was porting to Windows Azure, I discovered a bug, which has led me
to revisit my implementation. Here is the original code.
</p>
        <div id="codeSnippetWrapper">
          <div id="codeSnippet" class="csharpcode">
            <pre class="alt">
              <span id="lnum1" class="lnum">
              </span>
            </pre>
          </div>
          <div id="codeSnippetWrapper">
            <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum1"> 1:</span>
                <span style="color: #0000ff">public</span>
                <span style="color: #0000ff">class</span> RequireSslFilter:AuthorizeAttribute</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum2"> 2:</span> {</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum3"> 3:</span>
                <span style="color: #0000ff">protected</span>
                <span style="color: #0000ff">override</span>
                <span style="color: #0000ff">bool</span> AuthorizeCore(HttpContextBase
httpContext)</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum4"> 4:</span> {</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum5"> 5:</span>
                <span style="color: #0000ff">if</span> (httpContext.Request.IsLocal
== <span style="color: #0000ff">false</span> &amp;&amp; httpContext.Request.IsSecureConnection
== <span style="color: #0000ff">false</span>)</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum6"> 6:</span> httpContext.Response.Redirect(httpContext.Request.Url.ToString().ToLower().Replace(<span style="color: #006080">"http"</span>, <span style="color: #006080">"https"</span>));</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum7"> 7:</span>  </pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum8"> 8:</span>
                <span style="color: #0000ff">return</span>
                <span style="color: #0000ff">base</span>.AuthorizeCore(httpContext);</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum9"> 9:</span> }</pre>
              <!--CRLF-->
              <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
                <span style="color: #606060" id="lnum10"> 10:</span> }</pre>
              <!--CRLF-->
            </div>
          </div>
        </div>
        <p>
 
</p>
        <p>
As you can see, I’m calling base.AuthorizeCore at the end, which is what you usually
do when overriding a method. However, since the purpose of he Authorize Filter is
to, well authorize, the call to base.AuthorizeCore will return false if the user is
not authenticated. This is a problem because you might not be authenticated at the
time that this filter runs. 
</p>
        <p>
The reason I chose to use the Authorize Filter, is because it’s called before any
other filter, as explained by <a href="http://haacked.com/archive/2008/08/14/aspnetmvc-filters.aspx">Phill
Haack</a>. At first I thought about removing the call to the base.AuthorzieCore, but
that seemed more like a hack, then a correct solution. Digging deeper, I discovered
that the AuthorizeAttribute that I am inheriting from, implements the IAuthorizeFilter,
which requires you implement the OnAuthorization method. So instead of inheriting
from AuthorizeAttribute, I could just implement IAuthorizeFilter.
</p>
        <p>
However, someone already did it for me. In the <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471">Asp.Net
MVC futures project</a>, released with the Asp.Net MVC RTM source, there is a RequireSSL
attribute ready to use. The future’s project has more functionality then mine, allowing
for the option to redirect or throw an exception. It’s nice to see I was on the right
track at least.
</p>
        <p>
RequireSSL Attribute from Asp.Net MVC Futures:
</p>
        <div id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum1"> 1:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">void</span> OnAuthorization(AuthorizationContext
filterContext) {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum2"> 2:</span>
              <span style="color: #0000ff">if</span> (filterContext
== <span style="color: #0000ff">null</span>) {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum3"> 3:</span>
              <span style="color: #0000ff">throw</span>
              <span style="color: #0000ff">new</span> ArgumentNullException(<span style="color: #006080">"filterContext"</span>);</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum4"> 4:</span> }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum5"> 5:</span>  </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum6"> 6:</span>
              <span style="color: #0000ff">if</span> (!filterContext.HttpContext.Request.IsSecureConnection)
{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum7"> 7:</span>
              <span style="color: #008000">//
request is not SSL-protected, so throw or redirect</span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum8"> 8:</span>
              <span style="color: #0000ff">if</span> (Redirect)
{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum9"> 9:</span>
              <span style="color: #008000">//
form new URL</span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum10"> 10:</span> UriBuilder
builder = <span style="color: #0000ff">new</span> UriBuilder() {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum11"> 11:</span> Scheme
= <span style="color: #006080">"https"</span>,</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum12"> 12:</span> Host
= filterContext.HttpContext.Request.Url.Host,</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum13"> 13:</span>
              <span style="color: #008000">//
use the RawUrl since it works with URL Rewriting</span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum14"> 14:</span> Path
= filterContext.HttpContext.Request.RawUrl</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum15"> 15:</span> };</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum16"> 16:</span> filterContext.Result
= <span style="color: #0000ff">new</span> RedirectResult(builder.ToString());</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum17"> 17:</span> }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum18"> 18:</span>
              <span style="color: #0000ff">else</span> {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum19"> 19:</span>
              <span style="color: #0000ff">throw</span>
              <span style="color: #0000ff">new</span> HttpException((<span style="color: #0000ff">int</span>)HttpStatusCode.Forbidden,
MvcResources.RequireSslAttribute_MustUseSsl);</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum20"> 20:</span> }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum21"> 21:</span> }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #606060" id="lnum22"> 22:</span> }</pre>
            <!--CRLF-->
          </div>
        </div>
        <img width="0" height="0" src="http://blog.salvoz.com/aggbug.ashx?id=19b31023-5c88-4742-a7f2-22cdafea11de" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.salvoz.com">Adam Salvo</a>. 
</body>
      <title>Partial SSL and Authorization with Asp.Net MVC – Revisited</title>
      <guid isPermaLink="false">http://blog.salvoz.com/PermaLink,guid,19b31023-5c88-4742-a7f2-22cdafea11de.aspx</guid>
      <link>http://blog.salvoz.com/2009/04/25/PartialSSLAndAuthorizationWithAspNetMVCRevisited.aspx</link>
      <pubDate>Sat, 25 Apr 2009 21:08:27 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Back in March, I posted about &lt;a href="http://blog.salvoz.com/2009/03/14/PartialSSLAndAuthorizationWithAspNetMVC.aspx"&gt;creating
a custom authorization filter&lt;/a&gt; to enable Partial SSL. While using the filter on
an application I was porting to Windows Azure, I discovered a bug, which has led me
to revisit my implementation. Here is the original code.
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; RequireSslFilter:AuthorizeAttribute&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt; 2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt; 3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; AuthorizeCore(HttpContextBase
httpContext)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt; 4:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt; 5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (httpContext.Request.IsLocal
== &lt;span style="color: #0000ff"&gt;false&lt;/span&gt; &amp;amp;&amp;amp; httpContext.Request.IsSecureConnection
== &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt; 6:&lt;/span&gt; httpContext.Response.Redirect(httpContext.Request.Url.ToString().ToLower().Replace(&lt;span style="color: #006080"&gt;"http"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"https"&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt; 7:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt; 8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.AuthorizeCore(httpContext);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt; 9:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt; 10:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can see, I’m calling base.AuthorizeCore at the end, which is what you usually
do when overriding a method. However, since the purpose of he Authorize Filter is
to, well authorize, the call to base.AuthorizeCore will return false if the user is
not authenticated. This is a problem because you might not be authenticated at the
time that this filter runs. 
&lt;/p&gt;
&lt;p&gt;
The reason I chose to use the Authorize Filter, is because it’s called before any
other filter, as explained by &lt;a href="http://haacked.com/archive/2008/08/14/aspnetmvc-filters.aspx"&gt;Phill
Haack&lt;/a&gt;. At first I thought about removing the call to the base.AuthorzieCore, but
that seemed more like a hack, then a correct solution. Digging deeper, I discovered
that the AuthorizeAttribute that I am inheriting from, implements the IAuthorizeFilter,
which requires you implement the OnAuthorization method. So instead of inheriting
from AuthorizeAttribute, I could just implement IAuthorizeFilter.
&lt;/p&gt;
&lt;p&gt;
However, someone already did it for me. In the &lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471"&gt;Asp.Net
MVC futures project&lt;/a&gt;, released with the Asp.Net MVC RTM source, there is a RequireSSL
attribute ready to use. The future’s project has more functionality then mine, allowing
for the option to redirect or throw an exception. It’s nice to see I was on the right
track at least.
&lt;/p&gt;
&lt;p&gt;
RequireSSL Attribute from Asp.Net MVC Futures:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAuthorization(AuthorizationContext
filterContext) {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt; 2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (filterContext
== &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt; 3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span style="color: #006080"&gt;"filterContext"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt; 4:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt; 5:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt; 6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!filterContext.HttpContext.Request.IsSecureConnection)
{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt; 7:&lt;/span&gt; &lt;span style="color: #008000"&gt;//
request is not SSL-protected, so throw or redirect&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt; 8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Redirect)
{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt; 9:&lt;/span&gt; &lt;span style="color: #008000"&gt;//
form new URL&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt; 10:&lt;/span&gt; UriBuilder
builder = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UriBuilder() {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt; 11:&lt;/span&gt; Scheme
= &lt;span style="color: #006080"&gt;"https"&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt; 12:&lt;/span&gt; Host
= filterContext.HttpContext.Request.Url.Host,&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt; 13:&lt;/span&gt; &lt;span style="color: #008000"&gt;//
use the RawUrl since it works with URL Rewriting&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt; 14:&lt;/span&gt; Path
= filterContext.HttpContext.Request.RawUrl&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt; 15:&lt;/span&gt; };&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt; 16:&lt;/span&gt; filterContext.Result
= &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RedirectResult(builder.ToString());&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt; 17:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt; 18:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt; 19:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpException((&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)HttpStatusCode.Forbidden,
MvcResources.RequireSslAttribute_MustUseSsl);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt; 20:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt; 21:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt; 22:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blog.salvoz.com/aggbug.ashx?id=19b31023-5c88-4742-a7f2-22cdafea11de" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.salvoz.com"&gt;Adam Salvo&lt;/a&gt;. </description>
      <comments>http://blog.salvoz.com/CommentView,guid,19b31023-5c88-4742-a7f2-22cdafea11de.aspx</comments>
      <category>Technology/Asp.Net MVC</category>
      <category>Technology/Programming</category>
    </item>
  </channel>
</rss>