London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Programmatic access to files on virtual path

Vote:
 
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)
#20442
May 29, 2008 16:05
Vote:
 
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..?
#20445
May 29, 2008 16:43
Vote:
 
If you want to programmatically log in as another user, have a look at Ruwens example code:

http://labs.episerver.com/en/Blogs/Ruwen/Dates/111218/111219/111222/

There is also a BypassAccessCheck property on UnifiedDirectory.

 

 

#20446
May 29, 2008 18:55
Vote:
 
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();

#20453
May 30, 2008 10:00
Vote:
 

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...  

#20456
Edited, May 30, 2008 10:48
Vote:
 

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.

#20462
Jun 01, 2008 10:39
Vote:
 
That works! I should have known of that method..
Thanks
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...
#20656
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.