Try our conversational search powered by Generative AI!

Programmatic access to files on virtual path

I have a situation where I have to programmatically load a file on my EPiServer site's virtual path system and so the file cannot be accessed. Is there some way to have the ASPNET user/process act as ('impersonate') the currently logged in user, or can I somehow add ASPNET as a user on the site? (I am using the SQL role provider)
May 29, 2008 16:05
I have just tried enabling the multiplexing provider instead of the SQL provider and I was able to login with a windows account. However, EPiServer does not seem to support adding a Windows account to the basic role (which has access to the file in virtual path).. EPiServer also does not support setting a user's rights for all Global files so I would have to set access rights for the windows account on every single file..?
May 29, 2008 16:43
If you want to programmatically log in as another user, have a look at Ruwens example code:

There is also a BypassAccessCheck property on UnifiedDirectory.



May 29, 2008 18:55
I am able to log in the user with Ruwens code, but I still get an exception when the following code is executed ("url" is an url for a picture on my EPiServer site which the user should be able to access)

WebRequest request = HttpWebRequest.Create(new Uri(HttpContext.Current.Request.Url, Request.QueryString["url"]));

WebResponse response = request.GetResponse();

May 30, 2008 10:00

Now I have also tried to enable EPiServer's basic authentication module and disable anonymous access. When I access the file directly (on the address "url" above) I get the login screen from the browser and after logging in I can access the file. Then I would assumes that the code lines above would also be able to access the file if in between I add this:

request.Credentials = new NetworkCredential("admin", "Password"); 

However, that also does not work. I am running out of ideas now...  

Edited, May 30, 2008 10:48

Not sure if I've understood what your needs are, but this is how i fetch a file from a virtual path provider in CMS 5.

VirtualFile file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile( CurrentPage[”FilePath”].ToString() );
UnifiedFile f = file as UnifiedFile;

Hope it might be some help.

Jun 01, 2008 10:39
That works! I should have known of that method..
BTW I did actually make the other solution work, but only for a short while, then it suddenly did not work anymore.. I guess it is a problem when both anonymous access and basic authentication are enabled...
Jun 09, 2008 10:50
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.