{"id":156,"date":"2005-03-09T11:41:00","date_gmt":"2005-03-09T19:41:00","guid":{"rendered":"http:\/\/spacefold.com\/colin\/morethanfour\/?p=156"},"modified":"2020-08-16T11:42:13","modified_gmt":"2020-08-16T19:42:13","slug":"asp-net-and-impersonation-trouble","status":"publish","type":"post","link":"https:\/\/spacefold.com\/colin\/morethanfour\/2005\/03\/09\/asp-net-and-impersonation-trouble\/","title":{"rendered":"ASP.NET and impersonation trouble"},"content":{"rendered":"\n<p>So I have this Asp.NET application that needs to run on the WEBSERVER but see files in a directory on FILESERVER out on the net. (The files are, inevitably, Foxpro tables being accessed through OleDb.)<\/p>\n\n\n\n<p>First cut, the OleDbConnection fails to open the data (\\\\FILESERVER\\Sharename\\datafolder) with an &#8220;invalid path or file name&#8221; error. That&#8217;s because the ASP.NET application is running under the WEBSERVER\/aspnet user context which does not have permission to see the network share.<\/p>\n\n\n\n<p>&#8220;No problem,&#8221; we say. &#8220;Let&#8217;s just use the web.config file to tell Asp.NET to run under a context that&nbsp;<strong>does<\/strong>&nbsp;have permission to see the share:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;system.web&gt;\n    :\n    &lt;identity impersonate=\"true\"\n              userName=\"NETDOMAIN\\net_user\"\n              password=\"secret\"\/&gt;\n    :\n&lt;\/system.web&gt;\n<\/pre>\n\n\n\n<p>This works &#8211;&nbsp;<strong>except<\/strong>&nbsp;that every time we uploaded a new version of the .aspx files to the webserver, it threw an exception: &#8220;Cannot execute a program. The command being executed was [..]\\v1.1.4322\\csc.exe \/noconfig &#8230;&#8221;. Basically it didn&#8217;t appear to have rights to run the compiler to do that special ASP.NET on-the-fly compilation of the classes.<\/p>\n\n\n\n<p>Investigation seemed to indicate that it should have the appropriate access rights, but all the same, we couldn&#8217;t make it work without commenting out the&nbsp;&lt;identity&gt; specification;&nbsp;re-starting the IIS process; then putting it back after the successful compilation so that the network share was visible.<\/p>\n\n\n\n<p>Second cut was to omit the &lt;identity&gt; override, but to bracket the OleDb call with special in-line user impersonation code using Win32 LogonUser() calls. Well that didn&#8217;t work (and when I find out why, perhaps I&#8217;ll post about it).<\/p>\n\n\n\n<p>I found a solution to the problem on a web thread posted by shamrox (<a href=\"http:\/\/forums.rainbowportal.net\/ShowPost.aspx?PostID=5503\">http:\/\/forums.rainbowportal.net\/ShowPost.aspx?PostID=5503<\/a>) which I reproduce here:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em>Is this error happening when you try to run your project? I guess what I am asking is that it compiles fine but when it goes to the first screen you get this error. IE would never open if it didn&#8217;t compile.<\/em><\/p><p><em>If it is what I think it has to do with the aspnet_wp. It does some weird stuff. You don&#8217;t have to restart www to fix it, all you need to do is go to task manager and<\/em>&nbsp;[terminate the aspnet_wp.exe process]<em>. Don&#8217;t worry it restarts automatically. That will fix the problem for now. It comes up from time to time so if there is a better way I would like to know too.<\/em><\/p><\/blockquote>\n\n\n\n<p>Thanks shamrox &#8211; this works! Now we can leave the&nbsp;&lt;identity&gt; switch in place in the web.config in order for my web site to &#8220;see&#8221; the network resources, and when I upload a new version of the aspxs to my web site &#8211; it will stick with the exception on the recompile but a restart of the aspnet_wp.exe process will bring it back, no worries.<\/p>\n\n\n\n<p>I still think ASP.NET is the bomb.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I have this Asp.NET application that needs to run on the WEBSERVER but see files in a directory on FILESERVER out on the net. (The files are, inevitably, Foxpro tables being accessed through OleDb.) First cut, the OleDbConnection fails to open the data (\\\\FILESERVER\\Sharename\\datafolder) with an &#8220;invalid path or file name&#8221; error. That&#8217;s because [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-foxpro","post-preview"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}