<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dot Net Thoughts &#187; IIS 7</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/iis-7/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to Store and Retrieve files from SQL Server Database</title>
		<link>http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 07:41:48 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[File to Database]]></category>
		<category><![CDATA[IIS 7]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=417</guid>
		<description><![CDATA[The forum I joined recently got lot of queries like How to Save Images in the Database, How to save files in SQL Server, How read files from Database etc. So I thought of writing a post regarding this. Even though I am part of a Web project, I am doing some Windows applications for [...]]]></description>
			<content:encoded><![CDATA[<p>The forum I joined recently got lot of queries like How to Save Images in the Database, How to save files in SQL Server, How read files from Database etc. So I thought of writing a post regarding this. Even though I am part of a Web project, I am doing some Windows applications for the client. So I thought it will nice to brush-up the ASP.Net skills.</p>
<p>Here is the code. I am using SQL Server 2008, but I am not using FileStream for the current project, I already wrote a <a href="http://www.dotnetthoughts.net/2009/09/22/adding-and-reading-files-from-sql-server-2008-filestream/">post</a> to how to<br />
manage files with FileStream feature. In this post I am using nvarchar(MAX) datatype for storing the file content.</p>
<p><strong>Table Design</strong></p>
<pre class="brush: sql;">
CREATE TABLE [dbo].[tblFiles](
	[FileId] [uniqueidentifier] NOT NULL,
	[Filename] [nvarchar](255) NOT NULL,
	[FileContent] [varbinary](max) NULL
)
</pre>
<p>And the I set FileId default to newId() and FileContent default to NULL</p>
<pre class="brush: sql;">
ALTER TABLE [dbo].[tblFiles] ADD  CONSTRAINT [DF_tblFiles_FileId]  DEFAULT (newid()) FOR [FileId]
GO
ALTER TABLE [dbo].[tblFiles] ADD  CONSTRAINT [DF_tblFiles_FileContent]  DEFAULT (NULL) FOR [FileContent]
GO
</pre>
<p>I wrote the code in C#. I am having a Asp FileUpload control and a button to upload the file, and a Repeater control with two controls, a label for displaying the filename and hyper link control for downloading the file.</p>
<pre class="brush: xml;">
&lt;body&gt;
&lt;form runat=&quot;server&quot;&gt;
&lt;asp:FileUpload runat=&quot;server&quot; ID=&quot;fileUploadImage&quot; /&gt;
&lt;asp:Button runat=&quot;server&quot; ID=&quot;cmdUpload&quot; Text=&quot;Upload File&quot; OnClick=&quot;cmdUpload_Click&quot; /&gt;
&lt;asp:Repeater runat=&quot;server&quot; ID=&quot;rptrFiles&quot;&gt;
    &lt;HeaderTemplate&gt;
        &lt;table&gt;
    &lt;/HeaderTemplate&gt;
    &lt;ItemTemplate&gt;
        &lt;tr&gt;
            &lt;td&gt;
                &lt;asp:Label runat=&quot;server&quot; ID=&quot;lblFilename&quot; Text='&lt;%# Eval(&quot;FileName&quot;)%&gt;' /&gt;
            &lt;/td&gt;
            &lt;td&gt;
              &lt;asp:HyperLink runat=&quot;server&quot; Target=&quot;_blank&quot; ID=&quot;lbtDownload&quot; Text=&quot;Download&quot; NavigateUrl='&lt;%# &quot;Download.aspx?File=&quot;  + Eval(&quot;FileId&quot;).ToString() %&gt;' /&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/ItemTemplate&gt;
    &lt;FooterTemplate&gt;
        &lt;/table&gt;
    &lt;/FooterTemplate&gt;
&lt;/asp:Repeater&gt;
&lt;/form&gt;
&lt;/body&gt;
</pre>
<p><strong>Uploading the File to the Database</strong><br />
Code behind</p>
<pre class="brush: csharp;">
protected void cmdUpload_Click(object sender, EventArgs e)
{
    string fileName = Path.GetFileName(this.fileUploadImage.FileName);
    byte[] fileContent = this.fileUploadImage.FileBytes;
    using (SqlConnection connection = new SqlConnection(&quot;Server=.\\SQLEXPRESS;User Id=sa;Password=sapassword;Database=sampledb&quot;))
    {
        connection.Open();
        using (SqlCommand command = new SqlCommand(&quot;INSERT INTO tblFiles(Filename, FileContent) VALUES(@Filename, @FileContent)&quot;, connection))
        {
            SqlParameter fileNameParameter = new SqlParameter(&quot;@Filename&quot;, System.Data.SqlDbType.NVarChar, 255);
            fileNameParameter.Value = fileName;
            SqlParameter fileContentParameter = new SqlParameter(&quot;@FileContent&quot;, System.Data.SqlDbType.VarBinary);
            fileContentParameter.Value = fileContent;
            command.Parameters.AddRange(new SqlParameter[] { fileNameParameter, fileContentParameter });
            command.ExecuteNonQuery();
        }
    }
}
</pre>
<p>And here is code to bind the repeater from the Database</p>
<pre class="brush: csharp;">
DataTable dtFiles = new DataTable(&quot;Files&quot;);
using (SqlDataAdapter adapter = new SqlDataAdapter(&quot;SELECT FileId, FileName FROM tblFiles&quot;, &quot;Server=.\\SQLEXPRESS;User Id=sa;Password=sapassword;Database=sampledb&quot;))
{
    adapter.Fill(dtFiles);
}
this.rptrFiles.DataSource = dtFiles;
this.rptrFiles.DataBind();
</pre>
<p><strong>Download / Read the file from Database</strong><br />
And to download / read the file from Database, I am passing the File unique id to another page(download.aspx).I this page I am checking for the File querysting and based on that reading filecontent from Sql and writing it to Asp.net output stream. You can get more information about how to download files from IIS in this <a href="http://www.dotnetthoughts.net/2007/05/06/download-files-from-iis-server-using-aspnet/">post</a>.</p>
<pre class="brush: csharp;">
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString[&quot;File&quot;] != null)
    {
        string fileId = Request.QueryString[&quot;File&quot;];
        using (SqlConnection connection = new SqlConnection(&quot;Server=.\\SQLEXPRESS;User Id=sa;Password=sapassword;Database=Sample&quot;))
        {
            connection.Open();
            using (SqlCommand command = new SqlCommand(&quot;SELECT Filename, FileContent FROM tblFiles WHERE FileId = @FileId&quot;, connection))
            {
                command.Parameters.AddWithValue(&quot;@FileId&quot;, fileId);
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.HasRows)
                {
                    reader.Read();
                    byte[] content = reader[&quot;FileContent&quot;] as byte[];
                    string filename = reader[&quot;FileName&quot;].ToString();
                    Response.Clear();
                    Response.ClearContent();
                    Response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; + filename);
                    Response.AddHeader(&quot;Content-Length&quot;, content.Length.ToString());
                    Response.OutputStream.Write(content, 0, content.Length);
                    Response.End();
                }
            }
        }
    }
}
</pre>
<p>Please write to me if I missed something. Happy Programming .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple Chat script using ASP.Net C#</title>
		<link>http://www.dotnetthoughts.net/2009/09/11/a-simple-chat-script-using-asp-net-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/09/11/a-simple-chat-script-using-asp-net-c/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 12:50:34 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[AJAX.Net]]></category>
		<category><![CDATA[ASP.Net Chat script]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Chat]]></category>
		<category><![CDATA[IIS 7]]></category>
		<category><![CDATA[PageMethods]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=373</guid>
		<description><![CDATA[Few days back one of my colleague was looking for a simple chat script in ASP.Net, but he can&#8217;t found one. Almost all of the chat scripts were in ASP and he want to do it for an internal site. So I thought about implementing one. And here is the simple script using ASP.Net&#8217;s Page [...]]]></description>
			<content:encoded><![CDATA[<p>Few days back one of my colleague was looking for a simple chat script in ASP.Net, but he can&#8217;t found one. Almost all of the chat scripts were in ASP and he want to do it for an internal site. So I thought about implementing one. And here is the simple script using ASP.Net&#8217;s Page method feature. For this I am using Windows Authentication, because it is for a intranet site, where users will be coming from one domain only.</p>
<p>Code behind &#8211; Global.asax</p>
<pre class="brush: csharp;">
private List&lt;string&gt; onlineUsers;
void Session_Start(object sender, EventArgs e)
{
	if (this.onlineUsers == null)
	{
            this.onlineUsers = new List&lt;/string&gt;&lt;string&gt;();
        }

        if (!this.onlineUsers.Contains(HttpContext.Current.User.Identity.Name))
        {
            this.onlineUsers.Add(HttpContext.Current.User.Identity.Name);
        }
        HttpContext.Current.Session[&quot;Users&quot;] = this.onlineUsers;
}

void Session_End(object sender, EventArgs e)
{
        if (this.onlineUsers != null)
        {
            this.onlineUsers.Remove(HttpContext.Current.User.Identity.Name);
        }
	HttpContext.Current.Session[&quot;Users&quot;] = this.onlineUsers;
}
</pre>
<p>Web.Config</p>
<pre class="brush: xml;">
&lt;authentication mode=&quot;Windows&quot;/&gt;
&lt;authorization&gt;
	&lt;deny users=&quot;?&quot;/&gt;
&lt;/authorization&gt;
</pre>
<p>Default.aspx.cs</p>
<pre class="brush: csharp;">
private static List&lt;/string&gt;&lt;string&gt; chatCollection;

[WebMethod(true)]
public static List&lt;/string&gt;&lt;string&gt; Add(string comment)
{
	string user = HttpContext.Current.User.Identity.Name;
        if (chatCollection == null)
        {
		chatCollection = new List&lt;/string&gt;&lt;string&gt;();
        }
        comment = comment.Replace(&quot;&lt; &quot;, &quot;[&quot;).Replace(&quot;&gt;&quot;, &quot;]&quot;);
        comment = GetSmileys(comment);
        chatCollection.Add(string.Format(&quot;&lt;tr&gt;&lt;td&gt;{0} :&lt;font color=\&quot;blue\&quot;&gt;{1}&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&quot;, user, comment));
        return chatCollection;
}

private static string GetSmileys(string comment)
{
        if (comment.Contains(&quot;[:-)]&quot;))
        {
        	comment = comment.Replace(&quot;[:-)]&quot;, &quot;&lt;img src=\&quot;icons\\smile.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[;-)]&quot;))
        {
        	comment = comment.Replace(&quot;[;-)]&quot;, &quot;&lt;img src=\&quot;icons\\wink.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[:-(]&quot;))
        {
        	comment = comment.Replace(&quot;[:-(]&quot;, &quot;&lt;img src=\&quot;icons\\frown.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[:-D]&quot;))
        {
        	comment = comment.Replace(&quot;[:-D]&quot;, &quot;&lt;img src=\&quot;icons\\biggrin.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[:-|]&quot;))
        {
        	comment = comment.Replace(&quot;[:-|]&quot;, &quot;&lt;img src=\&quot;icons\\blankstare.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[B-)]&quot;))
        {
        	comment = comment.Replace(&quot;[B-)]&quot;, &quot;&lt;img src=\&quot;icons\\cool.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[}-)]&quot;))
        {
        	comment = comment.Replace(&quot;[}-)]&quot;, &quot;&lt;img src=\&quot;icons\\devilish.gif\&quot;/&gt;&quot;);
        }
        else if (comment.Contains(&quot;[:-P]&quot;))
        {
        	comment = comment.Replace(&quot;[:-P]&quot;, &quot;&lt;img src=\&quot;icons\\p.gif\&quot;/&gt;&quot;);
        }
	return comment;
}

[WebMethod(true)]
public static List&lt;/string&gt;&lt;string&gt; GetChat()
{
	if (chatCollection == null)
        {
        	chatCollection = new List&lt;/string&gt;&lt;string&gt;();
        }
        return chatCollection;
}

[WebMethod(true)]
public static List&lt;/string&gt;&lt;string&gt; GetUsers()
{
	if (HttpContext.Current.Session[&quot;Users&quot;] == null)
        {
        	HttpContext.Current.Session[&quot;Users&quot;] = new List&lt;/string&gt;&lt;string&gt;();
        }
        return HttpContext.Current.Session[&quot;Users&quot;] as List&lt;/string&gt;&lt;string&gt;;
}
</pre>
<p>And finally the HTML</p>
<p>Default.aspx</p>
<pre class="brush: xml;">

&lt; !DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;:: TEAM CHAT ::&lt;/title&gt;

    &lt;script type=&quot;text/javascript&quot;&gt;
        function sendChat() {
            var chatText = $get(&quot;txtChatInput&quot;).value;
            if (chatText != &quot;&quot;) {
                PageMethods.Add(chatText, sendChat_Callback);
            }
            else {
                $get(&quot;txtChatInput&quot;).focus();
            }
            return false;
        }
        function sendChat_Callback(response) {
            displayChatText(response);
            $get(&quot;txtChatInput&quot;).value = &quot;&quot;;
            $get(&quot;txtChatInput&quot;).focus();
        }
        function GetChat() {
            PageMethods.GetChat(GetChat_Callback);
        }
        function GetChat_Callback(response) {
            displayChatText(response);
        }
        function displayChatText(response) {
            var result;
            result = &quot;&lt;table&gt;&quot;;
            for (var i = response.length - 1; i &gt;= 0; i--) {
                result = result + response[i];
            }
            result = result + &quot;&lt;/table&gt;&quot;;
            $get(&quot;chatOutputDiv&quot;).innerHTML = result;
        }
        function getUsers() {
            PageMethods.GetUsers(GetUsers_Callback);
        }
        function GetUsers_Callback(response) {
            $get(&quot;lstUsers&quot;).options.length = 0;
            for (var i = response.length - 1; i &gt;= 0; i--) {
                addUsers(response[i]);
            }
        }
        function addUsers(text) {
            var optn = document.createElement(&quot;OPTION&quot;);
            optn.text = text;
            optn.value = text;
            $get(&quot;lstUsers&quot;).options.add(optn);
        }
        function LoadUI() {
            getUsers();
            GetChat();
            $get(&quot;txtChatInput&quot;).focus();
        }
        function showAbout() {
            var msg = &quot;Copyright (c) 2009 Anuraj. All rights reserved.\nLicenced under GNU GPL v2.&quot;;
            msg += &quot;\n\nVersion 0.2 : Supports Smileys\n&quot;;
            msg += &quot;Smileys should be in square brackets, like below,\ncase-sensitive(Sorry I will fix it later)\n&quot;;
            msg += &quot;Supported :- [:-)], [;-)], [:-(], [:-D], [:-|], [B-)], [}-)],[:-P]\n&quot;;
            msg += &quot;\n\nHappy Chatting [:)]\n&quot;;
            alert(msg);
        }
        setInterval(&quot;LoadUI();&quot;, 5000);
    &lt;/script&gt;

    &lt;style type=&quot;text/css&quot;&gt;
        body
        {
            font-family: Calibri;
            font-size: 11pt;
        }
        input
        {
            font-family: Calibri;
            font-size: 11pt;
            color: Blue;
        }
        .txt
        {
            border: solid 1px #000;
            font-family: Calibri;
            font-size: 11pt;
            color: Black;
        }
        option
        {
            font-family: Calibri;
            font-size: 11pt;
            color: Blue;
        }
        h1
        {
            color: Blue;
            font-size: xx-large;
            text-decoration: underline;
            text-align: center;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body onload=&quot;javascript:LoadUI();&quot;&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot; onsubmit=&quot;javascript:return sendChat();&quot;&gt;
    &lt;div&gt;
        &lt;asp :ScriptManager runat=&quot;server&quot; ID=&quot;scriptMgr&quot; EnablePageMethods=&quot;true&quot; ScriptMode=&quot;Release&quot;
            EnableViewState=&quot;false&quot; /&gt;
        &lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot; style=&quot;text-align: center&quot;&gt;
                    &lt;h1&gt;
                        :: TEAM CHAT ::
                    &lt;/h1&gt;
                    &lt;span&gt;A simple chat script using ASP.Net and C#&lt;/span&gt;
                    &amp;nbsp;&lt;a href=&quot;javascript:void('About');&quot; title=&quot;About TeamChat&quot; onclick=&quot;javascript:return showAbout

();&quot;&gt;?&lt;/a&gt;&amp;nbsp;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;

                    &lt;input class=&quot;txt&quot; type=&quot;text&quot; maxlength=&quot;1500&quot; style=&quot;width: 340px;&quot; id=&quot;txtChatInput&quot; /&gt;
                &lt;/td&gt;
                &lt;td valign=&quot;middle&quot;&gt;
                    &amp;nbsp;&lt;input type=&quot;button&quot; id=&quot;cmdSubmit&quot; value=&quot;Send&quot; onclick=&quot;javascript:return sendChat();&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot;&gt;
                    &amp;nbsp;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot; valign=&quot;top&quot;&gt;
                    &lt;div id=&quot;chatOutput&quot; style=&quot;height: 300px; width: 400px; border: solid 1px #000;
                        overflow: scroll;&quot;&gt;
                        &lt;div id=&quot;chatOutputDiv&quot; style=&quot;height: 280px; width: 380px;&quot;&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot;&gt;
                    &amp;nbsp;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot; valign=&quot;top&quot;&gt;
                    &lt;label&gt;
                        Online Users&lt;/label&gt;&lt;br /&gt;
                    &lt;select class=&quot;txt&quot; size=&quot;4&quot; id=&quot;lstUsers&quot; style=&quot;width: 400px; border: thin solid #000000;
                        font-family: Calibri; font-size: 11pt; color: #FFFFFF;&quot;&gt;
                        &lt;option&gt;No users available &lt;/option&gt;
                    &lt;/select&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot; style=&quot;text-align: center; font-size: 11px;&quot;&gt;
                    Copyright &amp;copy; 2009 &lt;a href=&quot;mailto:anuraj.p@mymailserver.com&quot;&gt;Anuraj&lt;/a&gt;. All rights
                    reserved.&lt;br /&gt;
                    Licenced under GNU GPL v2.
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Here is the Image &#8220;Team Chat&#8221; running on my machine</p>
<div id="attachment_374" class="wp-caption alignnone" style="width: 435px"><a href="http://anuraj.files.wordpress.com/2009/09/team_chat_image.jpg"><img src="http://anuraj.files.wordpress.com/2009/09/team_chat_image.jpg" alt="Team chat - asp.net script screenshot" title="Team Chat - Screen shot" width="425" height="580" class="size-full wp-image-374" /></a><p class="wp-caption-text">Team chat - asp.net script screenshot</p></div>
<p>Code seems like pretty self explantory. As wordpress don&#8217;t support zip attachments, I will upload, and give the source later.</p>
<p>Happy Chating <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I took the Emoticons from <a href="http://comments.deviantart.com/emoticons?order=popularity" target="_blank">deviantart.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/09/11/a-simple-chat-script-using-asp-net-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Implementing Windows authentication in ASP.NET on IIS 7</title>
		<link>http://www.dotnetthoughts.net/2009/07/30/implementing-windows-authentication-in-asp-net-on-iis-7/</link>
		<comments>http://www.dotnetthoughts.net/2009/07/30/implementing-windows-authentication-in-asp-net-on-iis-7/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 13:33:48 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[IIS 7]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=344</guid>
		<description><![CDATA[For implementing windows authentication in IIS 7 (On Windows Vista), you need to check whether the Windows authentication installed or not. You can do this either using Programs and Features &#62; Turn Windows features On or Off. And select the Checkbox windows authentication from Security. After installing the Windows Authentication in your system, update your [...]]]></description>
			<content:encoded><![CDATA[<p>For implementing windows authentication in IIS 7 (On Windows Vista),<br />
you need to check whether the Windows authentication installed or not. You can do this either using <em><strong>Programs and Features &gt; Turn Windows features On or Off.</strong></em> And select the Checkbox windows authentication from Security.</p>
<div id="attachment_345" class="wp-caption alignnone" style="width: 490px"><a href="http://anuraj.files.wordpress.com/2009/07/install_windows_authentication.jpg"><img src="http://anuraj.files.wordpress.com/2009/07/install_windows_authentication.jpg" alt="Install Windows Authentication" title="Install_Windows_authentication" width="480" height="510" class="size-full wp-image-345" /></a><p class="wp-caption-text">Install Windows Authentication</p></div>
<p>After installing the Windows Authentication in your system, update your IIS in web application settings. Select <em><strong>Authentication, and enable the Windows Authentication. And disable the Anonymous Authentication.</strong></em></p>
<div id="attachment_346" class="wp-caption alignnone" style="width: 490px"><a href="http://anuraj.files.wordpress.com/2009/07/authentication.jpg"><img src="http://anuraj.files.wordpress.com/2009/07/authentication.jpg" alt="Enable Windows Authentication" title="Enable Windows Authentication" width="480" height="231" class="size-full wp-image-346" /></a><p class="wp-caption-text">Enable Windows Authentication</p></div>
<p>Now in the <em>Web.config</em> file, set the Authentication mode to Windows.</p>
<pre class="brush: xml;">
&lt;authentication mode=&quot;Windows&quot; /&gt;
</pre>
<p>Also set the authorization rules, like which all users / roles need access etc.</p>
<pre class="brush: xml;">
&lt;authorization&gt;
&lt;allow users=&quot;DOMAIN\USER, DOMAIN\USER2&quot; /&gt;
&lt;deny users=&quot;*&quot;/&gt;
&lt;/authorization&gt;
</pre>
<p>Now modify the Default.aspx page so that it can display the current username.</p>
<pre class="brush: xml;">
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt; %= User.Identity.Name %&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
</pre>
<p>Now run the application, it will display the Windows Authentication dialog, if your username not in the list. If you cancel the login dialog it will display a Access Denied page. If you give the correct username and password, it will display the Username.</p>
<p>You can get more information from <a href="http://support.microsoft.com/kb/323176" target="_blank">How to implement Windows authentication and authorization in ASP.NET<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/07/30/implementing-windows-authentication-in-asp-net-on-iis-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
